question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question] How to integrate with setup.py?

See original GitHub issue

Using requirements.txt I can do it:

from pip.req import parse_requirements
requirements = [str(r.req) for r in
                parse_requirements('requirements.txt', session=False)]
test_requirements = [str(r.req) for r in
                     parse_requirements('requirements-test.txt', session=False)]

How can I do the same using Pipfile?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:38 (13 by maintainers)

github_iconTop GitHub Comments

26reactions
vphilipponcommented, Oct 17, 2017

First, disclaimer: My expertise is mainly with lib packages. I might miss some points. I hold the right to be wrong, and I’m ready to use it! Also, this got me to scratch my head a few time. I’d really like some review on this.

Now, let’s get to this.

I’ll start with this statement @elgertam:

[…] my usage of Pipfile leads me think that install_requires really is almost identical to what goes in the Pipfile. If I need numpy, I pipenv install numpy and a new entry goes into in my Pipfile’s [packages] group […]

You added numpy to your environment, you did not add numpy to the dependencies of your app. Those are two different things. Keep reading, you’ll see what I mean.

In other words, my usage is totally different from requirements.txt, which I used to just generate before committing using pip freeze > requirements.txt.

Surprisingly, your usage is not so different if you think about it:

  • Your previous worflow: pip install stuff -> pip freeze > requirements.txt -> feed install_requires from requirements.txt
  • Your new (attempted) workflow: pipenv install stuff -> Pipfile automatically updated -> trying to feed install_requires with the Pipfile.
  • What’s the intended idea: Add stuff to install_requires -> pipenv install -> Environment and Pipfile.lock are updated.

And for that intended way to work, you want a Pipfile that states that you want to install your app. Something like the requests Pipfile linked by @isobit.

Or, an example:

[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true

[dev-packages]
pytest = ">=2.8.0"
tox = "*"

[packages]
"-e ." = "*"

Your Pipfile is to describe your environment, not the dependencies of a package. As you see, the Pipfile above defines what I want to install, which is the local package in editable mode.

This may look a bit “useless”, as right now its all drived by a single package, but let say you want to install your app, but with requests[security], but it’s not a strict dependency from your app, you do pipenv install requests[security], and then:

[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true

[dev-packages]
pytest = ">=2.8.0"
tox = "*"

[packages]
"-e ." = "*"
requests = { extras = ['security'] }

And voilà, here’s an example of the difference between your abstract requirements, and your concrete requirements. Same goes if you wanted to install gunicorn or anything else needed in the environment, but that’s not part of the app itself.

What am I missing here, @vphilippon? Why is Pipfile’s [packages] too constrained to use in install_requires or tests_require?

If I’ve explained this well enough, you can see that its just supposed to be the other way around. You put your dependencies in install_requires, you put you package in the Pipfile, and then you get and environment, with a Pipfile.lock for reproducibility (as it will resolve and respect your package dependencies).

For test_require, I’ll admit I’m not sure that fits in all of this. IIRC, its a setuptools specific feature. We could argue that it’s a set of abstract dependencies for testing, and expect pipenv to resolve and install those then doing pipenv install --dev, for all packages, but I have a feeling that’s not quite right. I dont have a clear idea or opinion on this and the rationale around it, sorry.

I hope this all make sense somehow.

18reactions
nateprewittcommented, Sep 27, 2017

You should be able to accomplish this with the code below. This will load the Pipfile from your current project and return the dependencies in a pip compatible list.

from pipenv.project import Project
from pipenv.utils import convert_deps_to_pip

pfile = Project(chdir=False).parsed_pipfile
requirements = convert_deps_to_pip(pfile['packages'], r=False)
test_requirements = convert_deps_to_pip(pfile['dev-packages'], r=False)

Let us know if you have any further questions 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is setup.py? - Stack Overflow
setup.py is a python file, the presence of which is an indication that the module/package you are about to install has likely been...
Read more >
What is setup.py? - Educative.io
The setup.py file is a Python file which indicates that the installation module/package is most likely packed and distributed using Distutils, the Python...
Read more >
Do I need to include the license for all dependencies declared ...
No, you do not need to include licenses for code that isn't part of your repository. However, as a service to your users,...
Read more >
How to Package Python dependencies with PIP setuptools
Lay out your project on your local machine using an appropriate directory structure. Create a setup.py script that describes all the metadata ...
Read more >
Making sense of setup.py - YouTube
Tim McNamarahttps://kiwi.pycon.org/schedule/presentation/122/This talk will guide you through the process of wrapping your scraps and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found