我正在尝试使用 Setuptools 和 Build(PEP 517 构建模块)创建 Python 包的快照/每日构建。
我尝试改编Setuptools文档的这一部分:https://setuptools.pypa.io/en/latest/userguide/distribution.html#tagging-and-daily-build-or-snapshot-releases
但是,以下命令均无效:
python -m build --config-setting=--tag-date myproject
python -m build --config-setting=tag-date myproject
python -m build --tag-date myproject
Run Code Online (Sandbox Code Playgroud)
前两个构建没有版本标记的包,而第三个是错误的。--tag-build当我使用代替 时,结果是相同的--tag-date。
如果上述选项都不起作用,我如何告诉Setuptools添加版本标签?
我没有setup.py,只有一个setup.cfg。我无法使用setup.py bdist_wheel --tag-date,此命令会显示“找不到文件”,因为setup.py我的项目中不存在该文件。
在搜索Setuptools问题跟踪器后进行编辑,我还尝试了以下命令,但没有成功:
python -m build --config-setting=--global-options=--tag-date myproject
python -m build --config-setting=--global-options=tag-date myproject
python -m build --config-setting=global-options=--tag-date myproject
python -m build --config-setting=global-options=tag-date myproject
Run Code Online (Sandbox Code Playgroud) 我想实现与 Dask 库类似的行为,可以使用pip来安装dask、dask[dataframe]和dask[array]其他库。他们通过使用像这样的setup.py包密钥来做到这一点。如果我只安装,则不会安装,并且它们会在执行模块时警告您。daskdask[dataframe]
我在诗歌文档中找到了这一点poetry build,但是当我执行时,我只得到一个.whl包含所有包的文件。
如何打包我的模块以便能够使用安装库的特定部分poetry?
python setup.py python-packaging python-poetry pyproject.toml
我有一个 conda env 文件,其中包含一长串依赖项。我正在考虑按字母顺序对它们进行排序以提高可读性。
但后来我想知道:改变顺序会破坏事情吗?
考虑到这个 GitHub 问题,听起来不应该:https ://github.com/conda/conda/issues/4957
更一般地说,如果有关于如何订购 conda env 依赖项的最佳实践,我有兴趣学习。谢谢。
附录(23/3/2022): 的输出conda env export按字母顺序排序,所以我猜它没问题?
我有一个用诗歌创作的旧项目。诗歌创建的pyproject.toml如下:
\n[tool.poetry]\nname = "Dota2Learning"\nversion = "0.3.0"\ndescription = "Statistics and Machine Learning for your Dota2 Games."\nlicense = "MIT"\nreadme = "README.md"\nhomepage = "Coming soon..."\nrepository = "https://github.com/drigols/dota2learning/"\ndocumentation = "Coming soon..."\ninclude = ["CHANGELOG.md"]\nauthors = [\n "drigols <drigols.creative@gmail.com>",\n]\nmaintainers = [\n "drigols <drigols.creative@gmail.com>",\n]\nkeywords = [\n "dota2",\n "statistics",\n "machine Learning",\n "deep learning",\n]\n\n[tool.poetry.scripts]\ndota2learning = "dota2learning.cli.main:app"\n\n[tool.poetry.dependencies]\npython = "^3.10"\nrequests = "^2.27.1"\ntyper = {extras = ["all"], version = "^0.4.1"}\ninstall = "^1.3.5"\nSQLAlchemy = "^1.4.39"\nPyMySQL = "^1.0.2"\ncryptography = "^37.0.4"\npydantic = "^1.9.1"\nrich = "^12.5.1"\nfastapi = "^0.79.0"\nuvicorn = "^0.18.2"\n\n[tool.poetry.dev-dependencies]\nblack = {extras = …Run Code Online (Sandbox Code Playgroud) 我目前用来setuptools构建我的 Python 包,并且我已经在我的pyproject.toml文件中以这种方式声明了两位作者:
authors = [
{name = "X Y", email = "x.y@tt.net"},
{name = "Z H", email = "z.h@tt.net"},
]
Run Code Online (Sandbox Code Playgroud)
一切正常,我可以在 PyPI 上发布它,但只发布第一作者。我怎样才能显示两位作者。
我尝试使用以下语法
authors = ["X Y <x.y@tt.net>, Z H <z.h@tt.net>"]
Run Code Online (Sandbox Code Playgroud)
但我有以下错误
ValueError: invalid pyproject.toml config: `project.authors[{data__authors_x}]`.
configuration error: `project.authors[{data__authors_x}]` must be object
Run Code Online (Sandbox Code Playgroud)
请注意,我指定:
[build-system]
requires = ["setuptools","numpy","scipy","wheel"]
build-backend = "setuptools.build_meta"
Run Code Online (Sandbox Code Playgroud) 我正在尝试更新我的 Python CI 环境,并且现在正在从事包管理工作。我不想使用诗歌有几个原因;然而,诗歌的一个很好的功能是它会自动更新文件pyproject.toml。我知道 pip-tools 可以requirements.txt从pyproject.toml文件创建文件;但是,当您将带有 pip 的软件包安装到虚拟环境时,virtualenv是否有任何功能pip-tools可以自动更新文件?pyproject.toml
如何可靠地将来自LICENSES/(重用样式)的文件包含在源存档中,并为具有src/布局的 Python 包提供轮子?如何排除特定文件?
我的项目结构看起来像
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 LICENSES\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 MAIN.txt\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 SECUNDARY.txt\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 MANIFEST.in\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 random_package\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 foo1.cpp\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 foo2.cpp\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 submodule1\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bar1.cpp\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 submodule2\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bar2.cpp\nRun Code Online (Sandbox Code Playgroud)\n看起来pyproject.toml像
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 LICENSES\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 MAIN.txt\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 SECUNDARY.txt\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 MANIFEST.in\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 random_package\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 foo1.cpp\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 foo2.cpp\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 submodule1\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bar1.cpp\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 submodule2\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 …Run Code Online (Sandbox Code Playgroud) python setuptools python-wheel python-packaging pyproject.toml
所以我有以下文件结构:
\nproject/\n\xe2\x94\x9c\xe2\x94\x80 cpp_src/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 src/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 cpp source files\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 test/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 cpp test files\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 CMakeLists.txt\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 stub.pyi\n\xe2\x94\x9c\xe2\x94\x80 python_src/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 ...\n\xe2\x94\x9c\xe2\x94\x80 build.py\nRun Code Online (Sandbox Code Playgroud)\n在我的build.py文件中,我使用 setuptools 使用cpp_src自定义build_ext命令来编译和打包 C++ 扩展。但是,我似乎无法让它包含存根文件stub.pyi。如何修改 setuptools 命令来执行此操作?我不太关心文件结构,所以如果setup.py中需要另一个文件cpp_src,那很好。
如果有帮助的话,我还使用 Poetry 来管理虚拟环境。此外,如果有另一个构建系统可以使这变得更容易,我很乐意使用它。
\n谢谢。
\n编辑:这是该文件的简化版本build.py(完整存储库位于https://github.com/Aspect1103/Hades/tree/ Generation- rust ):
project/\n\xe2\x94\x9c\xe2\x94\x80 cpp_src/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 src/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 cpp source files\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 test/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 cpp test files\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 CMakeLists.txt\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 …Run Code Online (Sandbox Code Playgroud) 我对 Rtree 的一个问题感到困惑,Rtree 是我偶尔贡献的一个 Python 包。该包使用cibuildwheel为 PyPI 生成二进制轮。该包使用 ctypes 绑定到libspatialindex的 C API 。
以下是该过程的高级描述:
build.ymlinstall_libspatialindex.bash,并将*.so*共享库复制到 Rtree Python 包中(具体来说rtree/lib)setup.py,它将rtree/lib文件复制到轮子。(可能package-data会更容易,但那是题外话)。构建这个初始的二进制轮,例如将和python -m build --wheel相加。rtree/lib/libspatialindex.sortree/lib/libspatialindex_c.sopatchelf生成新的共享库。Rtree.libs/libspatialindex-91fc2909.so.6.1.1最终结果是一个带有共享库的两个副本的 Linux 二进制轮(一个在 中Rtree.libs,原始的在 中rtree/lib)。首选库是由auditwheel 创建的库,采用Rtree.libs.
解决方法可能是在和rtree/lib的帮助下删除。wheel unpackwheel pack
应该如何配置 cibuildwheel/auditwheel …
我是两个加密包的维护者pypdf,我们支持两个加密包:
要获得完整功能,用户需要安装其中之一。哪一个并不重要。
我如何在 中指定这一点pyproject.toml?
我目前有:
[project.optional-dependencies]
crypto = [
"cryptography; python_version >= '3.7'",
"PyCryptodome; python_version == '3.6'",
]
Run Code Online (Sandbox Code Playgroud)
但当用户拥有 Python >= 3.7 和 PyCryptodome 时,也没什么问题。
python dependency-management python-packaging pyproject.toml
python-packaging ×10
python ×9
setuptools ×4
pip ×2
python-wheel ×2
c++ ×1
conda ×1
linux ×1
pep517 ×1
pip-tools ×1
pypi ×1
setup.py ×1
versioning ×1