[英]Tox can't copy non-python file while installing the module
這是我正在編寫setup.py
文件的模塊的樹結構:
ls .
LICENSE
README.md
bin
examples
module
scratch
setup.py
tests
tox.ini
我配置我的setup.py
如下:
from setuptools import setup, find_packages
setup(
name="package_name",
version="0.1",
packages=find_packages(),
install_requires=[
# [...]
],
extras_require={
# [...]
},
tests_require={
'pytest',
'doctest'
},
scripts=['bin/bootstrap'],
data_files=[
('license', ['LICENSE']),
],
# [...]
# could also include long_description, download_url, classifiers, etc.
)
如果我從我的python環境安裝包(也是virtualenv)
pip install .
LICENSE
文件已正確安裝。
但是運行tox
:
[tox]
envlist = py27, py35
[testenv]
deps =
pytest
git+https://github.com/djc/couchdb-python
docopt
commands = py.test \
{posargs}
我收到此錯誤:
running install_data
creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data
creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data/data
creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data/data/license
error: can't copy 'LICENSE': doesn't exist or not a regular file
從setup.py中刪除data_files
部分使得tox
正常運行。
您的問題是setuptools無法在為構建源代碼分發而包含的文件中找到“LICENSE”文件。 你有2個選項,告訴setuptools包含該文件(兩者都在這里指出):
MANIFEST.in
文件(如https://github.com/pypa/sampleproject/ ) include_package_data=True
。 由於https://pypi.org/project/check-manifest/ ,使用MANIFEST.in
通常更簡單,更容易驗證,因此可以使用自動化來驗證事情確實是正確的(如果您使用像Git這樣的VCS或SVN)。
pip install .
使用python setup.py bdist_wheel
構建一個輪子,通過簡單地解python setup.py bdist_wheel
它來安裝,如輪規范中所定義: https : python setup.py bdist_wheel
tox
使用python setup.py sdist
構建源代碼分發,然后使用python setup.py install
解壓縮並python setup.py install
。
這可能是您行為不同的原因。
我在我的包中有一些資源文件,我在執行期間使用它們。 為了使安裝程序將它們存儲在包含python代碼的包中,我使用include_package_data=True
並使用importlib.resources
訪問它們。 您可以將backport用於比3.7更舊的Python版本或其他庫。
在每次發布之前,我都有一個腳本來驗證,我需要的所有文件都放在一個bdist
輪中,以確保一切都在這個地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.