python-poetry / python-poetry/poetry

Poetry `add` and `init` can create incompatible settings in pyproject.toml

Open
#707 13 comments 2 reactions 1 assignee View on GitHub

@Secrus is already working on this.

Since Sep 25, 2024.

area/init kind/bug
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 (-vvv option).

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:

  1. poetry init --dependency django would set the version of python in pyproject.toml to ^3.5 (maybe with a warning that your current version of python is lower than that)
  2. poetry init --dependency django would error if the current python version was unsupported
  3. poetry init --dependency django would 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.