Skip to content

Commit b3988e9

Browse files
committed
build: 更新构建配置和依赖管理
- 添加 setuptools 构建系统配置 - 使用 importlib.metadata 替代自定义版本管理 - 更新 GitHub Actions 工作流中的 actions 版本 - 优化文档构建流程和依赖安装
1 parent ce215a6 commit b3988e9

File tree

5 files changed

+36
-36
lines changed

5 files changed

+36
-36
lines changed

.github/workflows/pages.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,30 @@ jobs:
3333
with:
3434
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
3535
- name: Checkout
36-
uses: actions/checkout@main
36+
uses: actions/checkout@v4
3737
- name: 🐍 Set up Python
38-
uses: actions/setup-python@main
38+
uses: actions/setup-python@v5
3939
with:
4040
python-version: "3.12"
4141
cache: "pip"
4242
cache-dependency-path: "pyproject.toml"
43-
- name: 🔧 PyPI 配置
43+
- name: 🔧 环境与依赖
4444
run: |
45-
sudo apt-get install graphviz
46-
apt-get update && sudo apt-get upgrade
47-
pip install --upgrade pip
48-
pip install -ve .[doc,dev] --upgrade
49-
git clone --recursive https://github.com/xinetzone/maple-font.git
50-
cd maple-font
51-
pip install -ve .
52-
maple-font build --full
53-
conda install -c conda-forge pandoc compilers podman
45+
sudo apt-get update
46+
sudo apt-get install -y graphviz
47+
python -m pip install --upgrade pip
48+
pip install .[doc,dev] --upgrade
5449
- name: 🔧 Build HTML
5550
run: |
5651
invoke doc
5752
- name: Setup Pages
58-
uses: actions/configure-pages@main
53+
uses: actions/configure-pages@v5
5954
- name: Upload artifact
60-
uses: actions/upload-pages-artifact@main
55+
uses: actions/upload-pages-artifact@v2
6156
with:
6257
# Upload entire repository
6358
path: 'doc/_build/html/'
6459
- name: 🚀 Deploy to GitHub Pages
6560
id: deployment
66-
uses: actions/deploy-pages@main
61+
uses: actions/deploy-pages@v4
6762
# uses: peaceiris/[email protected]

.github/workflows/python-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
deploy:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@main
18+
- uses: actions/checkout@v4
1919
- name: Set up Python
20-
uses: actions/setup-python@main
20+
uses: actions/setup-python@v5
2121
with:
2222
python-version: "3.x"
2323
- name: Install dependencies
@@ -27,7 +27,7 @@ jobs:
2727
- name: Build package
2828
run: python -m build
2929
- name: Publish package
30-
uses: pypa/gh-action-pypi-publish@unstable/v1
30+
uses: pypa/gh-action-pypi-publish@release/v1
3131
with:
3232
user: __token__
3333
password: ${{ secrets.PYPI_API_TOKEN }}

doc/conf.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ def get_project_root():
2323
return Path(__file__).resolve().parents[1]
2424

2525
ROOT = get_project_root()
26-
sys.path.extend([str(ROOT/'doc')])
27-
from taolib import get_version # 引入获取版本号的函数
26+
try:
27+
from importlib.metadata import version as _pkg_version
28+
release = _pkg_version("taolib")
29+
except Exception:
30+
release = os.environ.get("TAOLIB_VERSION", "0.0.0")
2831

2932
# === 注入本地修复版 sphinx_tippy 扩展路径 ===
3033
# 说明:为修复 Wikipedia 抓取告警,优先加载仓库内修复版扩展。
@@ -34,9 +37,8 @@ def get_project_root():
3437
# 将本地扩展源码路径插入到 sys.path 前部,确保优先导入
3538
sys.path.insert(0, str(TIPPY_LOCAL_SRC))
3639
# ================================= 项目基本信息 =================================
37-
project = "tao" # 文档项目名称
38-
author = "xinetzone" # 文档作者
39-
release = get_version("taolib") # 获取taolib主题的版本号
40+
project = "tao"
41+
author = "xinetzone"
4042
copyright = '2021, xinetzone' # 版权信息
4143
# ================================= 国际化与本地化设置 ==============================
4244
language = 'zh_CN' # 文档语言(中文简体)

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,13 @@ dev = [
5555
"numpy",
5656
"matplotlib",
5757
]
58+
59+
[build-system]
60+
requires = ["setuptools>=61", "wheel"]
61+
build-backend = "setuptools.build_meta"
62+
63+
[tool.setuptools]
64+
package-dir = {"" = "src"}
65+
66+
[tool.setuptools.packages.find]
67+
where = ["src"]

src/taolib/__init__.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
"""taolib - 实用工具库
1+
from importlib.metadata import version, PackageNotFoundError
22

3-
该模块提供了一系列实用工具函数和类,用于各种日常开发任务。
4-
"""
5-
# 导入版本模块
6-
try:
7-
from .version import __version__, get_version
8-
except ImportError:
9-
# 如果版本模块不可用,设置默认版本号
10-
__version__ = "0.0.0"
113

12-
def get_version(package_name: str = "taolib", fallback: str = "0.0.0") -> str:
13-
return fallback
14-
15-
__all__ = ["__version__", "get_version", "doc"]
4+
def get_version(pkg_name: str) -> str:
5+
try:
6+
return version(pkg_name)
7+
except PackageNotFoundError:
8+
return "0.0.0"

0 commit comments

Comments
 (0)