Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system-site-packages setting (rebased) #2686

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ cache-dir = "/path/to/cache/directory"
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = true
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs" # /path/to/cache/directory/virtualenvs
```

@@ -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.
Defaults to `false`.

### `virtualenvs.options.system-site-packages`: boolean

If set to `true` the `--system-site-packages` parameter is passed to `virtualenv` on creation of the venv, giving the virtual environment access to the system site-packages dir.
Defaults to `false`.


### `repositories.<name>`: string

17 changes: 10 additions & 7 deletions poetry/config/config.py
Original file line number Diff line number Diff line change
@@ -35,12 +35,20 @@ class Config(object):
"create": True,
"in-project": None,
"path": os.path.join("{cache-dir}", "virtualenvs"),
"options": {"always-copy": False},
"options": {"always-copy": False, "system-site-packages": False},
},
"experimental": {"new-installer": True},
"installer": {"parallel": True},
}

_boolean_settings = {
"virtualenvs.create",
"virtualenvs.in-project",
"virtualenvs.options.always-copy",
"virtualenvs.options.system-site-packages",
"installer.parallel",
}

def __init__(
self, use_environment=True, base_dir=None
): # type: (bool, Optional[Path]) -> None
@@ -136,12 +144,7 @@ def process(self, value): # type: (Any) -> Any
return re.sub(r"{(.+?)}", lambda m: self.get(m.group(1)), value)

def _get_normalizer(self, name): # type: (str) -> Callable
if name in {
"virtualenvs.create",
"virtualenvs.in-project",
"virtualenvs.options.always-copy",
"installer.parallel",
}:
if name in self._boolean_settings:
return boolean_normalizer

if name == "virtualenvs.path":
5 changes: 5 additions & 0 deletions poetry/console/commands/config.py
Original file line number Diff line number Diff line change
@@ -70,6 +70,11 @@ def unique_config_values(self):
boolean_normalizer,
False,
),
"virtualenvs.options.system-site-packages": (
boolean_validator,
boolean_normalizer,
False,
),
"installer.parallel": (boolean_validator, boolean_normalizer, True,),
}

4 changes: 3 additions & 1 deletion tests/console/commands/env/test_use.py
Original file line number Diff line number Diff line change
@@ -51,7 +51,9 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(

venv_py37 = venv_cache / "{}-py3.7".format(venv_name)
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")
3 changes: 3 additions & 0 deletions tests/console/commands/test_config.py
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ def test_list_displays_default_value_if_not_set(tester, config, config_cache_dir
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {path} # {virtualenvs}
""".format(
cache=json.dumps(str(config_cache_dir)),
@@ -53,6 +54,7 @@ def test_list_displays_set_get_setting(tester, config, config_cache_dir):
virtualenvs.create = false
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {path} # {virtualenvs}
""".format(
cache=json.dumps(str(config_cache_dir)),
@@ -96,6 +98,7 @@ def test_list_displays_set_get_local_setting(tester, config, config_cache_dir):
virtualenvs.create = false
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {path} # {virtualenvs}
""".format(
cache=json.dumps(str(config_cache_dir)),
5 changes: 3 additions & 2 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
@@ -220,5 +220,6 @@ def test_create_poetry_fails_on_invalid_configuration():
def test_create_poetry_with_local_config(fixture_dir):
poetry = Factory().create_poetry(fixture_dir("with_local_config"))

assert not poetry.config.get("virtualenvs.in-project")
assert not poetry.config.get("virtualenvs.create")
assert poetry.config.get("virtualenvs.in-project") is False
assert poetry.config.get("virtualenvs.create") is False
assert poetry.config.get("virtualenvs.options.system-site-packages") is False
37 changes: 29 additions & 8 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
m.assert_called_with(
Path(tmp_dir) / "{}-py3.7".format(venv_name),
executable="python3.7",
flags={"always-copy": False},
flags={"always-copy": False, "system-site-packages": False},
)

envs_file = TOMLFile(Path(tmp_dir) / "envs.toml")
@@ -274,7 +274,7 @@ def test_activate_activates_different_virtualenv_with_envs_file(
m.assert_called_with(
Path(tmp_dir) / "{}-py3.6".format(venv_name),
executable="python3.6",
flags={"always-copy": False},
flags={"always-copy": False, "system-site-packages": False},
)

assert envs_file.exists()
@@ -327,7 +327,7 @@ def test_activate_activates_recreates_for_different_patch(
build_venv_m.assert_called_with(
Path(tmp_dir) / "{}-py3.7".format(venv_name),
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))

@@ -608,6 +608,27 @@ def err_on_rm_venv_only(path, *args, **kwargs):
m.side_effect = original_rmtree # Avoid teardown using `err_on_rm_venv_only`


@pytest.mark.parametrize("system_site_packages", [True, False])
def test_env_system_packages(tmp_dir, config, system_site_packages):
venv_path = Path(tmp_dir) / "venv"
EnvManager(config).build_venv(
str(venv_path), flags={"system-site-packages": system_site_packages}
)
pyvenv_cfg = venv_path / "pyvenv.cfg"
if sys.version_info >= (3, 3):
expected = "include-system-site-packages = {}".format(
"true" if system_site_packages else "false"
)
assert expected in pyvenv_cfg.read_text()
elif (2, 6) < sys.version_info < (3, 0):
assert (
system_site_packages
== venv_path.joinpath(
"lib", "python2.7", "no-global-site-packages.txt"
).exists()
)


@pytest.mark.skipif(os.name == "nt", reason="Symlinks are not support for Windows")
def test_env_has_symlinks_on_nix(tmp_dir, tmp_venv):
assert os.path.islink(tmp_venv.python)
@@ -651,7 +672,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_
m.assert_called_with(
config_virtualenvs_path / "{}-py3.7".format(venv_name),
executable="python3",
flags={"always-copy": False},
flags={"always-copy": False, "system-site-packages": False},
)


@@ -675,7 +696,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
m.assert_called_with(
config_virtualenvs_path / "{}-py3.9".format(venv_name),
executable="python3.9",
flags={"always-copy": False},
flags={"always-copy": False, "system-site-packages": False},
)


@@ -759,7 +780,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
config_virtualenvs_path
/ "{}-py{}.{}".format(venv_name, version.major, version.minor),
executable=None,
flags={"always-copy": False},
flags={"always-copy": False, "system-site-packages": False},
)


@@ -794,7 +815,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
config_virtualenvs_path
/ "{}-py{}.{}".format(venv_name, 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},
)


@@ -827,7 +848,7 @@ def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
m.assert_called_with(
poetry.file.parent / ".venv",
executable="python3.7",
flags={"always-copy": False},
flags={"always-copy": False, "system-site-packages": False},
)

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