diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 6c7e60deb34..fa690b797be 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -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(): diff --git a/tests/fixtures/no_name_project/README.rst b/tests/fixtures/no_name_project/README.rst new file mode 100644 index 00000000000..8b194670930 --- /dev/null +++ b/tests/fixtures/no_name_project/README.rst @@ -0,0 +1,2 @@ +No name project +=============== diff --git a/tests/fixtures/no_name_project/pyproject.toml b/tests/fixtures/no_name_project/pyproject.toml new file mode 100644 index 00000000000..f18fa403c06 --- /dev/null +++ b/tests/fixtures/no_name_project/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "" +version = "1.2.3" +description = "This project has no name" +authors = [ + "Sébastien Eustace " +] +license = "MIT" + +readme = "README.rst" + + +# Requirements +[tool.poetry.dependencies] +python = "~2.7 || ^3.6" + +[tool.poetry.group.dev.dependencies] +pytest = "~3.4" diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index 03c1e4c29ff..32fb5cb0865 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -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", + )