Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying --workers via environment variable #3743

Merged
merged 6 commits into from Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -25,6 +25,8 @@

<!-- Changes to how Black can be configured -->

- The `--workers` argument to Black can now be specified via the `BLACK_NUM_WORKERS`
environment variable (#3743)
- `.pytest_cache`, `.ruff_cache` and `.vscode` are now excluded by default (#3691)

### Packaging
Expand Down
5 changes: 4 additions & 1 deletion src/black/__init__.py
Expand Up @@ -373,7 +373,10 @@ def validate_regex(
"--workers",
type=click.IntRange(min=1),
default=None,
help="Number of parallel workers [default: number of CPUs in the system]",
help=(
"Number of parallel workers [default: BLACK_NUM_WORKERS environment variable "
"or number of CPUs in the system]"
),
)
@click.option(
"-q",
Expand Down
3 changes: 2 additions & 1 deletion src/black/concurrency.py
Expand Up @@ -80,7 +80,8 @@ def reformat_many(

executor: Executor
if workers is None:
workers = os.cpu_count() or 1
workers = int(os.environ.get("BLACK_NUM_WORKERS", 0))
workers = workers or os.cpu_count() or 1
if sys.platform == "win32":
# Work around https://bugs.python.org/issue26903
workers = min(workers, 60)
Expand Down