1

我使用Poetry进行 Python 依赖管理,以及PyCrate进行 ASN.1 编码/解码。

PyCrate 是从 GitHub 拉取的依赖项,一旦从 GitHub 拉取,就可以通过在 PyCrate 目录中运行安装文件来安装。

python setup.py install

如果可能的话,我想将安装步骤集成到我pyproject.toml的 . 我目前pyproject.toml包括 PyCrate 如下:

…
[tool.poetry.dependencies]
pycrate = {git = "https://github.com/P1sec/pycrate.git"}
…

这将从 GitHub 存储库中拉出 PyCrate,但会拉入srcPoetry 创建的 virtualenv 中的文件夹中。

有没有办法在执行时自动运行安装脚本poetry install?我已经研究过使用Poetry scripts,但到目前为止还没有能够正确启动和运行它。

我当前的设置涉及运行 a poetry install,然后手动运行setup.py installfor PyCrate,但是如果可以的话,我想让我poetry install执行完整的设置。

对此的任何帮助将不胜感激。

4

1 回答 1

1

当你奔跑时,诗歌应该已经python setup.py install为你奔跑了poetry install

Poetry 基本上只是运行pip install package,它下载包,基本上只是python setup.py install在包上运行!

在引擎盖下,[pip] 将运行python setup.py install

来源:https ://stackoverflow.com/a/15732821/10149169

但是,poetry 仅将软件包安装在隔离的虚拟环境中,以避免污染计算机的其余部分。

要用诗歌来运行某些东西,你需要用它来运行它poetry run YOUR_COMMAND

为了在虚拟环境中运行脚本,您必须运行poetry shell以进入虚拟环境,或者poetry run YOUR_COMMAND. 例如,要运行 Python 脚本,您应该这样做poetry run python your_python_script.py

例子

如果您有一个包含以下pyproject.toml文件的文件夹:

[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.6"
pycrate = {git = "https://github.com/P1sec/pycrate.git"}

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

运行后poetry install,您可以通过运行以下命令访问所有 pyrcrate 脚本poetry run SCRIPT_NAME

# works because pycrate_showmedia.py was installed with poetry install
me@computer:~/example-project$ poetry run poetry run pycrate_showmedia.py
usage: pycrate_showmedia.py [-h] [-bl BL] [-wt] input
pycrate_showmedia.py: error: the following arguments are required: input

如果您有一个导入 pycrate 库的 Python 文件,则还需要使用以下命令运行它poetry run

me@computer:~/example-project$ cat test.py 
import pycrate_core
print(pycrate_core.__version__)
me@computer:~/example-project$ poetry run python test.py
于 2019-12-02T17:55:43.200 回答