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

Intersection requirement in pyproject.toml rendered incorrectly in setup.py #1522

Closed
3 tasks done
connorbrinton opened this issue Oct 30, 2019 · 5 comments · Fixed by python-poetry/poetry-core#79
Closed
3 tasks done
Labels
kind/bug Something isn't working as expected

Comments

@connorbrinton
Copy link
Contributor

connorbrinton commented Oct 30, 2019

  • 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).

Issue

When running poetry install, Poetry translates the pyproject.toml requirement:

torch = "^1.3, !=1.3.0.post2"

To the following setup.py requirement:

install_requires = \
['torch^1.3, !=1.3.0.post2']

Which is rejected by pip, since it's not a valid PEP 508 version specifier.

Instructions to reproduce:

  • Download pyproject.toml and place in a directory
  • Create src/test78/__init__.py with the commands:
mkdir -p src/test78
touch src/test78/__init__.py
  • Run poetry install

Expected result: Success

Actual result:

Using virtualenv: /Users/.../Library/Caches/pypoetry/virtualenvs/test78-1boLTIX3-py3.7
Installing dependencies from lock file

Nothing to install or update

  - Skipping future (0.18.1) Already installed
  - Skipping numpy (1.17.3) Already installed
  - Skipping torch (1.3.0) Already installed
  - Installing test78 (0.1.0)

[EnvCommandError]
Command ['/Users/.../Library/Caches/pypoetry/virtualenvs/test78-1boLTIX3-py3.7/bin/python', '-m', 'pip', 'install', '-e', '/Users/.../Dropbox/Career/.../samples/test78'] errored with the following return code 1, and output: 
Obtaining file:///Users/.../Dropbox/Career/.../samples/test78
    Complete output from command python setup.py egg_info:
    error in test78 setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'^1.3, !='"
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /Users/.../Dropbox/Career/.../samples/test78/
You are using pip version 19.0.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


Traceback (most recent call last):
  File "/Users/.../.poetry/lib/poetry/_vendor/py3.7/clikit/console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "/Users/.../.poetry/lib/poetry/_vendor/py3.7/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "/Users/.../.poetry/lib/poetry/_vendor/py3.7/clikit/api/command/command.py", line 171, in _do_handle
    return getattr(handler, handler_method)(args, io, self)
  File "/Users/.../.poetry/lib/poetry/_vendor/py3.7/cleo/commands/command.py", line 92, in wrap_handle
    return self.handle()
  File "/Users/.../.poetry/lib/poetry/console/commands/install.py", line 88, in handle
    builder.build()
  File "/Users/.../.poetry/lib/poetry/masonry/builders/editable.py", line 17, in build
    return self._setup_build()
  File "/Users/.../.poetry/lib/poetry/masonry/builders/editable.py", line 42, in _setup_build
    'python', '-m', 'pip', 'install', '-e', str(self._path)
  File "/Users/.../.poetry/lib/poetry/utils/env.py", line 988, in run
    return super(VirtualEnv, self).run(bin, *args, **kwargs)
  File "/Users/.../.poetry/lib/poetry/utils/env.py", line 812, in run
    raise EnvCommandError(e, input=input_)

I used entr to also grab the contents of the temporary setup.py file generated by Poetry, available in this gist.

@connorbrinton connorbrinton added the kind/bug Something isn't working as expected label Oct 30, 2019
@tomzx
Copy link
Contributor

tomzx commented Dec 18, 2019

I'm encountering the same issue. It seems that the package = "^1.2.3, !=1.3.0" gets turned into package^1.2.3,!=1.3.0" in setup.py, while it should have been package>=1.2.3,<1.3.0,!=1.3.0. Given PEP508 (pointed in the original message), this is not a valid constraint string.

Temporary fix is to replace the ^ constraint with its >=,< equivalent.

@connorbrinton
Copy link
Contributor Author

connorbrinton commented Dec 18, 2019

@tomzx What version of Poetry are you using? I haven't looked at this issue in a while, but I think it may have been fixed in Poetry 1.0.0. I just ran a quick test with the following pyproject.toml:

[tool.poetry]
name = "test78"
version = "0.1.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = "^3.7"
torch = "^1.3, !=1.3.0.post2"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

And got the following install_requires in the setup.py in the built .tar.gz:

install_requires = \
['torch^1.3, !=1.3.0.post2']

@tomzx
Copy link
Contributor

tomzx commented Dec 18, 2019

@connorbrinton I am using poetry 1.0.0.

The example of the generated setup.py you gave is invalid per PEP508. The caret is not a valid comparison operator (see https://www.python.org/dev/peps/pep-0508/#grammar).

If you use

torch = "^1.3"

in your pyproject.toml, when you run poetry build and extract the setup.py from the generated test78-0.1.0.tar.gz, then it generates the following:

install_requires = \
['torch>=1.3,<2.0']

which is valid per PEP508.

@connorbrinton
Copy link
Contributor Author

Good point, I always have trouble remembering what's allowed under PEP 508 😅 My bad for not reading your comment more thoroughly!

Your PR looks great!

Copy link

github-actions bot commented Mar 3, 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 3, 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
2 participants