Skip to content

Commit a938781

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 68d6939 commit a938781

File tree

6 files changed

+64
-8
lines changed

6 files changed

+64
-8
lines changed

Diff for: docs/docs/configuration.md

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

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

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

Diff for: poetry/config/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Config(object):
3939
"options": {"always-copy": False},
4040
},
4141
"experimental": {"new-installer": True},
42+
"installer": {"parallel": True},
4243
}
4344

4445
def __init__(
@@ -140,6 +141,7 @@ def _get_validator(self, name): # type: (str) -> Callable
140141
"virtualenvs.create",
141142
"virtualenvs.in-project",
142143
"virtualenvs.options.always-copy",
144+
"installer.parallel",
143145
}:
144146
return boolean_validator
145147

@@ -151,6 +153,7 @@ def _get_normalizer(self, name): # type: (str) -> Callable
151153
"virtualenvs.create",
152154
"virtualenvs.in-project",
153155
"virtualenvs.options.always-copy",
156+
"installer.parallel",
154157
}:
155158
return boolean_normalizer
156159

Diff for: poetry/console/commands/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def unique_config_values(self):
6969
boolean_normalizer,
7070
False,
7171
),
72+
"installer.parallel": (boolean_validator, boolean_normalizer, True,),
7273
}
7374

7475
return unique_config_values

Diff for: 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

Diff for: tests/config/test_config.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
import os
22

3+
import pytest
34

4-
def test_config_get_default_value(config):
5-
assert config.get("virtualenvs.create") is True
5+
6+
@pytest.mark.parametrize(
7+
("name", "value"), [("installer.parallel", True), ("virtualenvs.create", True)]
8+
)
9+
def test_config_get_default_value(config, name, value):
10+
assert config.get(name) is value
611

712

813
def test_config_get_processes_depended_on_values(config):
914
assert os.path.join("/foo", "virtualenvs") == config.get("virtualenvs.path")
1015

1116

12-
def test_config_get_from_environment_variable(config, environ):
13-
assert config.get("virtualenvs.create")
14-
15-
os.environ["POETRY_VIRTUALENVS_CREATE"] = "false"
16-
assert not config.get("virtualenvs.create")
17+
@pytest.mark.parametrize(
18+
("name", "env_value", "value"),
19+
[
20+
("installer.parallel", "true", True),
21+
("installer.parallel", "false", False),
22+
("virtualenvs.create", "true", True),
23+
("virtualenvs.create", "false", False),
24+
],
25+
)
26+
def test_config_get_from_environment_variable(config, environ, name, env_value, value):
27+
env_var = "POETRY_{}".format("_".join(k.upper() for k in name.split(".")))
28+
os.environ[env_var] = env_value
29+
assert config.get(name) is value

Diff for: tests/console/commands/test_config.py

+27
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from poetry.config.config_source import ConfigSource
77
from poetry.core.pyproject import PyProjectException
88
from poetry.factory import Factory
9+
from poetry.utils._compat import PY2
10+
from poetry.utils._compat import WINDOWS
911

1012

1113
@pytest.fixture()
@@ -28,6 +30,7 @@ def test_list_displays_default_value_if_not_set(tester, config):
2830

2931
expected = """cache-dir = "/foo"
3032
experimental.new-installer = true
33+
installer.parallel = true
3134
virtualenvs.create = true
3235
virtualenvs.in-project = null
3336
virtualenvs.options.always-copy = false
@@ -46,6 +49,7 @@ def test_list_displays_set_get_setting(tester, config):
4649

4750
expected = """cache-dir = "/foo"
4851
experimental.new-installer = true
52+
installer.parallel = true
4953
virtualenvs.create = false
5054
virtualenvs.in-project = null
5155
virtualenvs.options.always-copy = false
@@ -86,6 +90,7 @@ def test_list_displays_set_get_local_setting(tester, config):
8690

8791
expected = """cache-dir = "/foo"
8892
experimental.new-installer = true
93+
installer.parallel = true
8994
virtualenvs.create = false
9095
virtualenvs.in-project = null
9196
virtualenvs.options.always-copy = false
@@ -122,3 +127,25 @@ def test_set_cert(tester, auth_config_source, mocker):
122127
tester.execute("certificates.foo.cert path/to/ca.pem")
123128

124129
assert "path/to/ca.pem" == auth_config_source.config["certificates"]["foo"]["cert"]
130+
131+
132+
def test_config_installer_parallel(tester, command_tester_factory):
133+
serial_enforced = PY2 and WINDOWS
134+
135+
tester.execute("--local installer.parallel")
136+
assert tester.io.fetch_output().strip() == "true"
137+
138+
workers = command_tester_factory(
139+
"install"
140+
)._command._installer._executor._max_workers
141+
assert workers > 1 or (serial_enforced and workers == 1)
142+
143+
tester.io.clear_output()
144+
tester.execute("--local installer.parallel false")
145+
tester.execute("--local installer.parallel")
146+
assert tester.io.fetch_output().strip() == "false"
147+
148+
workers = command_tester_factory(
149+
"install"
150+
)._command._installer._executor._max_workers
151+
assert workers == 1

0 commit comments

Comments
 (0)