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

Creating new virtualenv fails with cryptic error for project with empty name #5794

Closed
3 tasks done
mlegner opened this issue Jun 7, 2022 · 3 comments · Fixed by #5856
Closed
3 tasks done

Creating new virtualenv fails with cryptic error for project with empty name #5794

mlegner opened this issue Jun 7, 2022 · 3 comments · Fixed by #5856
Assignees
Labels
kind/bug Something isn't working as expected

Comments

@mlegner
Copy link

mlegner commented Jun 7, 2022

  • I am on the latest Poetry version.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: Linux (Ubuntu 20.04)

  • Poetry version: 1.2.0b2

  • Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/mlegner/39a29fa3d3678a8aedcde45d215e2897

Issue

When creating a new virtualenv via poetry env use python or poetry add someproject for a project with an empty name, it fails with the following output:

$ poetry env use python
Creating virtualenv -6WcazSRI-py3.8 in /home/markus/.cache/pypoetry/virtualenvs
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--read-only-app-data] [--app-data APP_DATA] [--reset-app-data] [--upgrade-embed-wheels] [--discovery {builtin}] [-p py] [--try-first-with py_exe]
                  [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed] [--activators comma_sep_list] [--clear] [--no-vcs-ignore] [--system-site-packages] [--symlinks | --copies] [--no-download | --download]
                  [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip] [--no-setuptools] [--no-wheel] [--no-periodic-update] [--symlink-app-data] [--prompt prompt] [-h]
                  dest
virtualenv: error: argument --prompt: expected one argument

The root of the problem is the virtualenvs.prompt option added in #5606: The standard value there, {project_name}-py{python_version} expands to something like -py3.8 for a project with empty name, which is interpreted as an option in the call to virtualenv instead of the value of --prompt.

I suggest to either add a check for an empty name or add quotes for the call to virtualenv.

@mlegner mlegner added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jun 7, 2022
@abn
Copy link
Member

abn commented Jun 7, 2022

While a project without a name is invalid, we should still handle the case be defaulting to py{python-version} if project_name is empty or otherwise unavailable.

@mlegner
Copy link
Author

mlegner commented Jun 7, 2022

While a project without a name is invalid, we should still handle the case be defaulting to py{python-version} if project_name is empty or otherwise unavailable.

How about instead changing https://github.com/python-poetry/poetry/blob/master/src/poetry/utils/env.py#L1083? From

            args.extend(["--prompt", prompt])

to

            args.extend(["--prompt", f'"{prompt}"'])

This would also fix some other potential issues when users change the virtualenvs.prompt setting.

Copy link

github-actions bot commented Mar 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants