[Distutils] How to specify dependencies in Python
guettliml at thomas-guettler.de
Mon Jan 16 10:59:27 EST 2017
Am 13.01.2017 um 14:07 schrieb Paul Moore:
> On 13 January 2017 at 12:23, Thomas Güttler
> <guettliml at thomas-guettler.de> wrote:
>> Am 12.01.2017 um 13:43 schrieb Nick Coghlan:
>>> On 12 January 2017 at 22:04, Thomas Güttler
>>> <guettliml at thomas-guettler.de> wrote:
>>>> I came across a python library which has docs, which start like this:
>>>> Include foolib in your requirements.txt file.
>>>> AFAIK dependencies should be specified via `install_requires` in
>>> Applications and services don't necessarily have a setup.py file -
>>> setup.py is more for pip-installable libraries and frameworks (see
>>> https://caremad.io/posts/2013/07/setup-vs-requirement/ for more on
>>> that topic).
>> What is an application?
>> The django project uses this definition:
>> I guess you mean something else, if you talk about "application".
>> What is an application for you?
> IMO, an "application" in this context is a standalone program
> (implemented in Python). This is as opposed to a "library" which is
> written to be imported in other Python code. Obviously, there's some
> overlap - some "applications" provide a "programming API" that can be
> imported, and some libraries provide command line entry points.
yes, I think the same way. There is some overlap.
> A library (something that you import) should declare in its metadata
> that you need to have its dependencies installed before it will work.
> That lets you (the user of the library) be ignorant of the
> dependencies of the library (which are implementation details as far
> as you are concerned) - pip just sorts it out for you from the
> metadata. To get the dependency metadata, the *library* should include
> its dependencies in install_requires in its setup.py.
Thank you for your explanation. For me this means, I should tell the maintainer
that a library should specify it's dependencies via install_requires.
> For applications on the other hand, you need to install exactly the
> environment you tested, so you *don't* use dependency metadata.
> Rather, you create a requirements.txt file that contains the exact
> versions of everything (direct dependencies) your application needs,
> then deploy your application script to a Python environment where
> you've run "pip install -r requirements.txt" to set it up correctly.
I think requirements.txt should be the result of some kind of Continous-Integration run.
If all tests are successful, then requirements.txt should be created with "pip freeze".
This means, that the Continous-Integration run does not use requirements.txt to
build its environment.
Next question: Where is the best place to store requirements.txt?
I think it should not be in the repo of a library. It should be somehow outside.
Up to now I a missing the right english term for it.
> As I say, there are lots of grey areas here. But from your
> description, the library you found sounds like it should have
> dependency metadata, and not need you to use a requirements file. On
> the other hand, the "Quickstart" may be trying to tell people how to
> use foolib in their *application*, in which case it's correct. (It's
> oversimplified, as if you're writing a library that depends on foolib
> you'd use install_requires, but simply changing the text to just say
> "put foolib in your install_requires" is no better, as then you'd have
> ignored the application use case...)
> If you can point to the actual library you're referring to, it would
> be easier to be specific :-)
I did not tell the name here, since I don't want to offend the library maintainer.
I think he does not like it, when people talk behind his back about his code.
I will do so after we found a solid solution here.
Thomas Guettler http://www.thomas-guettler.de/
More information about the Distutils-SIG