From 4efdfb69b67aa9182a116c3d28153899625c7e34 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Wed, 21 Jun 2023 23:43:40 -0700 Subject: [PATCH 1/5] Allow specifying `--workers` via environment variable --- src/black/__init__.py | 5 ++++- src/black/concurrency.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index 871e9a0d7c8..6d503e38ea1 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -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", diff --git a/src/black/concurrency.py b/src/black/concurrency.py index 1598f51e43f..893eba6675a 100644 --- a/src/black/concurrency.py +++ b/src/black/concurrency.py @@ -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) From 87626c9ff2abdb49ccc4adc5b9e1801ac9ab4d5b Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Wed, 21 Jun 2023 23:47:54 -0700 Subject: [PATCH 2/5] changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c7ecc396214..5cf83f86d38 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,8 @@ ### Configuration +- The `--workers` argument to Black can now be specified via the `BLACK_NUM_WORKERS` + environment variable (#3743) ### Packaging From 52b1ce3e5899eadc5c28e8ce1fad5f27ff4841a7 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Wed, 21 Jun 2023 23:50:05 -0700 Subject: [PATCH 3/5] liiiiint --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 5cf83f86d38..c11a7fe5178 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,7 @@ ### Configuration + - The `--workers` argument to Black can now be specified via the `BLACK_NUM_WORKERS` environment variable (#3743) From ddba4bf36bf460739d06b0417c782f6ec7819438 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 24 Jun 2023 13:48:39 -0700 Subject: [PATCH 4/5] docs --- docs/usage_and_configuration/the_basics.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/usage_and_configuration/the_basics.md b/docs/usage_and_configuration/the_basics.md index 6f3a3cff30c..35981bcd53e 100644 --- a/docs/usage_and_configuration/the_basics.md +++ b/docs/usage_and_configuration/the_basics.md @@ -246,7 +246,8 @@ respect the `--force-exclude` option on some editors that rely on using stdin. #### `-W`, `--workers` When _Black_ formats multiple files, it may use a process pool to speed up formatting. -This option controls the number of parallel workers. +This option controls the number of parallel workers. This can also be specified via +the `BLACK_NUM_WORKERS` environment variable. #### `-q`, `--quiet` @@ -296,6 +297,19 @@ Read configuration options from a configuration file. See Show available command-line options and exit. +### Environment variable options + +_Black_ supports the following configuration via environment variables. + +#### `BLACK_CACHE_DIR` + +The directory where _Black_ should store its cache. + +#### `BLACK_NUM_WORKERS` + +The number of parallel workers _Black_ should use. The command line option +`-W` / `--workers` takes precedence over this environment variable. + ### Code input alternatives _Black_ supports formatting code via stdin, with the result being printed to stdout. From 9b9ee61db11d804273d36cb5368ffb7250669791 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 24 Jun 2023 14:50:04 -0700 Subject: [PATCH 5/5] lint --- docs/usage_and_configuration/the_basics.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/usage_and_configuration/the_basics.md b/docs/usage_and_configuration/the_basics.md index 35981bcd53e..2a461487210 100644 --- a/docs/usage_and_configuration/the_basics.md +++ b/docs/usage_and_configuration/the_basics.md @@ -246,8 +246,8 @@ respect the `--force-exclude` option on some editors that rely on using stdin. #### `-W`, `--workers` When _Black_ formats multiple files, it may use a process pool to speed up formatting. -This option controls the number of parallel workers. This can also be specified via -the `BLACK_NUM_WORKERS` environment variable. +This option controls the number of parallel workers. This can also be specified via the +`BLACK_NUM_WORKERS` environment variable. #### `-q`, `--quiet` @@ -307,8 +307,8 @@ The directory where _Black_ should store its cache. #### `BLACK_NUM_WORKERS` -The number of parallel workers _Black_ should use. The command line option -`-W` / `--workers` takes precedence over this environment variable. +The number of parallel workers _Black_ should use. The command line option `-W` / +`--workers` takes precedence over this environment variable. ### Code input alternatives