hhstore / blog

My Tech Blog: about Mojo / Rust / Golang / Python / Kotlin / Flutter / VueJS / Blockchain etc.
https://github.com/hhstore/blog/issues
294 stars 24 forks source link

Python: Rye - Package Manager #410

Open hhstore opened 1 year ago

hhstore commented 1 year ago

📖 Abstract:

💯 Related:

hhstore commented 1 year ago

Rye: Python 新的包管理工具

Rye 项目简介:

Python社区目前已有方案:

我使用的方案:

hhstore commented 1 year ago

Rye 使用教程:

Rye 安装+配置:

Rye 安装:


curl -sSf https://rye-up.com/get | bash

Rye 配置环境变量:

Rye + zsh:


# zsh:
echo 'source "$HOME/.rye/env"' >> ~/.zshrc

Rye + fish:

# fish:
# python + rye: $HOME/.rye/shims
set -gx PATH "$PATH:$HOME/.rye/shims"

方法2:

# install
omf install foreign-env

# fenv + rye: source "$HOME/.rye/env"
if status --is-interactive
  fenv source "$HOME/.rye/env"
end
# rye end

Rye 更新:

rye self update

Rye 卸载:


rye self uninstall

Rye 基本用法:

新建项目:

rye init my-project

锁定 python 版本:


$ rye pin 3.10

添加/删除 python 依赖包:


rye add "flask>=2.0"

# dev 包:
rye add --dev black

rye remove flask

rye add black
rye sync
rye run black
hhstore commented 1 year ago

配置文件:

全局:


[[sources]]
name = "company-internal"
url = "https://company.internal/simple/"

项目内:


[[tool.rye.sources]]
name = "company-internal"
url = "https://company.internal/simple/"

toolchains


rye pin cpython@3.11.4

rye toolchain list

rye toolchain fetch cpython@3.8.5

rye toolchain remove cpython@3.8.5
hhstore commented 1 year ago

python + rust 插件:


rye init my-project --build-system maturin
cd maturin
rye install maturin

rye add --dev pip
rye sync
hhstore commented 1 year ago

发布包:

构建:


rye build
rye build --wheel --out target
rye build --clean

发布:


rye publish

rye publish dist/example-0.1.0.tar.gz

rye publish --token <your_token> --yes
hhstore commented 1 year ago

安装日志:


task: [install:rye] curl -sSf https://rye-up.com/get | bash
This script will automatically download and install rye (latest) for you.
######################################################################## 100.0%
Welcome to Rye!

This installer will install rye to /Users/dev/.rye
This path can be changed by exporting the RYE_HOME environment variable.

Details:
  Rye Version: 0.13.0
  Platform: macos (aarch64)

Continue? yes
Installed binary to /Users/dev/.rye/shims/rye
Bootstrapping rye internals
Downloading cpython@3.11.5
Checking checksum
success: Downloaded cpython@3.11.5
Upgrading pip
Installing internal dependencies
Updated self-python installation at /Users/dev/.rye/self

The rye directory /Users/dev/.rye/shims was not detected on PATH.
It is highly recommended that you add it.
Add this at the end of your .profile, .zprofile or similar:

    source "$HOME/.rye/env"

Note: after adding rye to your path, restart your shell for it to take effect.
For more information read https://mitsuhiko.github.io/rye/guide/installation

All done!

❯ rye --version
rye 0.13.0
commit: 0.13.0 (8e011231e 2023-08-29)
platform: macos (aarch64)
self-python: cpython@3.11
symlink support: true
hhstore commented 1 year ago

1

hhstore commented 1 year ago

1