Commit c349357b by Sébastien Eustace Committed by GitHub

Fix an error in env use if the virtualenvs.in-project setting is activated (#1682)

parent c78503e5
......@@ -208,6 +208,24 @@ class EnvManager(object):
patch = python_version.text
create = False
is_root_venv = self._poetry.config.get("virtualenvs.in-project")
# If we are required to create the virtual environment in the root folder,
# create or recreate it if needed
if is_root_venv:
create = False
venv = self._poetry.file.parent / ".venv"
if venv.exists():
# We need to check if the patch version is correct
_venv = VirtualEnv(venv)
current_patch = ".".join(str(v) for v in _venv.version_info[:3])
if patch != current_patch:
create = True
self.create_venv(io, executable=python, force=create)
return self.get(reload=True)
envs = tomlkit.document()
base_env_name = self.generate_env_name(self._poetry.package.name, str(cwd))
if envs_file.exists():
......
......@@ -661,3 +661,38 @@ def test_create_venv_does_not_try_to_find_compatible_versions_with_executable(
assert expected_message == str(e.value)
assert 0 == m.call_count
def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
manager, poetry, config, tmp_dir, mocker
):
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
config.merge(
{
"virtualenvs": {
"path": str(Path(tmp_dir) / "virtualenvs"),
"in-project": True,
}
}
)
mocker.patch(
"poetry.utils._compat.subprocess.check_output",
side_effect=check_output_wrapper(),
)
mocker.patch(
"poetry.utils._compat.subprocess.Popen.communicate",
side_effect=[("/prefix", None), ("/prefix", None)],
)
m = mocker.patch("poetry.utils.env.EnvManager.build_venv")
manager.activate("python3.7", NullIO())
m.assert_called_with(
os.path.join(str(poetry.file.parent), ".venv"), executable="python3.7"
)
envs_file = TomlFile(Path(tmp_dir) / "virtualenvs" / "envs.toml")
assert not envs_file.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