I have a Python module in which the setup.py
script starts as follows:
import setuptools, pathlib
HERE = pathlib.Path(__file__).parent
README = (HERE / "README.md").read_text()
REQUIRES = (HERE / "requirements.txt").read_text().strip().split("\n")
setuptools.setup(
install_requires=REQUIRES,
long_description=README,
...
)
When I run the setup from the command line, like this:
python setup.py sdist
it runs fine. But when I run
tox
I get an error on line 5 in file setup.py:
FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
even though both the requirements.txt
file and the README.md
file remain in the same folder as setup.py
.
Here is my tox.ini
file:
[tox]
envlist = py39
[testenv]
deps =
pytest
-r requirements.txt
commands =
pytest
How can I make tox
find my requirements.txt file?
As a complementary answer to the correct one by Erel
.
Depending on configuration, tox
builds the project, installs the build artifact and then tests against it. This is a good thing as only then you test what you ship, and not what is in the source tree.
In order to not forget to include files in the MANIFEST.in
file, I usually use the check-manifest
tool/linter, see https://pypi.org/project/check-manifest/
python setup.py sdist
is deprecated, see https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html - you should use https://pypa-build.readthedocs.io/en/stable/ instead
using a requirements.txt
in a setup.py
is not recommended, see this classic article https://caremad.io/posts/2013/07/setup-vs-requirement/ ; additionally, nowadays I would recommend to use pip-tools
to pin dependencies