我正在尝试将一个相当简单的python包从使用setup.py转换为setup.cfg和pyproject.toml (除非这变得非常混乱,以至于它“不值得”,在这种情况下,我将放弃--希望我不必这么做!)
我的setup.cfg看起来是这样的:
[metadata]
name = my_pkg
description = My Package
long_description = file: README.md
version = 2.1
author = My Company, Inc.
include_package_data = true
[options]
package_dir =
=src
packages =
find:
python_requires = >=3.7
install_requires =
pandas >= 1.1
numpy >= 1.14.2
mock >= 2.0.0
jsonpickle >= 1.0
pyyaml >= 3.13
pycron >= 1.0.0
importlib_resources >= 1.0.2
more_itertools >= 8.10
pytz >= 2021.3
my_internal_package >= 1.1
[options.packages.find]
where=src注意,my_internal_package在那里--这是一个托管在类似pypi的内部服务器上的内部依赖项,它需要在extra-index-url中的extra-index-url中的一个条目才能找到它。
我的tox.ini看起来是这样的:
[tox]
envlist = py39-pandas{11,12,13,14}
[testenv]
deps = nose
coverage
pandas11: pandas>=1.1,<1.2
pandas12: pandas>=1.2,<1.3
pandas13: pandas>=1.3,<1.4
pandas14: pandas>=1.4,<1.5
commands = python -m coverage run -m nose []
sitepackages = True当我尝试运行tox时,我得到了以下输出:
% tox
ERROR: pyproject.toml file found.
To use a PEP 517 build-backend you are required to configure tox to use an isolated_build:
https://tox.readthedocs.io/en/latest/example/package.html所以我不太明白为什么在这种情况下isolated_build是必要的(我看了上面的URL,但是我无法连接“可配置构建系统”和“独立虚拟环境”之间的点),但是我将其添加到tox.ini的[tox]部分中。
isolated_build = True(我的pyproject.toml已经具备了所需的[build-system]功能。)
现在,添加这些内容后,tox输出如下:
% tox
py39-pandas11 inst-nodeps: /Users/kwilliams/git/optos/my-pkg/.tox/.tmp/package/1/my-pkg-2.1.tar.gz
py39-pandas11 installed: ansicolors==1.1.8,attrs==21.4.0,cachetools==5.0.0,certifi==2021.10.8,cfgv==3.3.1,charset-normalizer==2.0.12,click==8.0.4,clipboard==0.0.4,coverage==6.3.2,deprecation==2.1.0,distlib==0.3.4,docker==5.0.3,my-pkg @ file:///Users/kwilliams/git/optos/my-pkg/.tox/.tmp/package/1/my_pkg-2.1.tar.gz,filelock==3.6.0,gitlab-utils==0.2,google-auth==2.6.0,grpcio==1.44.0,identify==2.4.11,idna==3.3,importlib-resources==5.4.0,inflect==5.4.0,iniconfig==1.1.1,jsonpickle==2.1.0,kubernetes==19.15.0,libretranslatepy==2.1.1,lxml==4.8.0,mock==4.0.3,more-itertools==8.12.0,nodeenv==1.6.0,nose==1.3.7,numpy==1.22.3,oauthlib==3.2.0,packaging==21.3,pandas==1.1.5,platformdirs==2.5.1,pluggy==1.0.0,pre-commit==2.17.0,protobuf==3.19.4,py==1.11.0,pyasn1==0.4.8,pyasn1-modules==0.2.8,pycron==3.0.0,pyparsing==3.0.7,pyperclip==1.8.2,pytest==6.2.5,pytest-asyncio==0.16.0,pytest-grpc==0.8.0,pytest-mock==3.7.0,python-dateutil==2.8.2,pytz==2021.3,PyYAML==6.0,requests==2.27.1,requests-oauthlib==1.3.1,rsa==4.8,six==1.16.0,testcontainers==3.4.2,toml==0.10.2,translate==3.6.1,types-futures==3.3.8,types-protobuf==3.17.5,types-setuptools==57.4.10,urllib3==1.26.8,virtualenv==20.13.3,websocket-client==1.3.1,wrapt==1.14.0,zipp==3.7.0
py39-pandas11 run-test-pre: PYTHONHASHSEED='2767948081'
py39-pandas11 run-test: commands[0] | python -m coverage run -m nose
EEEEEE..E.E........EEE...
======================================================================
ERROR: Failure: ModuleNotFoundError (No module named 'my_internal_package')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/kwilliams/git/my-pkg/.tox/py39-pandas11/lib/python3.9/site-packages/nose/failure.py", line 39, in runTest
raise self.exc_val.with_traceback(self.tb)
File "/Users/kwilliams/git/my-pkg/.tox/py39-pandas11/lib/python3.9/site-packages/nose/loader.py", line 417, in loadTestsFromName
module = self.importer.importFromPath(
File "/Users/kwilliams/git/my-pkg/.tox/py39-pandas11/lib/python3.9/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Users/kwilliams/git/my-pkg/.tox/py39-pandas11/lib/python3.9/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/kwilliams/.pyenv/versions/3.9.5/lib/python3.9/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/Users/kwilliams/.pyenv/versions/3.9.5/lib/python3.9/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 711, in _load
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/kwilliams/git/my-pkg/src/my_pkg/util/test_utils.py", line 6, in <module>
from my_internal_package import Blah, BlahBlah
ModuleNotFoundError: No module named 'my_internal_package'
... lots more output like this因此,它没有试图安装my_internal_package,或者至少没有成功。我查看了构建,试图了解这个isolated_build参数的作用,但是它没有提到依赖项是如何找到的--它只说明了以下内容:
isolated_build=false(true|false)新版本3.3.0。激活孤立的构建环境。tox将使用虚拟环境从源树构建源分发。对于构建工具和参数,请使用PEP-517和PEP-518中指定的pyproject.toml文件。要指定虚拟环境Python,请使用isolated_build_env配置部分。
任何帮助都将不胜感激!
更新
根据评论中的要求,我的文件结构如下:
.
├── MANIFEST.in
├── NEWS.md
├── README.md
├── pyproject.toml
├── setup.cfg
├── src
│ ├── my_pkg
│ │ ├── __init__.py
│ │ ├── agent
│ │ │ ├── __init__.py
│ │ │ ├── foo.py
│ │ ├── ...
│ │ └── util
│ │ ├── __init__.py
│ │ └── test_utils.py
├── test
│ ├── __init__.py
│ └── my_tests
│ ├── __init__.py
│ ├── agent
│ │ ├── __init__.py
│ │ ├── test_agent.py
│ │ ├── ...
└── tox.ini发布于 2022-09-27 15:27:08
我偶然发现了一个解决方案--摆脱了sitepackages = True文件中的tox.ini行。
不知道为什么这个能解决这个问题。我只添加了这一行(几年前),因为我认为如果它也能够使用来自全局环境的东西,它将加快构建测试环境的速度。根据医生们,它的功能如下:
如果要创建也可以访问全局安装的包的虚拟环境,则设置为true。
没有说明在这种情况下“全局”意味着什么--而不是在任何虚拟env中?在我用于开发的虚拟env中?
奇怪的是,没有这一行构建实际上要快得多。这就像在文档或其他方面的语义是向后的-它在py39-pandas11 installed:行中安装的先决条件要少得多:
py39-pandas11 inst-nodeps: /Users/kwilliams/git/my-pkg/.tox/.tmp/package/1/mypkg-2.1.tar.gz
py39-pandas11 installed: coverage==6.4.4,my-pkg @ file:///Users/kwilliams/git/my-pkg/.tox/.tmp/package/1/my_pkg-2.1.tar.gz,importlib-resources==5.9.0,jsonpickle==2.2.0,mock==4.0.3,more-itertools==8.14.0,nose==1.3.7,numpy==1.23.3,pandas==1.1.5,pycron==3.0.0,python-dateutil==2.8.2,pytz==2022.2.1,PyYAML==6.0,six==1.16.0, my_internal_package==1.1.1,zipp==3.8.1
py39-pandas11 run-test-pre: PYTHONHASHSEED='2799664931'
py39-pandas11 run-test: commands[0] | python -m coverage run -m nose
.....................................................S..SS...
----------------------------------------------------------------------
Ran 61 tests in 2.506s
OK (SKIP=3)不管怎么说,我的身材现在很好。
https://stackoverflow.com/questions/73860586
复制相似问题