小编sin*_*roc的帖子

pyproject.toml 中“[tool.setuptools.packages] find = {}”的功能

用于为包注册表打包 Python 项目的 GitLab 说明指示用户创建包含以下内容的 pyproject.toml 文件:

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "mypypipackage"
version = "0.0.1"
authors = [
    { name="Example Author", email="author@example.com" },
]
description = "A small example package"
requires-python = ">=3.7"
classifiers = [
   "Programming Language :: Python :: 3",
   "Operating System :: OS Independent",
]

[tool.setuptools.packages]
find = {}
Run Code Online (Sandbox Code Playgroud)

find = {}谁能解释一下底部的功能是什么?GitLab 指南没有解释,我似乎找不到任何相关文档。

当然,.toml 文件按照指示工作得很好,但在不[tool.setuptools.packages]完全包含该部分的情况下它似乎也工作得很好。

python setuptools pypi python-packaging

7
推荐指数
1
解决办法
6717
查看次数

如何通过 cfg 文件中的 cmdclass 覆盖 distutils 命令?

我正在将配置从 迁移setup.pysetup.cfg,但我遇到了关键字问题cmdclass。我查看了 setuptools 文档,似乎没有记录或支持此关键字。所以我尝试了options.entry_points。但我不断收到无效命令错误。

这是我所拥有的:

setup.cfg

[options.entry_points]
console_scripts =
    install = CustomInstall:run
Run Code Online (Sandbox Code Playgroud)

setup.py

from setuptools.command.install import install
from setuptools import setup

class CustomInstall(install):
    def run(self):
        print('overriden install command')

setup()
Run Code Online (Sandbox Code Playgroud)

结果只是一个正常的安装命令。但是,我想复制运行时得到的行为:

# setup.py
from setuptools.command.install import install
from setuptools import setup

class CustomInstall(install):
    def run(self):
        print('overriden install command')

setup(cmdclass= {"install": CustomInstall})
Run Code Online (Sandbox Code Playgroud)

它给出了一个覆盖的安装命令。

distutils setuptools setup.py python-packaging

6
推荐指数
1
解决办法
966
查看次数

如何让 pip 告诉我为什么它与 PyPI 二进制轮子不匹配?

我正在构建自己的 Python 安装,然后使用 pip 安装一些包。我想将预构建的二进制轮用于Cryptography等软件包。

  • Python 2.7.15 / 2.7.16
  • 点 19.0.3
  • 安装工具 40.8.0

在 GNU/Linux 上就可以了:它抓住了 Manylinux1 的轮子,一切都工作得很好。

在 MacOS 上,它拒绝下载大多数版本的任何二进制轮。我已经为 pip 添加了很多-v选项,但它只说了:

$ mypython -s -u -m pip install -v --only-binary 'cryptography' 'cryptography==2.6.1'
  ...
