Skip to content

Commit

Permalink
Cover edge case when environment is being created with empty project …
Browse files Browse the repository at this point in the history
…name (#5856)
  • Loading branch information
Secrus authored Aug 15, 2022
1 parent 7bb0a87 commit a896884
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,8 @@ def create_venv(

if venv_prompt is not None:
venv_prompt = venv_prompt.format(
project_name=self._poetry.package.name, python_version=python_minor
project_name=self._poetry.package.name or "virtualenv",
python_version=python_minor,
)

if not venv.exists():
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/no_name_project/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
No name project
===============
18 changes: 18 additions & 0 deletions tests/fixtures/no_name_project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = ""
version = "1.2.3"
description = "This project has no name"
authors = [
"Sébastien Eustace <[email protected]>"
]
license = "MIT"

readme = "README.rst"


# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"

[tool.poetry.group.dev.dependencies]
pytest = "~3.4"
40 changes: 40 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,3 +1415,43 @@ def test_build_environment_not_called_without_build_script_specified(
with build_environment(poetry, project_env) as env:
assert env == project_env
assert not env.executed


def test_create_venv_project_name_empty_sets_correct_prompt(
project_factory: ProjectFactory,
config: Config,
mocker: MockerFixture,
config_virtualenvs_path: Path,
):
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

fixture = Path(__file__).parent.parent / "fixtures" / "no_name_project"
poetry = project_factory("no", source=fixture)
manager = EnvManager(poetry)

poetry.package.python_versions = "^3.7"
venv_name = manager.generate_env_name("", str(poetry.file.parent))

mocker.patch("sys.version_info", (2, 7, 16))
mocker.patch(
"subprocess.check_output",
side_effect=check_output_wrapper(Version.parse("3.7.5")),
)
m = mocker.patch(
"poetry.utils.env.EnvManager.build_venv", side_effect=lambda *args, **kwargs: ""
)

manager.create_venv(NullIO())

m.assert_called_with(
config_virtualenvs_path / f"{venv_name}-py3.7",
executable="python3",
flags={
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="virtualenv-py3.7",
)

0 comments on commit a896884

Please sign in to comment.