配置
Rye 的大部分配置都包含在 pyproject.toml
文件中。但是,也有一些全局配置来影响它的工作方式。
更改主文件夹
默认情况下,Rye 将其所有配置放在 Unix 上的 ~/.rye
和 Windows 上的 %USERPROFILE%\.rye
中。这种行为可以通过 RYE_HOME
环境变量来改变。如果您不喜欢 Rye 将其配置放置的默认位置,或者需要将其隔离,这将很有用。
主文件夹结构
.rye
主文件夹包含用户配置以及 Rye 管理的状态,例如 已安装的工具链。以下文件和文件夹放置在 .rye
文件夹中。请注意,并非所有文件和文件夹都始终存在。
config.toml
这是一个影响 Rye 操作的配置文件。目前,那里只有很少的配置可用。有关可用的配置键,请参阅 配置文件。
self
虽然 Rye 是用 Rust 编写的,但它在内部使用了大量的 Python 工具。这些工具维护在存储在此位置的内部虚拟环境中。
py
在此文件夹中,Rye 存储了不同的 工具链。通常情况下,这些是包含已下载的 Python 发行版的文件夹,但它们也可以是符号链接或特殊引用文件。
shims
此文件夹包含垫片二进制文件。这些二进制文件例如是 python
可执行文件,它会自动代理到当前虚拟环境或全局安装的 工具。
配置文件
.rye
文件夹中的配置文件 config.toml
目前仅用于管理默认值。这是一个完全注释的配置文件
[default]
# This is the default value that is written into new pyproject.toml
# files for the `project.requires-python` key
requires-python = ">= 3.8"
# This is the default toolchain that is used
toolchain = "[email protected]"
# This is the default build system that is used
build-system = "hatchling"
# This is the default license that is used
license = "MIT"
# This sets the default author (overrides the defaults from git). The
# format here is "Name <email>".
author = "Full Name <[email protected]>"
# The dependency operator to use by default for dependencies. The options are
# '>=', '~=', and '=='. The default currently is '>='. This affects the behavior
# of `rye add`.
dependency-operator = ">="
[proxy]
# the proxy to use for HTTP (overridden by the http_proxy environment variable)
http = "http://127.0.0.1:4000"
# the proxy to use for HTTPS (overridden by the https_proxy environment variable)
https = "http://127.0.0.1:4000"
[behavior]
# When set to `true` the `managed` flag is always assumed to be `true`.
force-rye-managed = false
# Enables global shims when set to `true`. This means that the installed
# `python` shim will resolve to a Rye-managed toolchain even outside of
# virtual environments.
global-python = false
# Enable or disable automatic `sync` after `add` and `remove`. This defaults
# to `true` when uv is enabled and `false` otherwise.
autosync = true
# Marks the managed .venv in a way that cloud-based synchronization systems
# like Dropbox and iCloud Files will not upload it. This defaults to `true`
# as a .venv in cloud storage typically does not make sense. Set this to
# `false` to disable this behavior.
venv-mark-sync-ignore = true
# When set to `true` Rye will fetch certain interpreters with build information.
# This will increase the space requirements, will put the interpreter into an
# extra folder called `./install/` and place build artifacts adjacent in `./build`.
fetch-with-build-info = false
# An array of tables with optional sources. Same format as in pyproject.toml
[[sources]]
name = "default"
url = "https://pypi.ac.cn/simple/"
操作配置
新添加于 0.9.0
可以使用 rye config
读取和修改配置。键采用点分隔符号。--get
读取一个键,--set
、--set-int
、--set-bool
和 --unset
修改一个键。
rye config --set proxy.http=http://127.0.0.1:4000
rye config --set-bool behavior.force-rye-managed=true
rye config --get default.requires-python
有关更多信息,请参阅 config
。
每个项目配置
有关特定于项目的 pyproject.toml
配置,请参阅 pyproject.toml。