Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have one project I'd like to publish as packages targeting two Python versions (3.6 and 3.8).

What I understand:

  • How to install and activate different python versions using pyenv.
  • How to get poetry to create virtual environments that correspond to the chosen Python version.
  • How to setup pyproject.toml to specify the python version, manage dependencies, and publish a package using this configuration.

What I do not understand: how can I publish the same package for more than one Python version? I can't be the only one with this use-case right?

  • Does need two pyproject.toml files? (one for each python version and set of corresponding dependencies...)
  • Are there established ways of doing this with Poetry, or are other tools/workflows necessary?

Edit

Doing a bit more digging, I found this https://python-poetry.org/docs/versions/#multiple-constraints-dependencies which looks like it might be relevant.

Here's the example at the link above.

[tool.poetry.dependencies]
foo = [
    {version = "<=1.9", python = "^2.7"},
    {version = "^2.0", python = "^3.4"}
]

I've also found you can specify the Python version using poetry add like this...

poetry add cleo --python 3.6.10

Which adds dependencies in pyproject.toml like this...

cleo = {version = "^0.8.1", python = "3.6.10"}

Going to experiment and see if this works.

question from:https://stackoverflow.com/questions/65945929/poetry-how-to-publish-project-packages-targeting-multiple-python-versions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
139 views
Welcome To Ask or Share your Answers For Others

1 Answer

You probably need something like that in your pyproject.toml:

[tool.poetry.dependencies]
python = '3.6 || 3.8'

But I am not sure on the exact notation, it's a bit vague.

It seems to generate a setup.py with the following:

'>=3.6, !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.7.*'

So that would include 3.9, 3.10, etc. and this is incorrect.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...