Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f24388b151 | |||
| 535b7cba31 | |||
| 3f68bed3fd | |||
| 2e2ca812a1 | |||
| 8de565d0cb | |||
| 5480c48e67 | |||
| c6653d5117 | |||
| d194a991a0 | |||
| 4446658170 | |||
| 1d26f9d3e7 | |||
| d9644ca5d1 | |||
| d3c2d53449 | |||
| 9cfcfb38e4 | |||
| 69db241611 | |||
| 66e6295a24 | |||
| aebb4fce68 | |||
| 7784c8ff86 | |||
| 77918a5568 | |||
| 7e4c615dc7 | |||
| ac5082523e | |||
| 0df6f7c8ac | |||
| 4b66176ce6 | |||
| cf6b6fd059 | |||
| 6f93e6eb6d | |||
| 43e1aad1fe |
@@ -0,0 +1,47 @@
|
|||||||
|
# 版本控制
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
.github
|
||||||
|
|
||||||
|
# Python 缓存与构建产物
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.pyd
|
||||||
|
*.egg-info
|
||||||
|
*.egg
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
.eggs
|
||||||
|
|
||||||
|
# 测试与覆盖率
|
||||||
|
.pytest_cache
|
||||||
|
.coverage
|
||||||
|
htmlcov
|
||||||
|
.tox
|
||||||
|
coverage.xml
|
||||||
|
|
||||||
|
# 虚拟环境
|
||||||
|
.venv
|
||||||
|
venv
|
||||||
|
env
|
||||||
|
|
||||||
|
# 工具缓存
|
||||||
|
.uv-cache
|
||||||
|
.ruff_cache
|
||||||
|
.pyrefly_cache
|
||||||
|
.mypy_cache
|
||||||
|
|
||||||
|
# IDE 与编辑器
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# 文档与示例(按需保留)
|
||||||
|
docs
|
||||||
|
examples
|
||||||
|
|
||||||
|
# 系统文件
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
+15
-33
@@ -9,42 +9,24 @@ concurrency:
|
|||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint-and-typecheck:
|
ci:
|
||||||
name: Lint & Typecheck
|
name: Lint, Typecheck & Test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: pyflowx-ci:1.0.0
|
||||||
|
env:
|
||||||
|
UV_LINK_MODE: copy
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: http://gitea:3000/zhou/checkout.git@main
|
||||||
|
|
||||||
- uses: astral-sh/setup-uv@v5
|
- name: Sync dependencies
|
||||||
with:
|
run: uv sync --frozen
|
||||||
enable-cache: true
|
|
||||||
|
|
||||||
- uses: actions/setup-python@v5
|
- name: Ruff check
|
||||||
with:
|
run: ruff check src tests
|
||||||
python-version: '3.13'
|
|
||||||
|
|
||||||
- run: uv sync
|
- name: Pyrefly check
|
||||||
- run: uv run ruff check src tests
|
run: pyrefly check src tests
|
||||||
- run: uv run pyrefly check .
|
|
||||||
|
|
||||||
test:
|
- name: Tox test (py38, py313)
|
||||||
name: Test (${{ matrix.os }})
|
run: uvx tox run -e py38,py313
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- uses: astral-sh/setup-uv@v5
|
|
||||||
with:
|
|
||||||
enable-cache: true
|
|
||||||
|
|
||||||
- uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: |
|
|
||||||
3.8
|
|
||||||
3.13
|
|
||||||
|
|
||||||
- run: uvx tox run -e py38,py313
|
|
||||||
|
|||||||
@@ -6,56 +6,38 @@ on:
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
id-token: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
version: ${{ steps.version.outputs.version }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- uses: astral-sh/setup-uv@v5
|
|
||||||
with:
|
|
||||||
enable-cache: true
|
|
||||||
|
|
||||||
- uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.13'
|
|
||||||
|
|
||||||
- run: uv build
|
|
||||||
|
|
||||||
- id: version
|
|
||||||
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v7
|
|
||||||
with:
|
|
||||||
name: dist
|
|
||||||
path: dist/
|
|
||||||
|
|
||||||
publish-pypi:
|
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment: pypi
|
|
||||||
steps:
|
|
||||||
- uses: actions/download-artifact@v8
|
|
||||||
with:
|
|
||||||
name: dist
|
|
||||||
path: dist
|
|
||||||
|
|
||||||
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
needs: [build, publish-pypi]
|
name: Build, Publish & Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: pyflowx-ci:latest
|
||||||
|
env:
|
||||||
|
UV_LINK_MODE: copy
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/download-artifact@v8
|
- uses: http://gitea:3000/zhou/checkout.git@v4
|
||||||
with:
|
|
||||||
name: dist
|
|
||||||
path: dist
|
|
||||||
|
|
||||||
- uses: softprops/action-gh-release@v2
|
- name: Build distributions
|
||||||
|
run: uv build
|
||||||
|
|
||||||
|
- name: Publish to PyPI
|
||||||
|
uses: http://gitea:3000/zhou/gh-action-pypi-publish.git@release/v1
|
||||||
with:
|
with:
|
||||||
files: dist/*
|
password: ${{ secrets.PYPI_API_TOKEN }}
|
||||||
generate_release_notes: true
|
|
||||||
|
- name: Create Gitea Release
|
||||||
|
run: |
|
||||||
|
VERSION=${GITHUB_REF#refs/tags/v}
|
||||||
|
REPO=${GITHUB_REPOSITORY}
|
||||||
|
UPLOAD_URL=$(curl -s -X POST "https://git.gookeryoung.cn/api/v1/repos/${REPO}/releases" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"tag_name\": \"v${VERSION}\", \"name\": \"v${VERSION}\", \"draft\": false, \"prerelease\": false}" \
|
||||||
|
| jq -r '.upload_url')
|
||||||
|
for file in dist/*; do
|
||||||
|
curl -s -X POST "${UPLOAD_URL}?name=$(basename $file)" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary @"$file"
|
||||||
|
done
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ wheels/
|
|||||||
.venv
|
.venv
|
||||||
.coverage
|
.coverage
|
||||||
.idea
|
.idea
|
||||||
|
*_profile.html
|
||||||
|
|||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
# 使用国内镜像源拉取基础镜像
|
||||||
|
# 备选镜像源前缀:docker.1ms.run / dockerpull.com / docker.xuanyuan.me
|
||||||
|
FROM docker.m.daocloud.io/python:3.13-slim
|
||||||
|
|
||||||
|
# 环境变量:非交互 + 路径配置
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive \
|
||||||
|
LANG=C.UTF-8 \
|
||||||
|
LC_ALL=C.UTF-8 \
|
||||||
|
UV_LINK_MODE=copy \
|
||||||
|
UV_CACHE_DIR=/uv-cache \
|
||||||
|
UV_PYTHON_INSTALL_DIR=/uv-python \
|
||||||
|
UV_PROJECT_ENVIRONMENT=/opt/venv \
|
||||||
|
PATH="/opt/venv/bin:${PATH}"
|
||||||
|
|
||||||
|
# 配置 apt 国内镜像(阿里云)并安装系统依赖
|
||||||
|
RUN sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources \
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
ca-certificates \
|
||||||
|
curl \
|
||||||
|
git \
|
||||||
|
jq \
|
||||||
|
build-essential \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# 配置 pip 国内镜像(阿里云)
|
||||||
|
RUN mkdir -p /etc/pip \
|
||||||
|
&& printf '[global]\nindex-url = https://mirrors.aliyun.com/pypi/simple/\ntrusted-host = mirrors.aliyun.com\n' \
|
||||||
|
> /etc/pip/pip.conf \
|
||||||
|
&& mkdir -p /root/.config/pip \
|
||||||
|
&& ln -sf /etc/pip/pip.conf /root/.config/pip/pip.conf
|
||||||
|
|
||||||
|
# 安装 uv 并预装 Python 3.8 / 3.13
|
||||||
|
RUN pip install --no-cache-dir uv -i https://mirrors.aliyun.com/pypi/simple/ \
|
||||||
|
&& uv python install 3.8 3.13
|
||||||
|
|
||||||
|
# 安装 Node.js 20.x(actions/checkout 需要)
|
||||||
|
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
||||||
|
apt-get install -y nodejs && \
|
||||||
|
node --version
|
||||||
|
|
||||||
|
# 预装项目 dev 依赖(仅复制依赖描述文件,利用 Docker 层缓存)
|
||||||
|
WORKDIR /workspace
|
||||||
|
COPY pyproject.toml tox.ini README.md ./
|
||||||
|
COPY src/ ./src/
|
||||||
|
|
||||||
|
# 同步依赖到 /opt/venv(CI 时直接复用)
|
||||||
|
RUN uv sync --frozen --no-install-project 2>/dev/null || uv sync --no-install-project
|
||||||
|
|
||||||
|
# 预装 tox 环境(py38 + py313)
|
||||||
|
RUN uvx tox run -e py38,py313 --notest 2>/dev/null || true
|
||||||
|
|
||||||
|
# 持久化 uv 缓存目录(CI 可挂载到宿主机加速)
|
||||||
|
VOLUME ["/uv-cache"]
|
||||||
|
|
||||||
|
# 默认入口
|
||||||
|
CMD ["/bin/bash"]
|
||||||
+5
-6
@@ -21,11 +21,12 @@ license = { text = "MIT" }
|
|||||||
name = "pyflowx"
|
name = "pyflowx"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.8"
|
requires-python = ">=3.8"
|
||||||
version = "0.2.13"
|
version = "0.3.0"
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
autofmt = "pyflowx.cli.autofmt:main"
|
autofmt = "pyflowx.cli.autofmt:main"
|
||||||
bumpversion = "pyflowx.cli.bumpversion:main"
|
bumpversion = "pyflowx.cli.bumpversion:main"
|
||||||
|
dockercmd = "pyflowx.cli.dev.dockercmd:main"
|
||||||
emlman = "pyflowx.cli.emlmanager:main"
|
emlman = "pyflowx.cli.emlmanager:main"
|
||||||
filedate = "pyflowx.cli.filedate:main"
|
filedate = "pyflowx.cli.filedate:main"
|
||||||
filelvl = "pyflowx.cli.filelevel:main"
|
filelvl = "pyflowx.cli.filelevel:main"
|
||||||
@@ -37,8 +38,8 @@ msdown = "pyflowx.cli.llm.msdownload:main"
|
|||||||
packtool = "pyflowx.cli.packtool:main"
|
packtool = "pyflowx.cli.packtool:main"
|
||||||
pdftool = "pyflowx.cli.pdftool:main"
|
pdftool = "pyflowx.cli.pdftool:main"
|
||||||
piptool = "pyflowx.cli.piptool:main"
|
piptool = "pyflowx.cli.piptool:main"
|
||||||
pymake = "pyflowx.cli.pymake:main"
|
|
||||||
pxp = "pyflowx.cli.profiler:main"
|
pxp = "pyflowx.cli.profiler:main"
|
||||||
|
pymake = "pyflowx.cli.pymake:main"
|
||||||
reseticon = "pyflowx.cli.reseticoncache:main"
|
reseticon = "pyflowx.cli.reseticoncache:main"
|
||||||
scrcap = "pyflowx.cli.screenshot:main"
|
scrcap = "pyflowx.cli.screenshot:main"
|
||||||
sglang = "pyflowx.cli.llm.sglang:main"
|
sglang = "pyflowx.cli.llm.sglang:main"
|
||||||
@@ -66,9 +67,6 @@ dev = [
|
|||||||
"tox-uv>=1.13.1",
|
"tox-uv>=1.13.1",
|
||||||
"tox>=4.25.0",
|
"tox>=4.25.0",
|
||||||
]
|
]
|
||||||
llm = [
|
|
||||||
"sglang[all]==0.5.10rc0; python_version >= '3.10' and sys_platform == 'linux'",
|
|
||||||
]
|
|
||||||
office = [
|
office = [
|
||||||
"pillow>=10.4.0",
|
"pillow>=10.4.0",
|
||||||
"pymupdf>=1.24.11",
|
"pymupdf>=1.24.11",
|
||||||
@@ -94,7 +92,7 @@ packages = ["src/pyflowx"]
|
|||||||
pyflowx = { workspace = true }
|
pyflowx = { workspace = true }
|
||||||
|
|
||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
dev = ["pyflowx[dev,office,llm]"]
|
dev = ["pyflowx[dev,office]"]
|
||||||
|
|
||||||
[tool.coverage.run]
|
[tool.coverage.run]
|
||||||
branch = true
|
branch = true
|
||||||
@@ -158,3 +156,4 @@ select = [
|
|||||||
preset = "strict"
|
preset = "strict"
|
||||||
project-includes = ["**/*.ipynb", "**/*.py*"]
|
project-includes = ["**/*.ipynb", "**/*.py*"]
|
||||||
python-version = "3.8"
|
python-version = "3.8"
|
||||||
|
unused-ignore = false
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ from .task import (
|
|||||||
task_template,
|
task_template,
|
||||||
)
|
)
|
||||||
|
|
||||||
__version__ = "0.3.7"
|
__version__ = "0.4.0"
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"IS_LINUX",
|
"IS_LINUX",
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
|
import pyflowx as px
|
||||||
|
|
||||||
|
DockerMirrorType = Literal["tencent"]
|
||||||
|
|
||||||
|
DOCKER_MIRROR_URLS: dict[DockerMirrorType, str] = {"tencent": "ccr.ccs.tencentyun.com"}
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# parser = argparse.ArgumentParser(description="Docker 命令行工具")
|
||||||
|
# parser.add_argument("--username", nargs="?", default="", type=str, help="Docker 用户名")
|
||||||
|
# args = parser.parse_args()
|
||||||
|
|
||||||
|
tasks: list[px.TaskSpec] = [
|
||||||
|
px.cmd(["docker", "login", "--username", "xxx", DOCKER_MIRROR_URLS["tencent"]], name="docker_login_tencent"),
|
||||||
|
]
|
||||||
|
|
||||||
|
alias: dict[str, str | list[str | px.TaskSpec] | px.TaskSpec | px.Graph] = {
|
||||||
|
"login": "docker_login_tencent",
|
||||||
|
}
|
||||||
|
|
||||||
|
runner = px.CliRunner(strategy="sequential", tasks=tasks, aliases=alias)
|
||||||
|
runner.run_cli()
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import getpass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Literal, get_args
|
from typing import Literal, get_args
|
||||||
|
|
||||||
@@ -254,6 +255,31 @@ def main() -> None:
|
|||||||
allow_upstream_skip=True,
|
allow_upstream_skip=True,
|
||||||
verbose=True,
|
verbose=True,
|
||||||
),
|
),
|
||||||
|
# 安装 Docker
|
||||||
|
px.TaskSpec(
|
||||||
|
"install_docker",
|
||||||
|
cmd=["sudo", "apt", "install", "-y", "docker-compose-v2"],
|
||||||
|
conditions=(BuiltinConditions.IS_LINUX(),),
|
||||||
|
depends_on=("install_mirror",),
|
||||||
|
allow_upstream_skip=True,
|
||||||
|
verbose=True,
|
||||||
|
),
|
||||||
|
px.TaskSpec(
|
||||||
|
"add_docker_group",
|
||||||
|
cmd=["sudo", "usermod", "-aG", "docker", getpass.getuser()],
|
||||||
|
conditions=(BuiltinConditions.IS_LINUX(),),
|
||||||
|
depends_on=("install_docker",),
|
||||||
|
allow_upstream_skip=True,
|
||||||
|
verbose=True,
|
||||||
|
),
|
||||||
|
px.TaskSpec(
|
||||||
|
"refresh_docker_group",
|
||||||
|
cmd=["newgrp", "docker"],
|
||||||
|
conditions=(BuiltinConditions.IS_LINUX(),),
|
||||||
|
depends_on=("add_docker_group",),
|
||||||
|
allow_upstream_skip=True,
|
||||||
|
verbose=True,
|
||||||
|
),
|
||||||
# 设置 Python 环境变量
|
# 设置 Python 环境变量
|
||||||
*setenv_group({
|
*setenv_group({
|
||||||
"PIP_INDEX_URL": PIP_INDEX_URLS[python_mirror],
|
"PIP_INDEX_URL": PIP_INDEX_URLS[python_mirror],
|
||||||
|
|||||||
+24
-15
@@ -6,39 +6,48 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pyflowx as px
|
import pyflowx as px
|
||||||
from pyflowx.conditions import Constants
|
from pyflowx.conditions import Constants
|
||||||
|
|
||||||
|
# 项目根目录(pymake.py 在 src/pyflowx/cli,向上四层到达根目录)
|
||||||
|
ROOT_DIR = Path(__file__).parent.parent.parent.parent
|
||||||
|
|
||||||
MATURIN_BUILD_COMMAND = ["maturin", "build", "-r"]
|
MATURIN_BUILD_COMMAND = ["maturin", "build", "-r"]
|
||||||
if Constants.IS_WINDOWS:
|
if Constants.IS_WINDOWS:
|
||||||
MATURIN_BUILD_COMMAND.extend(["--target", "x86_64-win7-windows-msvc", "-Zbuild-std", "-i", "python3.8"])
|
MATURIN_BUILD_COMMAND.extend(["--target", "x86_64-win7-windows-msvc", "-Zbuild-std", "-i", "python3.8"])
|
||||||
|
|
||||||
# 扁平注册所有任务(px.cmd 自动从命令前两段推导 name)
|
# 扁平注册所有任务(px.cmd 自动从命令前两段推导 name)
|
||||||
|
# 所有任务指定 cwd=ROOT_DIR,确保在项目根目录执行
|
||||||
tasks: list[px.TaskSpec] = [
|
tasks: list[px.TaskSpec] = [
|
||||||
px.cmd(["uv", "build"]),
|
px.cmd(["uv", "build"], cwd=ROOT_DIR),
|
||||||
px.cmd(MATURIN_BUILD_COMMAND),
|
px.cmd(MATURIN_BUILD_COMMAND, cwd=ROOT_DIR),
|
||||||
px.cmd(["uv", "sync"]),
|
px.cmd(["uv", "sync"], cwd=ROOT_DIR),
|
||||||
px.cmd(["gitt", "c"], name="git_clean"),
|
px.cmd(["gitt", "c"], name="git_clean", cwd=ROOT_DIR),
|
||||||
px.cmd(
|
px.cmd(
|
||||||
["pytest", "-m", "not slow", "-n", "8", "--dist", "loadfile", "--color=yes", "--durations=10"],
|
["pytest", "-m", "not slow", "-n", "8", "--dist", "loadfile", "--color=yes", "--durations=10"],
|
||||||
name="test",
|
name="test",
|
||||||
|
cwd=ROOT_DIR,
|
||||||
),
|
),
|
||||||
px.cmd(
|
px.cmd(
|
||||||
["pytest", "-m", "not slow", "--dist", "loadfile", "--color=yes", "--durations=10"],
|
["pytest", "-m", "not slow", "--dist", "loadfile", "--color=yes", "--durations=10"],
|
||||||
name="test_fast",
|
name="test_fast",
|
||||||
|
cwd=ROOT_DIR,
|
||||||
),
|
),
|
||||||
px.cmd(
|
px.cmd(
|
||||||
["pytest", "--cov", "-n", "8", "--dist", "loadfile", "--tb=short", "-v", "--color=yes", "--durations=10"],
|
["pytest", "--cov", "-n", "8", "--dist", "loadfile", "--tb=short", "-v", "--color=yes", "--durations=10"],
|
||||||
name="test_coverage",
|
name="test_coverage",
|
||||||
|
cwd=ROOT_DIR,
|
||||||
),
|
),
|
||||||
px.cmd(["pyrefly", "check", "."]),
|
px.cmd(["pyrefly", "check", "."], cwd=ROOT_DIR),
|
||||||
px.cmd(["git", "add", "-A"], name="git_add_all"),
|
px.cmd(["git", "add", "-A"], name="git_add_all", cwd=ROOT_DIR),
|
||||||
px.cmd(["bumpversion"]),
|
px.cmd(["bumpversion"], cwd=ROOT_DIR),
|
||||||
px.cmd(["bumpversion", "minor"]),
|
px.cmd(["bumpversion", "minor"], cwd=ROOT_DIR),
|
||||||
px.cmd(["git", "push"]),
|
px.cmd(["git", "push"], cwd=ROOT_DIR),
|
||||||
px.cmd(["git", "push", "--tags"], name="git_push_tags"),
|
px.cmd(["git", "push", "--tags"], name="git_push_tags", cwd=ROOT_DIR),
|
||||||
px.cmd(["hatch", "publish"], name="publish_python"),
|
px.cmd(["hatch", "publish"], name="publish_python", cwd=ROOT_DIR),
|
||||||
px.cmd(["twine", "upload", "--disable-progress-bar"], name="twine_publish"),
|
px.cmd(["twine", "upload", "--disable-progress-bar"], name="twine_publish", cwd=ROOT_DIR),
|
||||||
]
|
]
|
||||||
|
|
||||||
# 单任务别名(alias 名与任务名相同):直接内联 TaskSpec,避免 str 自引用
|
# 单任务别名(alias 名与任务名相同):直接内联 TaskSpec,避免 str 自引用
|
||||||
@@ -55,13 +64,13 @@ aliases: dict[str, str | list[str | px.TaskSpec] | px.TaskSpec | px.Graph] = {
|
|||||||
"bump": ["c", "tc", "git_add_all", "bumpversion"],
|
"bump": ["c", "tc", "git_add_all", "bumpversion"],
|
||||||
"bumpmi": "bumpversion_minor",
|
"bumpmi": "bumpversion_minor",
|
||||||
"cov": ["git_clean", "test_coverage"],
|
"cov": ["git_clean", "test_coverage"],
|
||||||
"doc": px.cmd(["sphinx-build", "-b", "html", "docs", "docs/_build"], name="doc"),
|
"doc": px.cmd(["sphinx-build", "-b", "html", "docs", "docs/_build"], name="doc", cwd=ROOT_DIR),
|
||||||
"lint": px.cmd(["ruff", "check", "--fix", "--unsafe-fixes"], name="lint"),
|
"lint": px.cmd(["ruff", "check", "--fix", "--unsafe-fixes"], name="lint", cwd=ROOT_DIR),
|
||||||
"pb": ["twine_publish", "publish_python"],
|
"pb": ["twine_publish", "publish_python"],
|
||||||
"t": "test",
|
"t": "test",
|
||||||
"tf": "test_fast",
|
"tf": "test_fast",
|
||||||
"tc": ["pyrefly_check", "lint"],
|
"tc": ["pyrefly_check", "lint"],
|
||||||
"tox": px.cmd(["tox", "-p", "auto"], name="tox"),
|
"tox": px.cmd(["tox", "-p", "auto"], name="tox", cwd=ROOT_DIR),
|
||||||
# 发布命令
|
# 发布命令
|
||||||
"p": ["git_clean", "git_push", "git_push_tags"],
|
"p": ["git_clean", "git_push", "git_push_tags"],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -123,6 +124,22 @@ class TestTaskSpecDefinitions:
|
|||||||
assert spec.cmd == ["tox", "-p", "auto"]
|
assert spec.cmd == ["tox", "-p", "auto"]
|
||||||
assert spec.skip_if_missing is False
|
assert spec.skip_if_missing is False
|
||||||
|
|
||||||
|
def test_all_tasks_have_correct_cwd(self) -> None:
|
||||||
|
"""所有任务应该有正确的 cwd 设置(指向项目根目录)."""
|
||||||
|
# 验证 ROOT_DIR 定义正确(向上三层到达项目根目录)
|
||||||
|
expected_root = Path(__file__).parent.parent.parent
|
||||||
|
assert expected_root == pymake.ROOT_DIR
|
||||||
|
|
||||||
|
# 验证 tasks 中的所有命令任务都有正确的 cwd
|
||||||
|
for spec in pymake.tasks:
|
||||||
|
if spec.cmd is not None:
|
||||||
|
assert spec.cwd == pymake.ROOT_DIR, f"任务 {spec.name} 的 cwd 应为 {pymake.ROOT_DIR}"
|
||||||
|
|
||||||
|
# 验证 aliases 中的内联任务(doc/lint/tox)也有正确的 cwd
|
||||||
|
for name in ("doc", "lint", "tox"):
|
||||||
|
spec = _find_task(name)
|
||||||
|
assert spec.cwd == pymake.ROOT_DIR, f"任务 {name} 的 cwd 应为 {pymake.ROOT_DIR}"
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------- #
|
||||||
# main function
|
# main function
|
||||||
|
|||||||
+10
-3
@@ -531,16 +531,23 @@ class TestIntegrationWithRun:
|
|||||||
|
|
||||||
def test_profile_from_real_run(self) -> None:
|
def test_profile_from_real_run(self) -> None:
|
||||||
"""从真实 run() 结果构建剖面."""
|
"""从真实 run() 结果构建剖面."""
|
||||||
|
import time
|
||||||
|
|
||||||
|
def slow() -> int:
|
||||||
|
time.sleep(0.01) # 确保任务有实际耗时,避免 duration 极小导致并行度计算为 0
|
||||||
|
return 1
|
||||||
|
|
||||||
graph = px.Graph.from_specs([
|
graph = px.Graph.from_specs([
|
||||||
px.TaskSpec("a", lambda: 1),
|
px.TaskSpec("a", slow),
|
||||||
px.TaskSpec("b", lambda: 2, depends_on=("a",)),
|
px.TaskSpec("b", slow, depends_on=("a",)),
|
||||||
px.TaskSpec("c", lambda: 3, depends_on=("a",)),
|
px.TaskSpec("c", slow, depends_on=("a",)),
|
||||||
])
|
])
|
||||||
report = px.run(graph, strategy="sequential")
|
report = px.run(graph, strategy="sequential")
|
||||||
|
|
||||||
profile = ProfileReport.from_report(report, graph)
|
profile = ProfileReport.from_report(report, graph)
|
||||||
|
|
||||||
assert len(profile.tasks) == 3
|
assert len(profile.tasks) == 3
|
||||||
|
# sequential 策略下应为串行,duration > 0
|
||||||
assert profile.critical_path_duration > 0
|
assert profile.critical_path_duration > 0
|
||||||
# sequential 策略下并行度应为 1
|
# sequential 策略下并行度应为 1
|
||||||
assert profile.peak_parallelism == 1
|
assert profile.peak_parallelism == 1
|
||||||
|
|||||||
+2
-2
@@ -193,8 +193,8 @@ def test_should_execute_skip_if_missing_cmd_not_found() -> None:
|
|||||||
|
|
||||||
def test_should_execute_skip_if_missing_cmd_found() -> None:
|
def test_should_execute_skip_if_missing_cmd_found() -> None:
|
||||||
"""skip_if_missing 但命令存在时应执行."""
|
"""skip_if_missing 但命令存在时应执行."""
|
||||||
# 使用 Python 作为已安装的命令
|
# 使用 Python 作为已安装的命令(Windows 上 echo 是 shell 内置,shutil.which 找不到)
|
||||||
spec = TaskSpec("a", cmd=["echo"], skip_if_missing=True) # echo 应存在
|
spec = TaskSpec("a", cmd=["python"], skip_if_missing=True) # python 应存在
|
||||||
should_run, reason = spec.should_execute({})
|
should_run, reason = spec.should_execute({})
|
||||||
assert should_run is True
|
assert should_run is True
|
||||||
assert reason is None
|
assert reason is None
|
||||||
|
|||||||
Reference in New Issue
Block a user