requirements.txt or not requirements.txt?
Hello here! TL;DR: Should I use requirements.txt, or should I have my dependencies only listed inside setup.py? Long version: The two most common ways to have dependencies listed in a python package are either having them listed both in setup.py and requirements.txt files, or having them only listed in requirements.txt and then import them using some `parse_requirements` methods. In the projects which I am currently working on there are five lists of requirements: - requirements.txt - requirements_test.txt - requirements_dev.txt - install_requires inside setup.py - tests_require inside setup.py I wanted to remove duplicities, so I thought about removing the setup.py lists and parse the dependencies from the requirements*.txt files. But then I came across this, https://stackoverflow.com/a/28842733, which recommends using a `dev` entry in `extras_require` and then using `pip install -e .[dev]` to install them, which could be easily extended to also have a `pip install -e .[test]`. I find this a very clean option, since it reduces the amount of files the repository and makes setup.py and makes setup.py self-contained. Are any known drawbacks to this approach? Is it a good way to go? Regards, -- Carles Sala Cladellas carles@pythiac.com / +34 666 278 679 https://www.pythiac.com Pythia Consulting - Data Science as a Service
What kind of project is it? For example, is it a software library e.g. to put on PyPI, or a website application for a company to run? The answer to this question will help people answer your question because it has a big impact on what practice will be best for you. —Chris On Sun, May 6, 2018 at 11:54 PM Carles Sala Cladellas <carles@pythiac.com> wrote:
Hello here!
TL;DR: Should I use requirements.txt, or should I have my dependencies only listed inside setup.py?
Long version:
The two most common ways to have dependencies listed in a python package are either having them listed both in setup.py and requirements.txt files, or having them only listed in requirements.txt and then import them using some `parse_requirements` methods.
In the projects which I am currently working on there are five lists of requirements: - requirements.txt - requirements_test.txt - requirements_dev.txt - install_requires inside setup.py - tests_require inside setup.py
I wanted to remove duplicities, so I thought about removing the setup.py lists and parse the dependencies from the requirements*.txt files.
But then I came across this, https://stackoverflow.com/a/28842733, which recommends using a `dev` entry in `extras_require` and then using `pip install -e .[dev]` to install them, which could be easily extended to also have a `pip install -e .[test]`.
I find this a very clean option, since it reduces the amount of files the repository and makes setup.py and makes setup.py self-contained.
Are any known drawbacks to this approach? Is it a good way to go?
Regards,
-- Carles Sala Cladellascarles@pythiac.com / +34 666 278 679 https://www.pythiac.com Pythia Consulting - Data Science as a Service
-- Distutils-SIG mailing list distutils-sig@python.org https://mail.python.org/mm3/mailman3/lists/distutils-sig.python.org/ Message archived at https://mail.python.org/mm3/archives/list/distutils-sig@python.org/message/O...
Hi! Thanks for all the useful responses! I am basically working on libraries that will be distributed on PyPi, such as https://github.com/HDI-Project/BTB/ and https://github.com/HDI-Project/ATM/ (Auto Machine Learning and Model Tuning libraries developed by Data to AI lab, in MIT). It looks like, in this scenario, the setup.py option seems to be the most supported one, so we'll probably go for it! Thanks again! Carles On 07/05/18 09:59, Chris Jerdonek wrote:
What kind of project is it? For example, is it a software library e.g. to put on PyPI, or a website application for a company to run? The answer to this question will help people answer your question because it has a big impact on what practice will be best for you.
—Chris
On Sun, May 6, 2018 at 11:54 PM Carles Sala Cladellas <carles@pythiac.com <mailto:carles@pythiac.com>> wrote:
Hello here!
TL;DR: Should I use requirements.txt, or should I have my dependencies only listed inside setup.py?
Long version:
The two most common ways to have dependencies listed in a python package are either having them listed both in setup.py and requirements.txt files, or having them only listed in requirements.txt and then import them using some `parse_requirements` methods.
In the projects which I am currently working on there are five lists of requirements: - requirements.txt - requirements_test.txt - requirements_dev.txt - install_requires inside setup.py - tests_require inside setup.py
I wanted to remove duplicities, so I thought about removing the setup.py lists and parse the dependencies from the requirements*.txt files.
But then I came across this, https://stackoverflow.com/a/28842733, which recommends using a `dev` entry in `extras_require` and then using `pip install -e .[dev]` to install them, which could be easily extended to also have a `pip install -e .[test]`.
I find this a very clean option, since it reduces the amount of files the repository and makes setup.py and makes setup.py self-contained.
Are any known drawbacks to this approach? Is it a good way to go?
Regards,
-- Carles Sala Cladellas carles@pythiac.com <mailto:carles@pythiac.com> / +34 666 278 679
https://www.pythiac.com Pythia Consulting - Data Science as a Service
-- Distutils-SIG mailing list distutils-sig@python.org <mailto:distutils-sig@python.org> https://mail.python.org/mm3/mailman3/lists/distutils-sig.python.org/ Message archived at https://mail.python.org/mm3/archives/list/distutils-sig@python.org/message/O...
-- Carles Sala Cladellas carles@pythiac.com / +34 666 278 679 https://www.pythiac.com Pythia Consulting - Data Science as a Service
On 5/7/18 at 8:48 AM, carles@pythiac.com (Carles Sala Cladellas) pronounced:
But then I came across this, https://stackoverflow.com/a/28842733, which recommends using a `dev` entry in `extras_require` and then using `pip install -e .[dev]` to install them, which could be easily extended to also have a `pip install -e .[test]`.
We use setup.py for Pyramid. https://github.com/Pylons/pyramid/blob/master/setup.py Using just setup.py is a common practice going back a long time. It's the first method I learned in Python. We use `pip install -e .[docs]` to install documentation building requirements. "If it ain't documented, it's broken." We also use a pip requirements file (rtd.txt) to build our docs on Read The Docs. RTD effectively does a `pip install -e .[docs]` using that file. So setup.py and pip requirements files can be complementary, not mutually exclusive. --steve -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Steve Piercy Website Builder Eugene, OR <web@stevepiercy.com> <http://www.stevepiercy.com/>
The recommendation is typically: setup.py for libraries, requirements.txt for applications. But you may also use requirements.txt for specific tasks associated with a library, like building the docs. Donald wrote a blog post which better explains what these two formats do:https://caremad.io/posts/2013/07/setup-vs-requirement/ On Mon, May 7, 2018, at 7:48 AM, Carles Sala Cladellas wrote:
Hello here!
TL;DR: Should I use requirements.txt, or should I have my dependencies only listed inside setup.py?> Long version:
The two most common ways to have dependencies listed in a python package are either having them listed both in setup.py and requirements.txt files, or having them only listed in requirements.txt and then import them using some `parse_requirements` methods.> In the projects which I am currently working on there are five lists of requirements:> - requirements.txt - requirements_test.txt - requirements_dev.txt - install_requires inside setup.py - tests_require inside setup.py
I wanted to remove duplicities, so I thought about removing the setup.py lists and parse the dependencies from the requirements*.txt files.> But then I came across this, https://stackoverflow.com/a/28842733, which recommends using a `dev` entry in `extras_require` and then using `pip install -e .[dev]` to install them, which could be easily extended to also have a `pip install -e .[test]`.> I find this a very clean option, since it reduces the amount of files the repository and makes setup.py and makes setup.py self-contained.> Are any known drawbacks to this approach? Is it a good way to go?
Regards,
-- Carles Sala Cladellas carles@pythiac.com / +34 666 278 679
https://www.pythiac.com Pythia Consulting - Data Science as a Service> -- Distutils-SIG mailing list distutils-sig@python.org https://mail.python.org/mm3/mailman3/lists/distutils-sig.python.org/ Message archived at https://mail.python.org/mm3/archives/list/distutils-sig@python.org/message/O...
On Mon, May 07, 2018 at 08:48:23AM +0200, Carles Sala Cladellas wrote:
Hello here!
TL;DR: Should I use requirements.txt, or should I have my dependencies only listed inside setup.py?
Short answer: only setup.py, unless you find a reason to also use a requirements.txt. Long answer: https://packaging.python.org/discussions/install-requires-vs-requirements/ and especially https://caremad.io/posts/2013/07/setup-vs-requirement/
But then I came across this, [1]https://stackoverflow.com/a/28842733, which recommends using a `dev` entry in `extras_require` and then using `pip install -e .[dev]` to install them, which could be easily extended to also have a `pip install -e .[test]`.
I find this a very clean option, since it reduces the amount of files the repository and makes setup.py and makes setup.py self-contained.
Are any known drawbacks to this approach? Is it a good way to go?
I like it. It works nicely for me. It's not 100% complete approach: sometimes (when I'm working on an application rather than a tool/library) I also wish to have a list of concrete version pins with which the application has been known to work, so I use pip freeze (or pip-tools) to get a requirements.txt with all the frozen versions. HTH, Marius Gedminas -- Everyone generalizes from one example. At least, I do. -- Steven Brust
On Mon, May 07, 2018 at 11:33:44AM +0300, Marius Gedminas wrote:
On Mon, May 07, 2018 at 08:48:23AM +0200, Carles Sala Cladellas wrote:
Hello here!
TL;DR: Should I use requirements.txt, or should I have my dependencies only listed inside setup.py?
Short answer: only setup.py, unless you find a reason to also use a requirements.txt.
Long answer: https://packaging.python.org/discussions/install-requires-vs-requirements/ and especially https://caremad.io/posts/2013/07/setup-vs-requirement/
+1 let me point out one more thing. Suppose you have a project 'myproject' that depends on library1 that depends on library2. library1 doesn't declare dependancies in setup.py but uses requirements.txt. 'pip install' of myproject will not see the dependency on library2 I personally really appreciate what buildout does in this field. It relies on setup.py but allows you to take a 'snapshot' of the packages really used in versions.txt. It's a pinpoint that enter into the play *only if* setup.py requires that package. What I really don't like of requirements.txt is that it doesn't differentiate between required packages and packages that entered as dependacies of others. sandro *:-) -- Sandro Dentella *:-) http://trepalchi.it Il portale degli artisti http://www.reteisi.org Soluzioni libere per le scuole http://sqlkit.argolinux.org SQLkit home page - PyGTK/python/sqlalchemy
I would emphasize that setup.py is the way to go. Requirements.txt was only ever intended to be a way for a developer to provide a dependency chain so that other developers could duplicate the environment if necessary. Today's common usage was never originally intended. The `extras_require` that you have discovered is an excellent way of segregating non-installation-required dependencies. On some of my projects, I have built up the following "standard" extras: * all - this is programmatically defined as every dependency including the package itself * dev - this is programmatically defined as every dependency excluding the packge itself * test - all testing dependencies (i.e pytest, coverage, etc.) * docs - all documentation dependences (i.e. sphinx) For onboarding, I typically just then tell someone to use `-e .[all]` for setting up a development environment.
participants (7)
-
Alessandro Dentella
-
brian.m.bruggeman@gmail.com
-
Carles Sala Cladellas
-
Chris Jerdonek
-
Marius Gedminas
-
Steve Piercy - Website Builder
-
Thomas Kluyver