Skip to content

Commit 1109b81

Browse files
authored
Use maximum cores for jobs=0 (#209)
Fixes #207
1 parent cbf8bfd commit 1109b81

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

docs/src/markdown/about/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.12
4+
5+
- **NEW**: When `jobs` is set to `0`, use maximum available cores.
6+
37
## 2.11
48

59
- **NEW**: Add new command line option `--skip-dict-compile` which will skip the dictionary compiling step if the

docs/src/markdown/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ process files in a given task.
1919
jobs: 4
2020
```
2121

22+
If `jobs` is set to `0`, the maximum available cores will be used.
23+
2224
/// new | New 2.10
2325
Parallel processing is new in 2.10.
2426
///

docs/src/markdown/index.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ If you want to manually install it, run `#!bash python setup.py build` and `#!ba
5353
## Command Line Usage
5454

5555
```
56-
usage: pyspelling [-h] [--version] [--verbose] [--name NAME | --group GROUP] [--binary BINARY] [--jobs JOBS] [--config CONFIG] [--source SOURCE] [--spellchecker SPELLCHECKER] [--skip-dict-compile]
56+
usage: pyspelling [-h] [--version] [--verbose] [--name NAME | --group GROUP] [--binary BINARY] [--jobs JOBS] [--config CONFIG] [--source SOURCE]
57+
[--spellchecker SPELLCHECKER] [--skip-dict-compile]
5758
5859
Spell checking tool.
5960
@@ -64,7 +65,7 @@ options:
6465
--name, -n NAME Specific spelling task by name to run.
6566
--group, -g GROUP Specific spelling task group to run.
6667
--binary, -b BINARY Provide path to spell checker's binary.
67-
--jobs, -j JOBS Specify the number of spell checker processes to run in parallel.
68+
--jobs, -j JOBS Specify the number of spell checker processes to run in parallel. Using 0 will utilize the maximum number of cores.
6869
--config, -c CONFIG Spelling config.
6970
--source, -S SOURCE Specify override file pattern. Only applicable when specifying exactly one --name.
7071
--spellchecker, -s SPELLCHECKER
@@ -141,6 +142,8 @@ processing time. Specifying jobs on the command line will override the `jobs` se
141142
$ pyspelling -n my_task -j 4
142143
```
143144

145+
If `jobs` is set to `0`, the maximum available cores will be used.
146+
144147
/// new | New 2.10
145148
Parallel processing is new in 2.10.
146149
///

pyspelling/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class SpellingTask:
578578
"O": glob.O
579579
}
580580

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

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

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

683683
expect_match = self.task.get('expect_match', True)
684-
if jobs > 1:
684+
if jobs != 1 and jobs > 0:
685685
# Use multi-processing to process files concurrently
686-
with ProcessPoolExecutor(max_workers=jobs) as pool:
686+
with ProcessPoolExecutor(max_workers=jobs if jobs else None) as pool:
687687
for results in pool.map(self.multi_check, self.walk_src(source_patterns, glob_flags, glob_limit)):
688688
self.found_match = True
689689
yield from results
@@ -711,7 +711,7 @@ def spellcheck(
711711
sources=None,
712712
verbose=0,
713713
debug=False,
714-
jobs=0,
714+
jobs=None,
715715
skip_dict_compile=False
716716
):
717717
"""Spell check."""

pyspelling/__main__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ def main():
2020
'--jobs', '-j',
2121
action='store',
2222
type=int,
23-
default=0,
24-
help="Specify the number of spell checker processes to run in parallel."
23+
default=None,
24+
help=(
25+
"Specify the number of spell checker processes to run in parallel. "
26+
"Using 0 will utilize the maximum number of cores."
27+
)
2528
)
2629
parser.add_argument('--config', '-c', action='store', default='', help="Spelling config.")
2730
parser.add_argument(
@@ -64,7 +67,9 @@ def run(config, **kwargs):
6467
verbose = kwargs.get('verbose', 0)
6568
sources = kwargs.get('sources', [])
6669
debug = kwargs.get('debug', False)
67-
jobs = kwargs.get('jobs', 0)
70+
jobs = kwargs.get('jobs', None)
71+
if jobs is not None and jobs < 0:
72+
jobs = 1
6873
skip_dict_compile = kwargs.get('skip_dict_compile', False)
6974

7075
fail = False

pyspelling/__meta__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,5 @@ def parse_version(ver):
188188
return Version(major, minor, micro, release, pre, post, dev)
189189

190190

191-
__version_info__ = Version(2, 11, 0, "final")
191+
__version_info__ = Version(2, 12, 0, "final")
192192
__version__ = __version_info__._get_canonical()

tests/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def mktemp(self, filename, content, encoding):
8383
"""Make temp directory."""
8484

8585
filename = os.path.join(self.tempdir, os.path.normpath(filename))
86-
base, file = os.path.split(filename)
86+
base, _ = os.path.split(filename)
8787
if not os.path.exists(base):
8888
retry = 3
8989
while retry:

0 commit comments

Comments
 (0)