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(),
)
@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:
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 馃挴 馃挴 馃憤
Most helpful comment
@genzj What you are doing in your
setup.pyis not how you are supposed to do this. See https://www.python.org/dev/peps/pep-0508/#environment-markersAnd it is supported in Poetry. See the documentation here: https://poetry.eustace.io/docs/versions/#python-restricted-dependencies (
platformis not a documented keyword but it's also supported.