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

ResolutionImpossible if requires-python is empty #917

Closed
1 task done
astrojuanlu opened this issue Feb 16, 2022 · 6 comments
Closed
1 task done

ResolutionImpossible if requires-python is empty #917

astrojuanlu opened this issue Feb 16, 2022 · 6 comments
Labels
🐛 bug Something isn't working

Comments

@astrojuanlu
Copy link

astrojuanlu commented Feb 16, 2022

  • I have searched the issue tracker and believe that this is not a duplicate.

The pdm init command says "Python requires('*' to allow any)". But if I actually do that, then the resulting pyproject.toml contains the line requires-python = "", which makes resolution fail.

On the other hand, the default requires-python = ">=3.9" does not present any problems.

Steps to reproduce

python3.9 -m venv .venv    
source .venv/bin/activate    
pip install pdm &> /dev/null          
pdm init -n           
sed -i 's;">=3.9";"";g' pyproject.toml          
pdm add -vv "urllib3==1.25.7"    

Actual behavior

$ docker run -it --rm python:3.9 bash
root@97c704248096:/# python3.9 -m venv .venv
root@97c704248096:/# source .venv/bin/activate
(.venv) root@97c704248096:/# pip install pdm &> /dev/null 
(.venv) root@97c704248096:/# pdm init -n
Creating a pyproject.toml for PDM...
Using Python interpreter: /.venv/bin/python3.9 (3.9)
Changes are written to pyproject.toml.
(.venv) root@97c704248096:/# grep requires-python pyproject.toml 
requires-python = ">=3.9"
(.venv) root@97c704248096:/# sed -i 's;">=3.9";"";g' pyproject.toml 
(.venv) root@97c704248096:/# grep requires-python pyproject.toml 
requires-python = ""
(.venv) root@97c704248096:/# pdm add -vv "urllib3==1.25.7"
Adding packages to default dependencies: urllib3
======== Start resolving requirements ========
  urllib3==1.25.7
  python
  Adding requirement urllib3==1.25.7
	Found matching candidates:
	  <Candidate urllib3 1.25.7 from https://pypi.org/simple/urllib3/>
  Adding requirement python
======== Starting round 0 ========
Resolving: new pin python 
======== Ending round 0 ========
======== Starting round 1 ========
  Adding requirement python>=2.7,<4.0,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*(from urllib3 1.25.7)
  Adding requirement python>=2.7,<4.0,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*(from urllib3 1.25.7)
