Poetry: Specify version/OS related dependencies

Created on 23 Mar 2019  路  4Comments  路  Source: python-poetry/poetry

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have searched the documentation and believe that my question is not covered.

Question

I'm working on a project compatible with Py2/Py3 running on both Linux and Windows but with different dependencies. For example with py2 the configparser must be installed and on Windows pywin32 is needed. I used to detect the platform and Python versions dynamically and generate corresponding dependencies in setup.py before invoking the setup() of setuptools. Can I make it work with poetry and pyproject.toml?

Thanks a lot!

P.S. related script in my setup.py:

def os_requires():
    return ['Pillow', 'pypiwin32'] if sys.platform == 'win32' else []

def backport_requires():
    return ['configparser', 'subprocess32'] if sys.version_info[0] == 2 else []

def requires():
    return os_requires() + backport_requires()

setup(
    # omit many arguments...
    install_requires=requires(),
)

Most helpful comment

@genzj What you are doing in your setup.py is not how you are supposed to do this. See https://www.python.org/dev/peps/pep-0508/#environment-markers

And it is supported in Poetry. See the documentation here: https://poetry.eustace.io/docs/versions/#python-restricted-dependencies (platform is not a documented keyword but it's also supported.

All 4 comments

@genzj In the situation of having a custom build process, your project should stick to setuptools.

There are lots of decisions to make in this request, such as:

  1. Translate and describe those conditions in toml or not
  2. If no, the way of including custom scripts and concluding scattered configs.
    etc.

And the cons of making decisions seems to be more than pros.

poetry is a package manager, and this question will result in a autotools for python project in my imagination.

@drunkwcodes I got your idea. I think I'll stick to setuptools before find a good solution.

Thanks a lot!

@genzj What you are doing in your setup.py is not how you are supposed to do this. See https://www.python.org/dev/peps/pep-0508/#environment-markers

And it is supported in Poetry. See the documentation here: https://poetry.eustace.io/docs/versions/#python-restricted-dependencies (platform is not a documented keyword but it's also supported.

@sdispater thanks a lot for the neat solution. I think it's the thing I am looking for 馃挴 馃挴 馃憤

Was this page helpful?
0 / 5 - 0 ratings