我有一个非常简单的 python/typer 程序。
我还使用诗歌作为构建工具。
这是我的 pyproject.toml 文件的片段:
name = "cat-cli"
version = "0.1.3"
description = "Cat Cli"
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法将 toml 文件中指定的版本号获取到我的 python 程序中?
先感谢您
我正在用诗歌来构建我的包。我配置 pyproject.toml 以包含所有文件,tests但想要排除tests\\not_this_dir. 目标是当我在下面添加其他内容时,tests它们会被自动拾取。因为我有一些使用专有数据集的测试,所以我将它们放入其中,tests\\not_this_dir这样它们就不会被分发。
我遇到的问题是我无法说服诗歌排除not_this_dir. 这是我的缩写的内容pyproject.toml。
[tool.poetry]\nname = "mypkg"\nversion = "0.2.0"\ninclude = [\n { path = "data" },\n { path = "tests" },\n\nexclude = [\n { path = "tests/not_this_dir" }\n]\n\n[build-system]\nrequires = ["poetry-core"]\nbuild-backend = "poetry.core.masonry.api"\nRun Code Online (Sandbox Code Playgroud)\n文件结构为:
\nmypkg\n\xc2\xa6 .gitignore\n\xc2\xa6 pyproject.toml\n\xc2\xa6 README.txt\n\xc2\xa6 \n+---mypkg\n\xc2\xa6 \xc2\xa6 a.py\n\xc2\xa6 \xc2\xa6 b.py\n\xc2\xa6 \xc2\xa6 __init__.py\n\xc2\xa6 \n+---data\n\xc2\xa6 e.json\n\xc2\xa6 f.json\n\xc2\xa6 \n+---tests\n\xc2\xa6 \xc2\xa6 conftest.py\n\xc2\xa6 \xc2\xa6 test_g.py\n\xc2\xa6 \xc2\xa6 test_h.py\n\xc2\xa6 \xc2\xa6 __init__.py\n\xc2\xa6 \xc2\xa6 \n\xc2\xa6 +---data\n\xc2\xa6 \xc2\xa6 +---g\n\xc2\xa6 \xc2\xa6 …Run Code Online (Sandbox Code Playgroud) 我安装了一个包poetry add X,所以现在它显示在 toml 文件和 venv 中(我的位于.venv/lib/python3.10/site-packages/)。
现在要删除该软件包,我可以使用poetry remove X并且我知道它会正常工作。但有时,进入 toml 文件并删除那里的包行会更容易。这就是我尝试删除 X 行的方法。
然后我尝试这样做poetry install,但没有做任何事情当我这样做时ls .venv/lib/python3.10/site-packages/,我仍然看到 X 安装在那里。
我也尝试过poetry lock,但也没有改变。
那么是否有一些命令可以获取最新的 toml 文件并清除已安装的 toml 中不再存在的软件包?
我想我错过了一些简单的东西
我有一个Python诗歌应用程序:
name = "my-first-api"
version = "0.1.0"
description = ""
readme = "README.md"
packages = [{include = "application"}]
[tool.poetry.scripts]
start = "main:start"
[tool.poetry.dependencies]
python = ">=3.10,<3.12"
pip= "23.0.1"
setuptools="65.5.0"
fastapi="0.89.1"
uvicorn="0.20.0"
[tool.poetry.group.dev.dependencies]
pyinstaller = "^5.10.1"
pytest = "^7.3.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Run Code Online (Sandbox Code Playgroud)
我可以运行它并使用 Poetry 构建它,但是,我也希望能够使用诗歌脚本创建可执行文件。
现在我这样构建它:
poetry run pyinstaller main.py --collect-submodules application --onefile --name myapi
我想要类似的东西
poetry package也自动创建此可执行文件。我该如何连接它?
顺便提一句。这不起作用:(
[tool.poetry.scripts]
start = "main:start"
builddist = "poetry run pyinstaller main.py --collect-submodules application --onefile --name myapi"
Run Code Online (Sandbox Code Playgroud) 我刚刚使用以下安装脚本安装了诗歌
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3
Run Code Online (Sandbox Code Playgroud)
但是,当我执行诗歌时,它失败并出现以下错误
$ poetry
/usr/bin/env: ‘python’: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我最近升级到 ubuntu 20.04,这是升级的问题还是诗歌的问题?
在最近的一次发布审查中,我们惊讶地发现一些 GPL 包已作为可传递依赖项安装。有没有办法将 pip 或诗歌安装配置为在某些许可证类型上失败?我们的旧服务使用 pip,而新服务使用诗歌。或者,是否至少有一种列出所有依赖项(包括传递依赖项)的许可证的好方法?
以前,在定义如何构建 Python 包时,您可以使用 in 行包含文件夹Manifest.in:
recursive-include my_package/assets *
Run Code Online (Sandbox Code Playgroud)
但是,我想poetry和关联的pyproject.toml,而不是Manifest.in。
可以pyproject.toml换Manifest.in吗?或者,如何poetry与Manifest.in?
我的包版本在两个地方定义:
__version__ = 1.2.3 在 mypackage/__init__.pyversion = "1.2.3"在pyproject.toml(我正在使用诗歌)每当我遇到烦人而不是 DRY 的版本时,我都必须更新两者。有没有办法让 Python 从 TOML 读取版本,或者让 TOML 从 Python 读取版本?
我一直在使用 Docker 和 pipelinev 进行数据科学部署设置,现在我想更改为 Poetry。我的 Dockerfile 是:
FROM python:3.8-alpine3.13
ENV POETRY_VIRTUALENVS_CREATE=false \
POETRY_VERSION=1.1.11
RUN apk add --no-cache python3-dev gcc libc-dev musl-dev openblas gfortran build-base postgresql-libs postgresql-dev libffi-dev \
&& pip install poetry
COPY pyproject.toml poetry.lock ./
RUN poetry export -f requirements.txt --output requirements.txt && sed -i 's/^-e //' requirements.txt
USER root
RUN apt-get update && apt-get install -y --no-install-recommends python3-dev gcc libc-dev musl-dev openssh-client git libpq-dev \
&& apt-get clean -y
# install dependencies from requirements.txt
RUN pip install …Run Code Online (Sandbox Code Playgroud) 我是新手poetry,我已经四处搜索过,但如果我错过了一些明显的东西,我深表歉意。
pyproject.toml)poetry shell或poetry install,可能与 结合使用poetry env use),将我置于一个使用上面指定的 python 版本的环境中(我不介意它是否是几个命令而不是一个)poetry env use 3.10(当我还没有安装 python 3.10 时)
/bin/sh: python3.10: command not foundpoetrypython 3.10poetry env use 3.10(当我在conda安装了 python 3.10 的环境中时)
python可执行文件与 conda 环境中的可执行文件符号链接poetry而不是conda所以我想避免依赖conda安装 python 版本poetry配合使用pyenv(其中pyenv用于安装python版本)。
是否需要使用类似pyenv安装 python 版本的东西?有没有办法告诉我poetry我希望 …
python-poetry ×10
python ×7
docker ×1
dry ×1
executable ×1
linux ×1
package ×1
pip ×1
pypi ×1
python-3.x ×1
python-venv ×1
ubuntu-20.04 ×1
version ×1