Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.12

- **NEW**: When `jobs` is set to `0`, use maximum available cores.

## 2.11

- **NEW**: Add new command line option `--skip-dict-compile` which will skip the dictionary compiling step if the
Expand Down
2 changes: 2 additions & 0 deletions docs/src/markdown/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ process files in a given task.
jobs: 4
```

If `jobs` is set to `0`, the maximum available cores will be used.

/// new | New 2.10
Parallel processing is new in 2.10.
///
Expand Down
7 changes: 5 additions & 2 deletions docs/src/markdown/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ If you want to manually install it, run `#!bash python setup.py build` and `#!ba
## Command Line Usage

```
usage: pyspelling [-h] [--version] [--verbose] [--name NAME | --group GROUP] [--binary BINARY] [--jobs JOBS] [--config CONFIG] [--source SOURCE] [--spellchecker SPELLCHECKER] [--skip-dict-compile]
usage: pyspelling [-h] [--version] [--verbose] [--name NAME | --group GROUP] [--binary BINARY] [--jobs JOBS] [--config CONFIG] [--source SOURCE]
[--spellchecker SPELLCHECKER] [--skip-dict-compile]

Spell checking tool.

Expand All @@ -64,7 +65,7 @@ options:
--name, -n NAME Specific spelling task by name to run.
--group, -g GROUP Specific spelling task group to run.
--binary, -b BINARY Provide path to spell checker's binary.
--jobs, -j JOBS Specify the number of spell checker processes to run in parallel.
--jobs, -j JOBS Specify the number of spell checker processes to run in parallel. Using 0 will utilize the maximum number of cores.
--config, -c CONFIG Spelling config.
--source, -S SOURCE Specify override file pattern. Only applicable when specifying exactly one --name.
--spellchecker, -s SPELLCHECKER
Expand Down Expand Up @@ -141,6 +142,8 @@ processing time. Specifying jobs on the command line will override the `jobs` se
$ pyspelling -n my_task -j 4
```

If `jobs` is set to `0`, the maximum available cores will be used.

/// new | New 2.10
Parallel processing is new in 2.10.
///
Expand Down
10 changes: 5 additions & 5 deletions pyspelling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class SpellingTask:
"O": glob.O
}

def __init__(self, checker, config, binary='', verbose=0, jobs=0, debug=False, skip_dict_compile=False):
def __init__(self, checker, config, binary='', verbose=0, jobs=None, debug=False, skip_dict_compile=False):
"""Initialize."""

if checker == "hunspell": # pragma: no cover
Expand Down Expand Up @@ -678,12 +678,12 @@ def run_task(self, task, source_patterns=None):
source_patterns = self.task.get('sources', [])

# If jobs was not specified via command line, check the config for jobs settings
jobs = max(1, self.config.get('jobs', 1) if self.jobs == 0 else self.jobs)
jobs = self.config.get('jobs', 1) if self.jobs is None else self.jobs

expect_match = self.task.get('expect_match', True)
if jobs > 1:
if jobs != 1 and jobs > 0:
# Use multi-processing to process files concurrently
with ProcessPoolExecutor(max_workers=jobs) as pool:
with ProcessPoolExecutor(max_workers=jobs if jobs else None) as pool:
for results in pool.map(self.multi_check, self.walk_src(source_patterns, glob_flags, glob_limit)):
self.found_match = True
yield from results
Expand Down Expand Up @@ -711,7 +711,7 @@ def spellcheck(
sources=None,
verbose=0,
debug=False,
jobs=0,
jobs=None,
skip_dict_compile=False
):
"""Spell check."""
Expand Down
11 changes: 8 additions & 3 deletions pyspelling/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ def main():
'--jobs', '-j',
action='store',
type=int,
default=0,
help="Specify the number of spell checker processes to run in parallel."
default=None,
help=(
"Specify the number of spell checker processes to run in parallel. "
"Using 0 will utilize the maximum number of cores."
)
)
parser.add_argument('--config', '-c', action='store', default='', help="Spelling config.")
parser.add_argument(
Expand Down Expand Up @@ -64,7 +67,9 @@ def run(config, **kwargs):
verbose = kwargs.get('verbose', 0)
sources = kwargs.get('sources', [])
debug = kwargs.get('debug', False)
jobs = kwargs.get('jobs', 0)
jobs = kwargs.get('jobs', None)
if jobs is not None and jobs < 0:
jobs = 1
skip_dict_compile = kwargs.get('skip_dict_compile', False)

fail = False
Expand Down
2 changes: 1 addition & 1 deletion pyspelling/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,5 @@ def parse_version(ver):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(2, 11, 0, "final")
__version_info__ = Version(2, 12, 0, "final")
__version__ = __version_info__._get_canonical()
2 changes: 1 addition & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def mktemp(self, filename, content, encoding):
"""Make temp directory."""

filename = os.path.join(self.tempdir, os.path.normpath(filename))
base, file = os.path.split(filename)
base, _ = os.path.split(filename)
if not os.path.exists(base):
retry = 3
while retry:
Expand Down