Skipping link https://files.pythonhosted.org/packages/.../cryptography-2.6.1-cp27-cp27m-macosx_10_6_intel.whl#sha256=... (from https://pypi.org/simple/cryptography/) (requires-python:>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*); it is not compatible with this Python
  ...
  Could not find a version that satisfies the requirement cryptography==2.6.1 (from versions: 1.0.1, 1.0.2, 1.1, 1.1.1, 1.1.2, 1.2, 1.2.1, 1.2.2, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.4, 1.5, 1.5.1, …
Run Code Online (Sandbox Code Playgroud)

python macos pip python-wheel python-packaging

6
推荐指数
2
解决办法
2249
查看次数

使用 setup.py 自定义 python 包目录布局

假设我有以下目录结构:

\n\n
src/\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 python/\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 generated/\n        \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n        \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 a.py\n        \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lib/\n            \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n            \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 b.py\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的是什么setup.py为了创建目录布局如下的 dist,

\n\n
src/\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 python/\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 a.py\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lib/\n        \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n        \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 b.py\n
Run Code Online (Sandbox Code Playgroud)\n\n

目标是简单地消除该generated文件夹。我尝试了无数的变化,package_dir但除了原始目录结构之外,无法生成任何内容。

\n

distutils setuptools setup.py python-packaging

6
推荐指数
1
解决办法
5126
查看次数

python - setup.py sdist bdist_wheel

我决定创建一个名为“NsmPY”的小模块。一旦我完成了模块背后的代码(可在 GitHub 上找到),我就开始尝试将这个新模块上传到 PyPi。然而,当我运行必要的命令时python3 setup.py sdist bdist_wheel,程序抛出一个错误:

running sdist
running egg_info
writing nsmpy.egg-info\PKG-INFO
writing dependency_links to nsmpy.egg-info\dependency_links.txt
writing top-level names to nsmpy.egg-info\top_level.txt
reading manifest file 'nsmpy.egg-info\SOURCES.txt'
writing manifest file 'nsmpy.egg-info\SOURCES.txt'
warning: sdist: standard file not found: should have one of README, README.rst, README.txt, README.md

running check
creating nsmpy-1.0
creating nsmpy-1.0\nsmpy.egg-info
copying files to nsmpy-1.0...
copying setup.cfg -> nsmpy-1.0
copying setup.py -> nsmpy-1.0
copying nsmpy.egg-info\PKG-INFO -> nsmpy-1.0\nsmpy.egg-info
copying nsmpy.egg-info\SOURCES.txt -> nsmpy-1.0\nsmpy.egg-info
copying nsmpy.egg-info\dependency_links.txt -> nsmpy-1.0\nsmpy.egg-info
copying nsmpy.egg-info\top_level.txt -> nsmpy-1.0\nsmpy.egg-info …
Run Code Online (Sandbox Code Playgroud)

python pip setuptools python-packaging

6
推荐指数
1
解决办法
2万
查看次数

我们可以在 VirtualBox 中导入 .ova 文件后将其删除吗?

我在 MacBook 上安装了 VirtualBox,并下载了 Kali Linux .ova 文件作为虚拟机使用。但是,我的存储空间不足,.ova 文件占用了近 4 GB 的存储空间。现在我已经将 .ova 文件导入到 VirtualBox 中,我可以删除它吗?

virtualbox virtual-machine

6
推荐指数
1
解决办法
4973
查看次数

如何从我的 setup.py 中读取 pyproject.toml 中的项目依赖项,以避免在两个文件中重复信息?

我们正在升级使用BeeWare 的公文包 0.3.1进行打包,它使用pyproject.toml而不是setup.py指定如何打包,包括要在包中包含哪些依赖项。

这是一个pyproject.tomlfor公文包的最小示例:

[tool.briefcase.app.exampleapp]
formal_name = "exampleapp"
description = "something"
requires = ['PyQt5', 'qtconsole']
sources = ['exampleapp']
Run Code Online (Sandbox Code Playgroud)

我们想访问来自 的需求列表setup.py,因此我们不必在两个文件中复制它,并使它们保持同步。我们还没有准备好离开setuptools,这仅用于打包。替代方案当然是让setup.py自动生成pyproject.toml文件,但这似乎与PEP 518的意图有点背道而驰

python setuptools python-packaging pyproject.toml beeware

6
推荐指数
1
解决办法
1594
查看次数

Poetry:在项目目录中创建项目虚拟环境有什么好处?

默认情况下,poetry 在项目 root 之外创建虚拟环境。例如,在 mac 上,它在~/Library/Caches/pypoetry.

但是,我发现了以下建议

# Configure poetry to create virtual environments inside the project's root directory
poetry config virtualenvs.in-project true
Run Code Online (Sandbox Code Playgroud)

另外,诗歌文档本身指出了这两个选项

默认情况下,poetry 在 {cache-dir}/virtualenvs(Windows 上为 {cache-dir}\virtualenvs)中创建一个虚拟环境。您可以通过编辑诗歌配置来更改缓存目录值。此外,您可以使用 virtualenvs.in-project 配置变量在项目目录中创建虚拟环境。

在项目目录内或外部创建项目虚拟环境有什么好处?

virtualenv python-venv python-poetry

6
推荐指数
1
解决办法
7308
查看次数

如何使用诗歌添加私人存储库?

使用Artifactory(https://cloud.google.com/artifact-registry)我打算添加对诗歌的依赖(https://python-poetry.org/docs/repositories/)。

我可以使用命令安装:(pip install --index-url https://us-central1-python.pkg.dev/<PROJECT_ID>/<SOME_LIB_REPO>/simple/ <PACKAGE_NAME>使用 keyrings.google-artifactregistry-auth 进行身份验证)

我打算使用 POETRY 来管理我的依赖项。我不知道使用诗歌是否会增加这种依赖性。poetry add --source <PACKAGE_NAME> https://us-central1-python.pkg.dev/<PROJECT_ID>/<SOME_LIB_REPO>我收到此错误:

poetry update
Updating dependencies
Resolving dependencies... (0.9s)

  RepositoryError

  401 Client Error: Unauthorized for url: https://us-central1-python.pkg.dev/<PROJECT_ID>/<SOME_LIB_REPO>/simple/pytest/
Run Code Online (Sandbox Code Playgroud)

我的 pyproject.toml

...

[[tool.poetry.source]]
name = "SOME_LIB"
url = " https://us-central1-python.pkg.dev/<PROJECT_ID>/<SOME_LIB_REPO>/simple/"
secondary = true
Run Code Online (Sandbox Code Playgroud)

这里有如何使用 PIP/VIRTUALENV 进行配置的详细信息:https://cloud.google.com/artifact-registry/docs/python/authentication但没有有关 Poetry 的详细信息。

您对此有什么建议吗?

python python-packaging python-poetry google-artifact-registry

6
推荐指数
1
解决办法
1090
查看次数

如何在 pyproject.toml 中指定 setuptools 入口点

我有一个像这样的 setup.py :

#!/usr/bin/env python

from setuptools import setup, find_packages

setup(
    name="myproject",
    package_dir={"": "src"},
    packages=find_packages("src"),
    entry_points={
        "console_scripts": [
            "my-script = myproject.myscript:entrypoint",
        ],
    },
)
Run Code Online (Sandbox Code Playgroud)

如何entry_points使用 setuptools 在 pyproject.toml 中编写该配置?

我猜测类似这样的事情,继续setuptools 的 pyproject.toml 文档,它说我需要在引用入口点的文档之后使用“INI 格式” ,但它似乎没有给出示例,我的猜测关于如何将 setuptools 语法与 pyproject.toml 语法结合起来是错误的(我从pip install -e .该报告中得到了回溯pip._vendor.tomli.TOMLDecodeError: Invalid value,指向entry-pointspyproject.toml 中的行):

[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[metadata]
name = "myproject"

[tool.setuptools]
package-dir = {"" = "src"}

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.dynamic]
entry-points …
Run Code Online (Sandbox Code Playgroud)

python program-entry-point setuptools python-packaging pyproject.toml

6
推荐指数
1
解决办法
4760
查看次数