python-poetry / python-poetry/poetry
Poetry `add` and `init` can create incompatible settings in pyproject.toml
@Secrus is already working on this.
Since Sep 25, 2024.
- Dominant language
- Python
- Stars
- 34.3k
- Forks
- 2.5k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 30
Description
- 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 (
-vvvoption).
- OS version and name: Ubuntu Xenial
- Poetry version: 0.12.10
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/nottrobin/0cb0ab3a049891640280fa08f4ca5bcc
Issue
If I try to create a pyproject.toml with Python2 but with Django as a dependency, it creates a pyproject.toml that is incompatible:
$ poetry init --no-interaction --dependency django
This command will guide you through creating your pyproject.toml config.
Using version ^2.1 for django
$ poetry install
Creating virtualenv django-project-py2.7 in /root/.cache/pypoetry/virtualenvs
Installing dependencies from lock file
Warning: The lock file is not up to date with the latest changes in pyproject.toml. You may be getting outdated dependencies. Run update to update them.
[SolverProblemError]
The current project must support the following Python versions: 2.7.12
Because no versions of django match >=2.1,<2.1.4 || >2.1.4,<3.0
and django (2.1.4) requires Python >=3.5, django is forbidden.
So, because django-project depends on django (^2.1), version solving failed.
install [--no-dev] [--dry-run] [-E|--extras EXTRAS] [--develop DEVELOP]
This is because these two requirements are fundamentally not quite compatible:
python = "^2.7"
django = "^2.1"
I understand that this might be difficult for Poetry to resolve as it might not have the information that Django 2.1 doesn't work on python < 3.5 at the time it's creating the pyproject.toml. But it's unfortunate that this means that the setup experience for a poetry-based Django project requires such deeper understanding.
Possible solutions could be:
poetry init --dependency djangowould set the version of python inpyproject.tomlto^3.5(maybe with a warning that your current version of python is lower than that)poetry init --dependency djangowould error if the current python version was unsupportedpoetry init --dependency djangowould select the most recent version of Django supported by the current version of python
I think the nicest experience would be 1. - as you might want to generate a valid pyproject.toml with any version of python, in the full knowledge that you can't actually run the project with that version.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.