Tox 失败,因为 setup.py 找不到 requirements.txt
Tox fails because setup.py can't find the requirements.txt
我已经在我的项目中添加了 tox,我的 tox.ini
非常简单:
[tox]
envlist = py37
[testenv]
deps =
-r{toxinidir}/requirements_test.txt
commands =
pytest -v
但是当我 运行 tox
时,我得到以下错误:
ERROR: invocation failed (exit code 1), logfile: /path/to/my_project/.tox/py37/log/py37-2.log
========================================================================================= log start ==========================================================================================
Processing ./.tox/.tmp/package/1/my_project-0+untagged.30.g6909bfa.dirty.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-req-build-ywna_4ks/setup.py", line 15, in <module>
with open(requirements_path) as requirements_file:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-req-build-ywna_4ks/requirements.txt'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-ywna_4ks/
You are using pip version 10.0.1, however version 19.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
========================================================================================== log end ===========================================================================================
__________________________________________________________________________________________ summary ___________________________________________________________________________________________
ERROR: py37: InvocationError for command /path/to/my_project/.tox/py37/bin/python -m pip install --exists-action w .tox/.tmp/package/1/my_project-0+untagged.30.g6909bfa.dirty.zip (exited with code 1)
这是我的 setup.py
:
-*- coding: utf-8 -*-
import os
import sys
from setuptools import setup, find_packages
import versioneer
here = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, here)
requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
with open(requirements_path) as requirements_file:
requires = requirements_file.readlines()
setup(
name='my_project',
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
maintainer='Hamed',
license='BSD',
py_modules=['my_project'],
packages=find_packages(),
package_data={'': ['*.csv', '*.yml', '*.html']},
include_package_data=True,
install_requires=requires,
long_description=open('README.md').read(),
zip_safe=False
]
},
)
python setup.py install
工作正常。
似乎 tox 正在 tmp 目录中查找要求,但在那里找不到。我的配置有问题吗?
我正在使用 tox==3.12.1
、python==3.7.3
、setuptools==41.0.1
和 conda==4.6.9
我已经在 Arch 和 SLES 12 上对此进行了测试,两者都得到了相同的结果。
根据 @phd 的观点,我发现 requirements.txt
不存在于源代码分发中。将 requirements.txt
添加到 MANIFEST.in
解决了问题!
互补:
我将我的需求分成了不同的文件(base_requirements.txt
、dev_requirements.txt
等),它们都在一个 requirements
目录中。在这种情况下,您需要在 MANIFEST.in
中添加此目录 as
recursive-include requirements *
我已经在我的项目中添加了 tox,我的 tox.ini
非常简单:
[tox]
envlist = py37
[testenv]
deps =
-r{toxinidir}/requirements_test.txt
commands =
pytest -v
但是当我 运行 tox
时,我得到以下错误:
ERROR: invocation failed (exit code 1), logfile: /path/to/my_project/.tox/py37/log/py37-2.log
========================================================================================= log start ==========================================================================================
Processing ./.tox/.tmp/package/1/my_project-0+untagged.30.g6909bfa.dirty.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-req-build-ywna_4ks/setup.py", line 15, in <module>
with open(requirements_path) as requirements_file:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-req-build-ywna_4ks/requirements.txt'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-ywna_4ks/
You are using pip version 10.0.1, however version 19.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
========================================================================================== log end ===========================================================================================
__________________________________________________________________________________________ summary ___________________________________________________________________________________________
ERROR: py37: InvocationError for command /path/to/my_project/.tox/py37/bin/python -m pip install --exists-action w .tox/.tmp/package/1/my_project-0+untagged.30.g6909bfa.dirty.zip (exited with code 1)
这是我的 setup.py
:
-*- coding: utf-8 -*-
import os
import sys
from setuptools import setup, find_packages
import versioneer
here = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, here)
requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
with open(requirements_path) as requirements_file:
requires = requirements_file.readlines()
setup(
name='my_project',
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
maintainer='Hamed',
license='BSD',
py_modules=['my_project'],
packages=find_packages(),
package_data={'': ['*.csv', '*.yml', '*.html']},
include_package_data=True,
install_requires=requires,
long_description=open('README.md').read(),
zip_safe=False
]
},
)
python setup.py install
工作正常。
似乎 tox 正在 tmp 目录中查找要求,但在那里找不到。我的配置有问题吗?
我正在使用 tox==3.12.1
、python==3.7.3
、setuptools==41.0.1
和 conda==4.6.9
我已经在 Arch 和 SLES 12 上对此进行了测试,两者都得到了相同的结果。
根据 @phd 的观点,我发现 requirements.txt
不存在于源代码分发中。将 requirements.txt
添加到 MANIFEST.in
解决了问题!
互补
我将我的需求分成了不同的文件(base_requirements.txt
、dev_requirements.txt
等),它们都在一个 requirements
目录中。在这种情况下,您需要在 MANIFEST.in
中添加此目录 as
recursive-include requirements *