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: PDM - Package Manager #415

Open
hhstore opened this issue Dec 7, 2023 · 8 comments
Open

Python: PDM - Package Manager #415

hhstore opened this issue Dec 7, 2023 · 8 comments
Labels
Package Python python 3.5+ (3.6, 3.7) Tool

Comments

@hhstore
Copy link
Owner

hhstore commented Dec 7, 2023

📖 Abstract:

  • ✅ PDM: 号称当前最好用的 Python 包管理工具.

💯 Related:

@hhstore
Copy link
Owner Author

hhstore commented Dec 7, 2023

PDM: Python 包管理工具

  • Python 的包管理工具, 各有各的问题.
  • 当前使用方案: pyenv + poetry. 基本够用.
  • PDM, 之前看到过, 懒得尝试. (号称比 poetry 更好, 试试看)

Update: 2024-04:

  • ✅ 更推荐 Rye, 已经比较成熟.
  • ❎ 不推荐 PDM, 各种不完善 & bug.(始终不喜欢)

PK 其他:(试用报告)

  • Poetry + Pyenv: 依然是当前(2023-12)首选.
  • Rye: 当前不推荐, 和 Mojo 有干扰, 懒的排雷.(不如 poetry + pyenv)
  • PDM: 不如 Poetry new project 方便, 虽然支持 pdm init --copier xxx 方式, 但不想用.
    • 亮点是 script 功能, 不过我重度使用 go-task, 也一样有.

PS:

  • 💡 这些工具, 和 cargo(rust) 比, 都是半吊子, 各有各的残废.(还是别浪费时间了, 等 Mojo 吧)

PDM 安装:

  • install pdm
  • ✅ 推荐使用如下指令: 支持 pyenv.
pip install pipx
pipx install pdm[all]
  • ❌ 不要使用:
    • ❌ 官方 curl -sSL https://pdm-project.org/install-pdm.py | python3 -
      • 无法和 pyenv 搭配.
    • brew install pdm
      • 会额外安装一堆一堆💩💩!!! (题外: brew 的依赖管理, 越来越恶心)

@hhstore
Copy link
Owner Author

hhstore commented Dec 7, 2023

PDM 功能:

添加包依赖:

pdm add requests   # add requests
pdm add requests==2.25.1   # add requests with version constraint
pdm add requests[socks]   # add requests with extra dependency
pdm add "flask>=1.0" flask-sqlalchemy   # add multiple dependencies with different specifiers


# 本地包: 
pdm add ./sub-package
pdm add ./first-1.0.0-py2.py3-none-any.whl


# 基于 URL:
# Install gzipped package from a plain URL
pdm add "https://github.com/numpy/numpy/releases/download/v1.20.0/numpy-1.20.0.tar.gz"
# Install wheel from a plain URL
pdm add "https://github.com/explosion/spacy-models/releases/download/en_core_web_trf-3.5.0/en_core_web_trf-3.5.0-py3-none-any.whl"

dev 分组:

pdm add -dG test pytest

# 开发分组:
# A relative path to the directory
pdm add -e ./sub-package --dev
# A file URL to a local directory
pdm add -e file:///path/to/sub-package --dev
# A VCS URL
pdm add -e git+https://github.com/pallets/click.git@main#egg=click --dev
  • 配置文件:
[tool.pdm.dev-dependencies]
lint = [
    "flake8",
    "black"
]
test = ["pytest", "pytest-cov"]
doc = ["mkdocs"]

@hhstore
Copy link
Owner Author

hhstore commented Dec 7, 2023

PDM Script 功能: 🌟🌟🌟

[tool.pdm.scripts]
start = {cmd = [
    "flask",
    "run",
    # Important comment here about always using port 54321
    "-p", "54321"
]}

@hhstore
Copy link
Owner Author

hhstore commented Dec 7, 2023

PDM 创建项目:

pdm init --cookiecutter gh:cjolowicz/cookiecutter-hypermodern-python
# or
pdm init --copier gh:pawamoy/copier-pdm --UNSAFE

@hhstore
Copy link
Owner Author

hhstore commented Dec 7, 2023

1

3 similar comments
@hhstore
Copy link
Owner Author

hhstore commented Dec 7, 2023

1

@hhstore
Copy link
Owner Author

hhstore commented Jan 6, 2024

1

@hhstore
Copy link
Owner Author

hhstore commented Jan 6, 2024

1

@hhstore hhstore added Python python 3.5+ (3.6, 3.7) Tool Package labels Jan 6, 2024
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) Tool
Projects
None yet
Development

No branches or pull requests

1 participant