Conflicts detected: 
  python (from project)
  python>=2.7,<4.0,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.* (from <Candidate urllib3 1.25.7 from https://pypi.org/simple/urllib3/>)
  python (from project)
  python>=2.7,<4.0,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.* (from <Candidate urllib3 1.25.7 from https://pypi.org/simple/urllib3/>)
Candidate rejected: python None
🔒 Lock failed
Unable to find a resolution because the following dependencies don't work on all Python versions defined by the project's `requires-python`: 
  python>=2.7,<4.0,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.* (from <Candidate urllib3 1.25.7 from https://pypi.org/simple/urllib3/>)
To fix this, you can change the value of `requires-python` in pyproject.toml.
Traceback (most recent call last):
  File "/.venv/bin/pdm", line 8, in <module>
    sys.exit(main())
  File "/.venv/lib/python3.9/site-packages/pdm/core.py", line 226, in main
    return Core().main(args)
  File "/.venv/lib/python3.9/site-packages/pdm/core.py", line 161, in main
    raise cast(Exception, err).with_traceback(traceback)
  File "/.venv/lib/python3.9/site-packages/pdm/core.py", line 156, in main
    f(options.project, options)
  File "/.venv/lib/python3.9/site-packages/pdm/cli/commands/add.py", line 53, in handle
    actions.do_add(
  File "/.venv/lib/python3.9/site-packages/pdm/cli/actions.py", line 236, in do_add
    resolved = do_lock(project, strategy, tracked_names, reqs, dry_run=dry_run)
  File "/.venv/lib/python3.9/site-packages/pdm/cli/actions.py", line 96, in do_lock
    raise ResolutionImpossible("Unable to find a resolution") from None
resolvelib.resolvers.ResolutionImpossible: Unable to find a resolution
(.venv) root@97c704248096:/# pdm init -n
pyproject.toml already exists, update it now.
Using the last selection, add '-i' to ignore it.
Using Python interpreter: /.venv/bin/python3.9 (3.9)
Changes are written to pyproject.toml.
(.venv) root@97c704248096:/# grep requires-python pyproject.toml 
requires-python = ">=3.9"
(.venv) root@97c704248096:/# pdm add -vv "urllib3==1.25.7"
Adding packages to default dependencies: urllib3
======== Start resolving requirements ========
  urllib3==1.25.7
  python>=3.9
  Adding requirement urllib3==1.25.7
	Found matching candidates:
	  <Candidate urllib3 1.25.7 from https://pypi.org/simple/urllib3/>
  Adding requirement python>=3.9
======== Starting round 0 ========
Resolving: new pin python >=3.9
======== Ending round 0 ========
======== Starting round 1 ========
Resolving: new pin urllib3 1.25.7
======== Ending round 1 ========
======== Starting round 2 ========
======== Resolution Result ========
Stable pins:
   python None
  urllib3 1.25.7
	Found matching candidates:
	  <Candidate urllib3 1.25.7 from https://pypi.org/simple/urllib3/>
🔒 Lock successful
Changes are written to pdm.lock.
Changes are written to pyproject.toml.
Synchronizing working set with lock file: 1 to add, 0 to update, 0 to remove

Install urllib3 1.25.7 successful

🎉 All complete!

Expected behavior

I would have expected requires-python = "" to not cause any issue.

Environment Information

# pdm info && pdm info --env
PDM version:        1.12.8
Python Interpreter: /.venv/bin/python3.9 (3.9)
Project Root:       /
Project Packages:   /__pypackages__/3.9
{
  "implementation_name": "cpython",
  "implementation_version": "3.9.10",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.13.0-28-generic",
  "platform_system": "Linux",
  "platform_version": "#31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022",
  "python_full_version": "3.9.10",
  "platform_python_implementation": "CPython",
  "python_version": "3.9",
  "sys_platform": "linux"
}
@astrojuanlu astrojuanlu added the 🐛 bug Something isn't working label Feb 16, 2022
@frostming
Copy link
Collaborator

The failure reason is printed in the output:

Unable to find a resolution because the following dependencies don't work on all Python versions defined by the project's `requires-python`: 
  python>=2.7,<4.0,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.* (from <Candidate urllib3 1.25.7 from https://pypi.org/simple/urllib3/>)
To fix this, you can change the value of `requires-python` in pyproject.toml.

Why do you think this is a bug? Close it now.

@astrojuanlu
Copy link
Author

astrojuanlu commented Feb 16, 2022

The pdm init command says "Python requires('*' to allow any)"

If * leads to "zero Python versions supported" instead of "any Python version supported", then the wording of pdm init is highly misleading IMHO.

@astrojuanlu
Copy link
Author

If given *, then pdm init should not produce requires-python metadata at all, if I understood correctly.

@frostming
Copy link
Collaborator

If * leads to "zero Python versions supported" instead of "any Python version supported",

No, it does mean any Python version supported. But your dependency urllib3 supports a narrower version range: >=2.7,<4.0,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*. So it can't find a resolution that supports ALL versions that the project promises.

@frostming
Copy link
Collaborator

frostming commented Feb 16, 2022

Basically, if the dependency specifies a requires-python, the dependant's requires-python MUST be a subset(narrower) of it, for the good of compatibility. It means "all must work" instead of "any of it works"

@astrojuanlu
Copy link
Author

Aaaaaaaah okay, I understand. So requires-python = "" means "this project works with all (any) Python version" which cannot be satisfied if any dependency pins the Python version.

Thanks for the explanation and sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants