Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Rye - Package Manager #410

Open
hhstore opened this issue Aug 30, 2023 · 8 comments
Open

Python: Rye - Package Manager #410

hhstore opened this issue Aug 30, 2023 · 8 comments
Labels
Package Python python 3.5+ (3.6, 3.7) Rust

Comments

@hhstore
Copy link
Owner

hhstore commented Aug 30, 2023

๐Ÿ“– Abstract:

  • โœ… Rye: Python ๆ–ฐ็š„ๅŒ…็ฎก็†ๅทฅๅ…ท. (mitsuhiko ๅผ€ๅ‘, flask ไฝœ่€…)

๐Ÿ’ฏ Related:

@hhstore
Copy link
Owner Author

hhstore commented Aug 30, 2023

Rye: Python ๆ–ฐ็š„ๅŒ…็ฎก็†ๅทฅๅ…ท

Rye ้กน็›ฎ็ฎ€ไป‹:

  • https://github.com/mitsuhiko/rye
  • ไฝฟ็”จ Rust ๅฎž็Žฐ็š„ Python ๅŒ…็ฎก็†ๅทฅๅ…ท. (ๅ‚่€ƒไบ† rustup/cargo ็š„่ฎพ่ฎก)
  • ไฝœ่€…ๆ˜ฏ mitsuhiko, flask ไฝœ่€…. Python ็คพๅŒบ็Ÿฅๅๅผ€ๅ‘่€….
  • ่ฟ™ไธช้กน็›ฎๅ‡บๆฅๆœ‰ไธ€ๆฎตๆ—ถ้—ดไบ†, ๆœ€่ฟ‘ๅ‘ๅธƒไบ†ไธ€ไธชๆ–ฐ็‰นๆ€ง Rust Modules: rust ๆ’ไปถๅบ“ๅŠŸ่ƒฝ.
  • so, ๆœ‰ๅฟ…่ฆไป‹็ปไธ€ไธ‹.

Python็คพๅŒบ็›ฎๅ‰ๅทฒๆœ‰ๆ–นๆกˆ:

  • โœ…๏ธ pip: ๅฎ˜ๆ–น้ป˜่ฎคๅŒ…ๅฎ‰่ฃ…(ๆœ€ๅค่€็š„). ้…ๅˆ requirements.txt
  • โœ…๏ธ pdm - ็›ฎๅ‰ๆœ€ๅฅฝ
  • โœ…๏ธ pyenv: Python ๅคš็‰ˆๆœฌ็ฎก็†(virtualenv)
  • โœ…๏ธ poetry: ๅŒ…็ฎก็†ๅทฅๅ…ท. ้…ๅˆ pyproject.toml
  • โœ…๏ธ ๅ…ถไป–ๆ–นๆกˆ pipenv, ๆˆ‘ไธชไบบๅนถไธๆ˜ฏๅคชๅ–œๆฌข. (็ผบๅคฑไธ€ไบ›ๅŠŸ่ƒฝ)

ๆˆ‘ไฝฟ็”จ็š„ๆ–นๆกˆ:

  • โœ…๏ธ ้•ฟๆœŸไฝฟ็”จ: pyenv + poetry.
  • โœ…๏ธ pyenv ็ฎก็† python ็‰ˆๆœฌ.
  • โœ…๏ธ poetry ็ฎก็† python ไพ่ต–ๅŒ….

@hhstore
Copy link
Owner Author

hhstore commented Aug 30, 2023

Rye ไฝฟ็”จๆ•™็จ‹:

Rye ๅฎ‰่ฃ…+้…็ฝฎ:

Rye ๅฎ‰่ฃ…:

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

Rye ้…็ฝฎ็Žฏๅขƒๅ˜้‡:

  • ้…็ฝฎ: Add Shims to Path, ่ฎพ็ฝฎ็Žฏๅขƒๅ˜้‡

Rye + zsh:

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

Rye + fish:

  • ๅฎ˜ๆ–นๆ–‡ๆกฃๆœชๆไพ› fish ่ฎพ็ฝฎ, ๆŸฅ็œ‹ env ๆ–‡ไปถ, ๆ‰‹ๅŠจๆทปๅŠ ๅฆ‚ไธ‹:
# fish:
# python + rye: $HOME/.rye/shims
set -gx PATH "$PATH:$HOME/.rye/shims"

ๆ–นๆณ•2:

  • ๅฎ‰่ฃ…ไธ€ไธชๆ’ไปถ: foreign-env
# install
omf install foreign-env
  • ๆ›ดๆ–ฐ ~/.config/fish/config.fish ้…็ฝฎๆ–‡ไปถ:
# 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
  • sync+run:
rye add black
rye sync
rye run black

@hhstore
Copy link
Owner Author

hhstore commented Aug 30, 2023

้…็ฝฎๆ–‡ไปถ:

ๅ…จๅฑ€:

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

้กน็›ฎๅ†…:

  • pyproject.toml
[[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
Copy link
Owner Author

hhstore commented Aug 30, 2023

python + rust ๆ’ไปถ:

rye init my-project --build-system maturin
cd maturin
  • ๅฎ‰่ฃ… maturin:
rye install maturin

  • ๅทฅๅ…ท้“พ:
rye add --dev pip
rye sync

@hhstore
Copy link
Owner Author

hhstore commented Aug 30, 2023

ๅ‘ๅธƒๅŒ…:

ๆž„ๅปบ:

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
Copy link
Owner Author

hhstore commented Aug 30, 2023

ๅฎ‰่ฃ…ๆ—ฅๅฟ—:

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
Copy link
Owner Author

hhstore commented Aug 30, 2023

1

1 similar comment
@hhstore
Copy link
Owner Author

hhstore commented Aug 30, 2023

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package Python python 3.5+ (3.6, 3.7) Rust
Projects
None yet
Development

No branches or pull requests

1 participant