Skip to content

Commit 7db94d0

Browse files
committed
move always-copy option to virtualenvs.options namespace
fix issue for showing all configs when options has more then two level
1 parent a5ae42f commit 7db94d0

File tree

7 files changed

+46
-25
lines changed

7 files changed

+46
-25
lines changed

Diff for: poetry/config/config.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Config(object):
3636
"create": True,
3737
"in-project": None,
3838
"path": os.path.join("{cache-dir}", "virtualenvs"),
39-
"always-copy": False,
39+
"options": {"always-copy": False},
4040
},
4141
"experimental": {"new-installer": True},
4242
}
@@ -88,7 +88,11 @@ def _all(config, parent_key=""):
8888
for key in config:
8989
value = self.get(parent_key + key)
9090
if isinstance(value, dict):
91-
all_[key] = _all(config[key], parent_key=key + ".")
91+
if parent_key != "":
92+
current_parent = parent_key + key + "."
93+
else:
94+
current_parent = key + "."
95+
all_[key] = _all(config[key], parent_key=current_parent)
9296
continue
9397

9498
all_[key] = value
@@ -132,14 +136,22 @@ def process(self, value): # type: (Any) -> Any
132136
return re.sub(r"{(.+?)}", lambda m: self.get(m.group(1)), value)
133137

134138
def _get_validator(self, name): # type: (str) -> Callable
135-
if name in {"virtualenvs.create", "virtualenvs.in-project"}:
139+
if name in {
140+
"virtualenvs.create",
141+
"virtualenvs.in-project",
142+
"virtualenvs.options.always-copy",
143+
}:
136144
return boolean_validator
137145

138146
if name == "virtualenvs.path":
139147
return str
140148

141149
def _get_normalizer(self, name): # type: (str) -> Callable
142-
if name in {"virtualenvs.create", "virtualenvs.in-project"}:
150+
if name in {
151+
"virtualenvs.create",
152+
"virtualenvs.in-project",
153+
"virtualenvs.options.always-copy",
154+
}:
143155
return boolean_normalizer
144156

145157
if name == "virtualenvs.path":

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ def unique_config_values(self):
5858
lambda val: str(Path(val)),
5959
str(Path(CACHE_DIR) / "virtualenvs"),
6060
),
61-
"virtualenvs.always-copy": (boolean_validator, boolean_normalizer, False),
6261
"experimental.new-installer": (
6362
boolean_validator,
6463
boolean_normalizer,
6564
True,
6665
),
66+
"virtualenvs.options.always-copy": (
67+
boolean_validator,
68+
boolean_normalizer,
69+
False,
70+
),
6771
}
6872

6973
return unique_config_values

