Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup.py does not play nicely with pipenv #525

Closed
jmichalicek opened this issue Oct 18, 2017 · 4 comments
Closed

setup.py does not play nicely with pipenv #525

jmichalicek opened this issue Oct 18, 2017 · 4 comments
Labels
feature New feature that should be supported
Milestone

Comments

@jmichalicek
Copy link

jmichalicek commented Oct 18, 2017

With the new pipenv, which is recommended by python.org now, there are issues with using os.sys_version in setup.py to determine which dependencies to install.

It appears that since pipenv technically runs in your main python environment rather than inside the virtualenv it manages, setup.py detects that python version. So for example I use python 3.6 as my main python, but have a few legacy projects which are on 2.7 for now. If I use pipenv then weasyprint's setup.py sees python 3.6 in os.sys_version and sets an incorrect version of CairSVG in the requirements.

Would it be possible to use the extras_require feature of setuptools 18.0 and up to handle the conditional dependency?

Please also see https://github.com/kennethreitz/pipenv/issues/924

@liZe liZe added the feature New feature that should be supported label Oct 18, 2017
@liZe
Copy link
Member

liZe commented Oct 18, 2017

Well… I can understand the problem and I'd like to solve it, but I don't understand how extras_require could help without breaking the current behavior (pip2 install weasyprint installs CairoSVG 1, pip3 install weasyprint installs CairoSVG 2). Could you give me a hint?

@jmichalicek
Copy link
Author

jmichalicek commented Oct 19, 2017

I have not tested this in setup.py, but my understanding is that you should be able to use the environment markers in extras_require to install the intended version of CairoSVG. I've tested this with putting them in a requirements.txt and hard setting the CairoSVG version with markers in the Pipfile successfully.

https://hynek.me/articles/conditional-python-dependencies/ discusses using them in setup.py in extras_require.
pypa/setuptools#1087 also discusses it quite a bit and gives a few examples.

If I've understood correctly, you can remove the bit checking sys.version_info and setting the dependency and instead use one of the following

setup(
# ...stuff which is already there,
    extras_require={
        ":python_version<'3.0'":  ['CairoSVG >= 1.0.20, < 2.0.0'],
        ":python_version>='3.0'": ['CairoSVG >= 1.0.20']}
) 

@liZe liZe added this to the v0.42 milestone Oct 19, 2017
@liZe liZe closed this as completed in 1eef005 Oct 19, 2017
@liZe
Copy link
Member

liZe commented Oct 19, 2017

Looks good to me, thanks for the hint!

@jmichalicek
Copy link
Author

jmichalicek commented Oct 19, 2017

No problem, I'm glad to see that it works. Working on getting several projects migrated over to using pipenv has definitely been a bit of a learning experience.

I just did a bit more digging and while you may not want to rely on it just yet due to newness, it appears setuptools 36.2.0 added the ability to use the environment markers within install_requires as well, rather than forcing use of the empty named extras_require.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature that should be supported
Projects
None yet
Development

No branches or pull requests

2 participants