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

Cover edge case when environment is being created with empty project name #5856

Merged
merged 4 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
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
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",
)