Diff for: poetry/utils/env.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def create_venv(
645645
self.build_venv(
646646
venv,
647647
executable=executable,
648-
always_copy=self._poetry.config.get("virtualenvs.always-copy"),
648+
flags=self._poetry.config.get("virtualenvs.options"),
649649
)
650650
else:
651651
if force:
@@ -662,7 +662,7 @@ def create_venv(
662662
self.build_venv(
663663
venv,
664664
executable=executable,
665-
always_copy=self._poetry.config.get("virtualenvs.always-copy"),
665+
flags=self._poetry.config.get("virtualenvs.options"),
666666
)
667667
elif io.is_very_verbose():
668668
io.write_line("Virtualenv <c1>{}</> already exists.".format(name))
@@ -687,8 +687,10 @@ def create_venv(
687687

688688
@classmethod
689689
def build_venv(
690-
cls, path, executable=None, always_copy=False
691-
): # type: (Union[Path,str], Optional[Union[str, Path]], bool) -> virtualenv.run.session.Session
690+
cls, path, executable=None, flags=None
691+
): # type: (Union[Path,str], Optional[Union[str, Path]], Dict[str, bool]) -> virtualenv.run.session.Session
692+
flags = flags or {}
693+
692694
if isinstance(executable, Path):
693695
executable = executable.resolve().as_posix()
694696

@@ -700,8 +702,9 @@ def build_venv(
700702
str(path),
701703
]
702704

703-
if always_copy:
704-
args.insert(0, "--always-copy")
705+
for flag, value in flags.items():
706+
if value is True:
707+
args.insert(0, "--{}".format(flag))
705708

706709
return virtualenv.cli_run(args)
707710

Diff for: tests/console/commands/env/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def build_venv(
9-
path, executable=None, always_copy=False
9+
path, executable=None, flags=None
1010
): # type: (Union[Path,str], Optional[str], bool) -> ()
1111
Path(path).mkdir(parents=True, exist_ok=True)
1212

Diff for: tests/console/commands/env/test_use.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
5151

5252
venv_py37 = venv_cache / "{}-py3.7".format(venv_name)
5353
mock_build_env.assert_called_with(
54-
venv_py37, executable="python3.7", always_copy=False
54+
venv_py37, executable="python3.7", flags={"always-copy": False}
5555
)
5656

5757
envs_file = TOMLFile(venv_cache / "envs.toml")

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def test_list_displays_default_value_if_not_set(tester, config):
1717

1818
expected = """cache-dir = "/foo"
1919
experimental.new-installer = true
20-
virtualenvs.always-copy = false
2120
virtualenvs.create = true
2221
virtualenvs.in-project = null
22+
virtualenvs.options.always-copy = false
2323
virtualenvs.path = {path} # /foo{sep}virtualenvs
2424
""".format(
2525
path=json.dumps(os.path.join("{cache-dir}", "virtualenvs")), sep=os.path.sep
@@ -35,9 +35,9 @@ def test_list_displays_set_get_setting(tester, config):
3535

3636
expected = """cache-dir = "/foo"
3737
experimental.new-installer = true
38-
virtualenvs.always-copy = false
3938
virtualenvs.create = false
4039
virtualenvs.in-project = null
40+
virtualenvs.options.always-copy = false
4141
virtualenvs.path = {path} # /foo{sep}virtualenvs
4242
""".format(
4343
path=json.dumps(os.path.join("{cache-dir}", "virtualenvs")), sep=os.path.sep
@@ -75,9 +75,9 @@ def test_list_displays_set_get_local_setting(tester, config):
7575

7676
expected = """cache-dir = "/foo"
7777
experimental.new-installer = true
78-
virtualenvs.always-copy = false
7978
virtualenvs.create = false
8079
virtualenvs.in-project = null
80+
virtualenvs.options.always-copy = false
8181
virtualenvs.path = {path} # /foo{sep}virtualenvs
8282
""".format(
8383
path=json.dumps(os.path.join("{cache-dir}", "virtualenvs")), sep=os.path.sep

Diff for: tests/utils/test_env.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_env_get_venv_with_venv_folder_present(
119119

120120

121121
def build_venv(
122-
path, executable=None, always_copy=False
122+
path, executable=None, flags=None
123123
): # type: (Union[Path,str], Optional[str], bool) -> ()
124124
os.mkdir(str(path))
125125

@@ -160,7 +160,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
160160
m.assert_called_with(
161161
Path(tmp_dir) / "{}-py3.7".format(venv_name),
162162
executable="python3.7",
163-
always_copy=False,
163+
flags={"always-copy": False},
164164
)
165165

166166
envs_file = TOMLFile(Path(tmp_dir) / "envs.toml")
@@ -280,7 +280,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
280280
m.assert_called_with(
281281
Path(tmp_dir) / "{}-py3.6".format(venv_name),
282282
executable="python3.6",
283-
always_copy=False,
283+
flags={"always-copy": False},
284284
)
285285

286286
assert envs_file.exists()
@@ -334,7 +334,7 @@ def test_activate_activates_recreates_for_different_patch(
334334
build_venv_m.assert_called_with(
335335
Path(tmp_dir) / "{}-py3.7".format(venv_name),
336336
executable="python3.7",
337-
always_copy=False,
337+
flags={"always-copy": False},
338338
)
339339
remove_venv_m.assert_called_with(Path(tmp_dir) / "{}-py3.7".format(venv_name))
340340

@@ -664,7 +664,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_
664664
m.assert_called_with(
665665
Path("/foo/virtualenvs/{}-py3.7".format(venv_name)),
666666
executable="python3",
667-
always_copy=False,
667+
flags={"always-copy": False},
668668
)
669669

670670

@@ -690,7 +690,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
690690
m.assert_called_with(
691691
Path("/foo/virtualenvs/{}-py3.9".format(venv_name)),
692692
executable="python3.9",
693-
always_copy=False,
693+
flags={"always-copy": False},
694694
)
695695

696696

@@ -779,7 +779,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
779779
)
780780
),
781781
executable=None,
782-
always_copy=False,
782+
flags={"always-copy": False},
783783
)
784784

785785

@@ -817,7 +817,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
817817
)
818818
),
819819
executable="python{}.{}".format(version.major, version.minor - 1),
820-
always_copy=False,
820+
flags={"always-copy": False},
821821
)
822822

823823

@@ -849,7 +849,9 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
849849
manager.activate("python3.7", NullIO())
850850

851851
m.assert_called_with(
852-
poetry.file.parent / ".venv", executable="python3.7", always_copy=False
852+
poetry.file.parent / ".venv",
853+
executable="python3.7",
854+
flags={"always-copy": False},
853855
)
854856

855857
envs_file = TOMLFile(Path(tmp_dir) / "virtualenvs" / "envs.toml")

0 commit comments

Comments
 (0)