Skip to content

Commit 23d5ef3

Browse files
committed
config: add support for installer.parallel
This change allows users to disable parallel execution while using the new installer. Resolves: #3087
1 parent f2d53e5 commit 23d5ef3

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

docs/docs/configuration.md

+9
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ Defaults to one of the following directories:
102102
- Windows: `C:\Users\<username>\AppData\Local\pypoetry\Cache`
103103
- Unix: `~/.cache/pypoetry`
104104

105+
### `installer.parallel`: boolean
106+
107+
Use parallel execution when using the new (`>=1.1.0`) installer.
108+
Defaults to `true`.
109+
110+
!!!note:
111+
This configuration will be ignored, and parallel execution disabled when running
112+
Python 2.7 under Windows.
113+
105114
### `virtualenvs.create`: boolean
106115

107116
Create a new virtual environment if one doesn't already exist.

poetry/config/config.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Config(object):
3838
"path": os.path.join("{cache-dir}", "virtualenvs"),
3939
},
4040
"experimental": {"new-installer": True},
41+
"installer": {"parallel": True},
4142
}
4243

4344
def __init__(
@@ -131,14 +132,22 @@ def process(self, value): # type: (Any) -> Any
131132
return re.sub(r"{(.+?)}", lambda m: self.get(m.group(1)), value)
132133

133134
def _get_validator(self, name): # type: (str) -> Callable
134-
if name in {"virtualenvs.create", "virtualenvs.in-project"}:
135+
if name in {
136+
"virtualenvs.create",
137+
"virtualenvs.in-project",
138+
"installer.parallel",
139+
}:
135140
return boolean_validator
136141

137142
if name == "virtualenvs.path":
138143
return str
139144

140145
def _get_normalizer(self, name): # type: (str) -> Callable
141-
if name in {"virtualenvs.create", "virtualenvs.in-project"}:
146+
if name in {
147+
"virtualenvs.create",
148+
"virtualenvs.in-project",
149+
"installer.parallel",
150+
}:
142151
return boolean_normalizer
143152

144153
if name == "virtualenvs.path":

poetry/console/commands/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def unique_config_values(self):
6363
boolean_normalizer,
6464
True,
6565
),
66+
"installer.parallel": (boolean_validator, boolean_normalizer, True,),
6667
}
6768

6869
return unique_config_values

poetry/installation/executor.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
class Executor(object):
35-
def __init__(self, env, pool, config, io, parallel=True):
35+
def __init__(self, env, pool, config, io, parallel=None):
3636
self._env = env
3737
self._io = io
3838
self._dry_run = False
@@ -42,6 +42,9 @@ def __init__(self, env, pool, config, io, parallel=True):
4242
self._chef = Chef(config, self._env)
4343
self._chooser = Chooser(pool, self._env)
4444

45+
if parallel is None:
46+
parallel = config.get("installer.parallel", True)
47+
4548
if parallel and not (PY2 and WINDOWS):
4649
# This should be directly handled by ThreadPoolExecutor
4750
# however, on some systems the number of CPUs cannot be determined

tests/console/commands/test_config.py

+27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from poetry.config.config_source import ConfigSource
77
from poetry.factory import Factory
8+
from poetry.utils._compat import PY2
9+
from poetry.utils._compat import WINDOWS
810

911

1012
@pytest.fixture()
@@ -17,6 +19,7 @@ def test_list_displays_default_value_if_not_set(tester, config):
1719

1820
expected = """cache-dir = "/foo"
1921
experimental.new-installer = true
22+
installer.parallel = true
2023
virtualenvs.create = true
2124
virtualenvs.in-project = null
2225
virtualenvs.path = {path} # /foo{sep}virtualenvs
@@ -34,6 +37,7 @@ def test_list_displays_set_get_setting(tester, config):
3437

3538
expected = """cache-dir = "/foo"
3639
experimental.new-installer = true
40+
installer.parallel = true
3741
virtualenvs.create = false
3842
virtualenvs.in-project = null
3943
virtualenvs.path = {path} # /foo{sep}virtualenvs
@@ -73,6 +77,7 @@ def test_list_displays_set_get_local_setting(tester, config):
7377

7478
expected = """cache-dir = "/foo"
7579
experimental.new-installer = true
80+
installer.parallel = true
7681
virtualenvs.create = false
7782
virtualenvs.in-project = null
7883
virtualenvs.path = {path} # /foo{sep}virtualenvs
@@ -108,3 +113,25 @@ def test_set_cert(tester, auth_config_source, mocker):
108113
tester.execute("certificates.foo.cert path/to/ca.pem")
109114

110115
assert "path/to/ca.pem" == auth_config_source.config["certificates"]["foo"]["cert"]
116+
117+
118+
@pytest.mark.skipif(
119+
PY2 and WINDOWS, reason="Python 2.7 under windows is enforced serial"
120+
)
121+
def test_config_installer_parallel(tester, command_tester_factory):
122+
tester.execute("--local installer.parallel")
123+
assert tester.io.fetch_output().strip() == "true"
124+
125+
assert (
126+
command_tester_factory("install")._command._installer._executor._max_workers > 1
127+
)
128+
129+
tester.io.clear_output()
130+
tester.execute("--local installer.parallel false")
131+
tester.execute("--local installer.parallel")
132+
assert tester.io.fetch_output().strip() == "false"
133+
134+
assert (
135+
command_tester_factory("install")._command._installer._executor._max_workers
136+
== 1
137+
)

0 commit comments

Comments
 (0)