一个用于从项目依赖项生成conda环境文件的Python辅助工具。
项目描述
pydeps2env
从您的Python项目依赖项创建conda环境文件的一种简单方法。
从列在单个或多个不同源格式(如pyproject.toml
、setup.cfg
、environment.yaml
或requirements.txt
)中的Python包依赖项创建conda environment.yml
文件。
该项目包含
- GitHub动作
- Python包
- 命令行脚本
flowchart LR
pyproject.toml --> pydeps2env
setup.cfg --> pydeps2env
environment.yaml --> pydeps2env
requirements.txt --> pydeps2env
pydeps2env --> E2[environment.yaml]
pydeps2env --> R2[requirements.txt]
基本使用(GitHub动作)
默认情况下,该操作将解析您根目录中的pyproject.toml
文件到environment.yml
。以下是一个简单的示例设置
steps:
- uses: CagtayFabry/pydeps2env@v1.0.0
[project]
requires-python = ">=3.8,<3.10"
dependencies = [
"numpy >=1.20",
"pandas >=1.0",
"IPython",
"boltons",
]
[project.optional-dependencies]
test = ["pytest"]
pip_only = ["bidict"]
默认参数将输出此排序后的environment.yml
(请注意,Python依赖规范将始终是列表中的第一个项目)
channels:
- defaults
dependencies:
- python>=3.8,<3.10
- boltons
- IPython
- numpy>=1.20
- pandas>=1.0
带有选项--build_system include --extras test pip_only --pip bidict
的完整输出
channels:
- defaults
dependencies:
- python>=3.8,<3.10
- boltons
- IPython
- numpy>=1.20
- pandas>=1.0
- pytest
- setuptools>=40.9.0
- setuptools_scm
- wheel
- pip:
- bidict
基本使用(Python)
使用Python创建一个Environment
并将其导出到environment.yaml
文件。
from pydeps2env import Environment
env = Environment("./test/pyproject.toml[doc]")
env.export("my_environment.yaml")
基本使用(命令行)
将多个源文件合并到单个环境文件中(包括构建依赖项)。使用pip
安装pandas。
pydeps2env ./test/setup.cfg ./test/pyproject.toml[doc] ./test/environment.yaml ./test/requirements.txt -o output.yaml -c defaults --extras test -b include --pip pandas
高级用法(定义文件)
用户可以将复杂配置存储在一个 YAML 文件中,并使用 create_from_definition
创建所需的输出。示例定义文件
# the target file to create
output: test-configuration.yaml
# default name of the environment
name: test-env
# conda channels to include
channels:
- conda-forge
- defaults
# list of source files that define sub environments
# these will be loaded as Environment()
sources:
- ./test/environment.yaml
- ./test/local.yaml
- ./test/pyproject.toml[doc]
- ./test/requirements.txt
- https://github.com/CagtayFabry/pydeps2env/blob/custom_deps/pyproject.toml
# extras to apply to all sources and packages
extras:
- test
# dependencies that should be removed after collection
remove:
- pyyaml
additional_requirements:
- urllib3
# include build system dependencies
# list of dependencies that must be pip installed (excluding auto-sorted depedencies like urls)
pip:
- urllib3
include_build_system: include
配置选项(GitHub 动作)
为了自定义输出,操作可以使用输入选项
文件
指定要解析的依赖文件的位置。默认为 'pyproject.toml'。可以列出多个文件。这将会生成一个组合的环境文件。
输出
指定要生成的 conda 环境文件的位置和名称。默认为 'environment.yml'
频道
列出要在环境文件中包含的 conda 频道。默认为 'conda-forge'
。使用空格分隔多个频道(例如,'conda-forge defaults'
)。
额外选项
指定一个或多个可选的 [extras_require]
部分,以添加到所有环境中(例如,使用 'test'
包括通常使用 pip install pkg[test]
安装的包)。请注意,对于单个包,也可以使用 [extra] 的语法。
构建系统
如果设置为 'include'
,则 [build-system]
下列出的依赖项(或在 setup.cfg
中的 [options:setup_requires]
)将被添加到环境中(默认为 'omit'
,因此不会安装设置依赖项)。
pip
列出要通过 pip
安装的包,而不是通过 conda
。依赖项将列在环境文件的 pip:
部分下。如果依赖项带有其 URN,它将始终通过 pip 安装(例如,pydeps2env @ git+https://github.com/CagtayFabry/pydeps2env
)
示例
steps:
- uses: CagtayFabry/pydeps2env@v1.0.0
with:
files: ./test/pyproject.toml[doc] ./test/setup.cfg # comine both files, add [doc] only for pyproject.toml
output: 'environment_test.yml'
channels: 'conda-forge defaults'
extras: 'test'
build_system: 'include'
pip: 'bidict'
[project]
requires-python = ">=3.8,<3.10"
dependencies = [
"numpy >=1.20",
"pandas >=1.0",
"IPython",
"boltons",
]
[project.optional-dependencies]
test = ["pytest"]
pip_only = ["bidict"]
channels:
- conda-forge
- defaults
dependencies:
- python>=3.8,<3.10
- boltons
- IPython
- numpy>=1.20
- pandas>=1.0
- pytest
- setuptools>=40.9.0
- setuptools_scm
- sphinx
- wheel
- pip:
- bidict
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
构建分布
pydeps2env-1.2.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 3c3ce127d2ade4ce8751327b9edbdebb103f2bf738fb43ec6291d523e97799ea |
|
MD5 | d5b45788ce09d3929b2227b3fb3ee606 |
|
BLAKE2b-256 | 8437ad2835e3c69a0f2b38851ff1a2d11e73b9658d217950256d543d51c78733 |
pydeps2env-1.2.0-py3-none-any.whl 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 86f37f49fb6d8de2912d0525644c6d612fccb2e4b3ec0055ca910d8499a949ea |
|
MD5 | 4107672f22194af1ae4f456487c250ac |
|
BLAKE2b-256 | 49092518896cc33cb9113f2e61be690b1a302664ab1e4bf91fe3236890533c97 |