Commit 38558a19 by vlad0337187 Committed by Arun Babu Neelicattu

feature(virtualenv): add 'system-site-packages' option

parent 37b36f48
...@@ -35,6 +35,7 @@ cache-dir = "/path/to/cache/directory" ...@@ -35,6 +35,7 @@ cache-dir = "/path/to/cache/directory"
virtualenvs.create = true virtualenvs.create = true
virtualenvs.in-project = null virtualenvs.in-project = null
virtualenvs.options.always-copy = true virtualenvs.options.always-copy = true
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs" # /path/to/cache/directory/virtualenvs virtualenvs.path = "{cache-dir}/virtualenvs" # /path/to/cache/directory/virtualenvs
``` ```
...@@ -143,6 +144,11 @@ Defaults to `{cache-dir}/virtualenvs` (`{cache-dir}\virtualenvs` on Windows). ...@@ -143,6 +144,11 @@ Defaults to `{cache-dir}/virtualenvs` (`{cache-dir}\virtualenvs` on Windows).
If set to `true` the `--always-copy` parameter is passed to `virtualenv` on creation of the venv. Thus all needed files are copied into the venv instead of symlinked. If set to `true` the `--always-copy` parameter is passed to `virtualenv` on creation of the venv. Thus all needed files are copied into the venv instead of symlinked.
Defaults to `false`. Defaults to `false`.
### `virtualenvs.options.system-site-packages`: boolean
Give the virtual environment access to the system site-packages directory.
Applies on virtualenv creation.
Defaults to `false`.
### `repositories.<name>`: string ### `repositories.<name>`: string
......
...@@ -35,7 +35,7 @@ class Config(object): ...@@ -35,7 +35,7 @@ class Config(object):
"create": True, "create": True,
"in-project": None, "in-project": None,
"path": os.path.join("{cache-dir}", "virtualenvs"), "path": os.path.join("{cache-dir}", "virtualenvs"),
"options": {"always-copy": False}, "options": {"always-copy": False, "system-site-packages": False},
}, },
"experimental": {"new-installer": True}, "experimental": {"new-installer": True},
"installer": {"parallel": True}, "installer": {"parallel": True},
...@@ -140,6 +140,7 @@ class Config(object): ...@@ -140,6 +140,7 @@ class Config(object):
"virtualenvs.create", "virtualenvs.create",
"virtualenvs.in-project", "virtualenvs.in-project",
"virtualenvs.options.always-copy", "virtualenvs.options.always-copy",
"virtualenvs.options.system-site-packages",
"installer.parallel", "installer.parallel",
}: }:
return boolean_normalizer return boolean_normalizer
......
...@@ -62,6 +62,16 @@ To remove a repository (repo is a short alias for repositories): ...@@ -62,6 +62,16 @@ To remove a repository (repo is a short alias for repositories):
), ),
"virtualenvs.create": (boolean_validator, boolean_normalizer, True), "virtualenvs.create": (boolean_validator, boolean_normalizer, True),
"virtualenvs.in-project": (boolean_validator, boolean_normalizer, False), "virtualenvs.in-project": (boolean_validator, boolean_normalizer, False),
"virtualenvs.options.always-copy": (
boolean_validator,
boolean_normalizer,
False,
),
"virtualenvs.options.system-site-packages": (
boolean_validator,
boolean_normalizer,
False,
),
"virtualenvs.path": ( "virtualenvs.path": (
str, str,
lambda val: str(Path(val)), lambda val: str(Path(val)),
...@@ -72,11 +82,6 @@ To remove a repository (repo is a short alias for repositories): ...@@ -72,11 +82,6 @@ To remove a repository (repo is a short alias for repositories):
boolean_normalizer, boolean_normalizer,
True, True,
), ),
"virtualenvs.options.always-copy": (
boolean_validator,
boolean_normalizer,
False,
),
"installer.parallel": ( "installer.parallel": (
boolean_validator, boolean_validator,
boolean_normalizer, boolean_normalizer,
......
...@@ -637,8 +637,8 @@ class EnvManager(object): ...@@ -637,8 +637,8 @@ class EnvManager(object):
create_venv = self._poetry.config.get("virtualenvs.create") create_venv = self._poetry.config.get("virtualenvs.create")
root_venv = self._poetry.config.get("virtualenvs.in-project") root_venv = self._poetry.config.get("virtualenvs.in-project")
venv_path = self._poetry.config.get("virtualenvs.path") venv_path = self._poetry.config.get("virtualenvs.path")
if root_venv: if root_venv:
venv_path = cwd / ".venv" venv_path = cwd / ".venv"
elif venv_path is None: elif venv_path is None:
......
...@@ -52,7 +52,9 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file( ...@@ -52,7 +52,9 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
venv_py37 = venv_cache / "{}-py3.7".format(venv_name) venv_py37 = venv_cache / "{}-py3.7".format(venv_name)
mock_build_env.assert_called_with( mock_build_env.assert_called_with(
venv_py37, executable="python3.7", flags={"always-copy": False} venv_py37,
executable="python3.7",
flags={"always-copy": False, "system-site-packages": False},
) )
envs_file = TOMLFile(venv_cache / "envs.toml") envs_file = TOMLFile(venv_cache / "envs.toml")
......
...@@ -32,6 +32,7 @@ installer.parallel = true ...@@ -32,6 +32,7 @@ installer.parallel = true
virtualenvs.create = true virtualenvs.create = true
virtualenvs.in-project = null virtualenvs.in-project = null
virtualenvs.options.always-copy = false virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {path} # {virtualenvs} virtualenvs.path = {path} # {virtualenvs}
""".format( """.format(
cache=json.dumps(str(config_cache_dir)), cache=json.dumps(str(config_cache_dir)),
...@@ -53,6 +54,7 @@ installer.parallel = true ...@@ -53,6 +54,7 @@ installer.parallel = true
virtualenvs.create = false virtualenvs.create = false
virtualenvs.in-project = null virtualenvs.in-project = null
virtualenvs.options.always-copy = false virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {path} # {virtualenvs} virtualenvs.path = {path} # {virtualenvs}
""".format( """.format(
cache=json.dumps(str(config_cache_dir)), cache=json.dumps(str(config_cache_dir)),
...@@ -96,6 +98,7 @@ installer.parallel = true ...@@ -96,6 +98,7 @@ installer.parallel = true
virtualenvs.create = false virtualenvs.create = false
virtualenvs.in-project = null virtualenvs.in-project = null
virtualenvs.options.always-copy = false virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {path} # {virtualenvs} virtualenvs.path = {path} # {virtualenvs}
""".format( """.format(
cache=json.dumps(str(config_cache_dir)), cache=json.dumps(str(config_cache_dir)),
......
...@@ -222,3 +222,5 @@ def test_create_poetry_with_local_config(fixture_dir): ...@@ -222,3 +222,5 @@ def test_create_poetry_with_local_config(fixture_dir):
assert not poetry.config.get("virtualenvs.in-project") assert not poetry.config.get("virtualenvs.in-project")
assert not poetry.config.get("virtualenvs.create") assert not poetry.config.get("virtualenvs.create")
assert not poetry.config.get("virtualenvs.options.always-copy")
assert not poetry.config.get("virtualenvs.options.system-site-packages")
...@@ -159,7 +159,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file( ...@@ -159,7 +159,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
m.assert_called_with( m.assert_called_with(
Path(tmp_dir) / "{}-py3.7".format(venv_name), Path(tmp_dir) / "{}-py3.7".format(venv_name),
executable="python3.7", executable="python3.7",
flags={"always-copy": False}, flags={"always-copy": False, "system-site-packages": False},
) )
envs_file = TOMLFile(Path(tmp_dir) / "envs.toml") envs_file = TOMLFile(Path(tmp_dir) / "envs.toml")
...@@ -279,7 +279,7 @@ def test_activate_activates_different_virtualenv_with_envs_file( ...@@ -279,7 +279,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
m.assert_called_with( m.assert_called_with(
Path(tmp_dir) / "{}-py3.6".format(venv_name), Path(tmp_dir) / "{}-py3.6".format(venv_name),
executable="python3.6", executable="python3.6",
flags={"always-copy": False}, flags={"always-copy": False, "system-site-packages": False},
) )
assert envs_file.exists() assert envs_file.exists()
...@@ -333,7 +333,7 @@ def test_activate_activates_recreates_for_different_patch( ...@@ -333,7 +333,7 @@ def test_activate_activates_recreates_for_different_patch(
build_venv_m.assert_called_with( build_venv_m.assert_called_with(
Path(tmp_dir) / "{}-py3.7".format(venv_name), Path(tmp_dir) / "{}-py3.7".format(venv_name),
executable="python3.7", executable="python3.7",
flags={"always-copy": False}, flags={"always-copy": False, "system-site-packages": False},
) )
remove_venv_m.assert_called_with(Path(tmp_dir) / "{}-py3.7".format(venv_name)) remove_venv_m.assert_called_with(Path(tmp_dir) / "{}-py3.7".format(venv_name))
...@@ -661,7 +661,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_ ...@@ -661,7 +661,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_
m.assert_called_with( m.assert_called_with(
config_virtualenvs_path / "{}-py3.7".format(venv_name), config_virtualenvs_path / "{}-py3.7".format(venv_name),
executable="python3", executable="python3",
flags={"always-copy": False}, flags={"always-copy": False, "system-site-packages": False},
) )
...@@ -685,7 +685,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific ...@@ -685,7 +685,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
m.assert_called_with( m.assert_called_with(
config_virtualenvs_path / "{}-py3.9".format(venv_name), config_virtualenvs_path / "{}-py3.9".format(venv_name),
executable="python3.9", executable="python3.9",
flags={"always-copy": False}, flags={"always-copy": False, "system-site-packages": False},
) )
...@@ -769,7 +769,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility( ...@@ -769,7 +769,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
config_virtualenvs_path config_virtualenvs_path
/ "{}-py{}.{}".format(venv_name, version.major, version.minor), / "{}-py{}.{}".format(venv_name, version.major, version.minor),
executable=None, executable=None,
flags={"always-copy": False}, flags={"always-copy": False, "system-site-packages": False},
) )
...@@ -804,7 +804,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable( ...@@ -804,7 +804,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
config_virtualenvs_path config_virtualenvs_path
/ "{}-py{}.{}".format(venv_name, version.major, version.minor - 1), / "{}-py{}.{}".format(venv_name, version.major, version.minor - 1),
executable="python{}.{}".format(version.major, version.minor - 1), executable="python{}.{}".format(version.major, version.minor - 1),
flags={"always-copy": False}, flags={"always-copy": False, "system-site-packages": False},
) )
...@@ -838,7 +838,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir( ...@@ -838,7 +838,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
m.assert_called_with( m.assert_called_with(
poetry.file.parent / ".venv", poetry.file.parent / ".venv",
executable="python3.7", executable="python3.7",
flags={"always-copy": False}, flags={"always-copy": False, "system-site-packages": False},
) )
envs_file = TOMLFile(Path(tmp_dir) / "virtualenvs" / "envs.toml") envs_file = TOMLFile(Path(tmp_dir) / "virtualenvs" / "envs.toml")
...@@ -875,3 +875,17 @@ def test_venv_has_correct_paths(tmp_venv): ...@@ -875,3 +875,17 @@ def test_venv_has_correct_paths(tmp_venv):
assert paths.get("platlib") is not None assert paths.get("platlib") is not None
assert paths.get("scripts") is not None assert paths.get("scripts") is not None
assert tmp_venv.site_packages.path == Path(paths["purelib"]) assert tmp_venv.site_packages.path == Path(paths["purelib"])
def test_env_system_packages(tmp_path, config):
venv_path = tmp_path / "venv"
pyvenv_cfg = venv_path / "pyvenv.cfg"
EnvManager(config).build_venv(path=venv_path, flags={"system-site-packages": True})
if sys.version_info >= (3, 3):
assert "include-system-site-packages = true" in pyvenv_cfg.read_text()
elif (2, 6) < sys.version_info < (3, 0):
assert not venv_path.joinpath(
"lib", "python2.7", "no-global-site-packages.txt"
).exists()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment