diff --git a/.github/workflows/Termux-publish.yml b/.github/workflows/Termux-publish.yml index 79b172e..57090e2 100644 --- a/.github/workflows/Termux-publish.yml +++ b/.github/workflows/Termux-publish.yml @@ -39,7 +39,7 @@ jobs: dpkg-deb -x $FNAME python cp -a python/data/data/com.termux/files/usr/lib/libpython* $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/24 sed -i 's/"abi3-py[0-9]*",\? *//g' crates/stream-gears/Cargo.toml - sed -i 's/aiohttp\[speedups\] >= 3\.9\.5/aiohttp[speedups] <= 3.9.5/' pyproject.toml + sed -i 's/aiohttp\[speedups\] >= 3\.9\.5/aiohttp[speedups] <= 3.9.5/' crates/stream-gears/pyproject.toml - name: Build wheel for aarch64 (Termux) run: | export NDK_BIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin @@ -48,6 +48,7 @@ jobs: export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$NDK_BIN/aarch64-linux-android24-clang export PYO3_CROSS_LIB_DIR=python/data/data/com.termux/files/usr/lib/ maturin build \ + -m crates/stream-gears/Cargo.toml \ --release \ --strip \ --manylinux off \ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 498fb19..afea079 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist + args: --release --out dist -m crates/stream-gears/Cargo.toml sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} manylinux: ${{ matrix.platform.target == 'aarch64' && '2_28' || 'auto' }} - name: Smoke test wheel @@ -74,7 +74,7 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist -i python3.14t + args: --release --out dist -m crates/stream-gears/Cargo.toml -i python3.14t sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} manylinux: ${{ matrix.platform.target == 'aarch64' && '2_28' || 'auto' }} - name: Upload wheels @@ -112,14 +112,14 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist + args: --release --out dist -m crates/stream-gears/Cargo.toml sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} manylinux: musllinux_1_2 - name: Build free-threaded wheels uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist -i python3.14t + args: --release --out dist -m crates/stream-gears/Cargo.toml -i python3.14t sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} manylinux: musllinux_1_2 - name: Upload wheels @@ -154,7 +154,7 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist + args: --release --out dist -m crates/stream-gears/Cargo.toml sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - uses: actions/setup-python@v5 with: @@ -164,7 +164,7 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist -i python3.14t + args: --release --out dist -m crates/stream-gears/Cargo.toml -i python3.14t sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - name: Upload wheels uses: actions/upload-artifact@v4 @@ -197,13 +197,13 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist + args: --release --out dist -m crates/stream-gears/Cargo.toml sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - name: Build free-threaded wheels uses: PyO3/maturin-action@v1 with: target: ${{ matrix.platform.target }} - args: --release --out dist -i python3.14t + args: --release --out dist -m crates/stream-gears/Cargo.toml -i python3.14t sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - name: Upload wheels uses: actions/upload-artifact@v4 @@ -226,7 +226,7 @@ jobs: uses: PyO3/maturin-action@v1 with: command: sdist - args: --out dist + args: --out dist -m crates/stream-gears/Cargo.toml - name: Upload sdist uses: actions/upload-artifact@v4 with: diff --git a/Dockerfile b/Dockerfile index 9e4bd57..bca71d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ COPY . /biliup RUN set -eux; \ \ - if [ ! -f /biliup/pyproject.toml ]; then \ + if [ ! -f /biliup/crates/stream-gears/pyproject.toml ]; then \ rm -rf /biliup; \ git clone --depth 1 --branch "$branch_name" "$repo_url" /biliup; \ fi; @@ -31,7 +31,7 @@ RUN set -eux; \ apt-get update; \ apt-get install -y --no-install-recommends python3-pip g++ patchelf; \ pip3 install maturin --break-system-packages; \ - if [ ! -f /biliup/pyproject.toml ]; then \ + if [ ! -f /biliup/crates/stream-gears/pyproject.toml ]; then \ rm -rf /biliup; \ git clone --depth 1 --branch "$branch_name" "$repo_url" /biliup; \ fi; @@ -41,7 +41,7 @@ COPY --from=webui-builder /biliup/out /biliup/out WORKDIR /biliup RUN set -eux; \ - maturin build --release; + maturin build --release -m crates/stream-gears/Cargo.toml; # Deploy Biliup diff --git a/README.md b/README.md index 69f6323..778ce4c 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ graph TB | `crates/danmaku` | 弹幕客户端:多平台协议解析与 XML 输出 | | `crates/stream-gears` | PyO3 绑定,暴露给 `python -m biliup` | | `app`、`public` | Next.js WebUI 源码;`npm run build` 产物输出到 `out/` 并由后端内嵌 | -| `biliup` | 精简 Python 包:最小入口与可供外部调用的投稿库 | +| `crates/stream-gears/biliup` | 精简 Python 包:最小入口与可供外部调用的投稿库 | | `tauri-app` | 桌面端外壳(实验性) | @@ -313,7 +313,7 @@ graph TB ### Python -1. 安装依赖 `maturin dev` +1. 安装依赖 `maturin develop -m crates/stream-gears/Cargo.toml` 2. `npm run build` 3. 启动 Biliup:`python3 -m biliup` diff --git a/biliup/__init__.py b/crates/stream-gears/biliup/__init__.py similarity index 100% rename from biliup/__init__.py rename to crates/stream-gears/biliup/__init__.py diff --git a/biliup/__main__.py b/crates/stream-gears/biliup/__main__.py similarity index 100% rename from biliup/__main__.py rename to crates/stream-gears/biliup/__main__.py diff --git a/biliup/plugins/__init__.py b/crates/stream-gears/biliup/plugins/__init__.py similarity index 100% rename from biliup/plugins/__init__.py rename to crates/stream-gears/biliup/plugins/__init__.py diff --git a/biliup/plugins/bili_webup.py b/crates/stream-gears/biliup/plugins/bili_webup.py similarity index 100% rename from biliup/plugins/bili_webup.py rename to crates/stream-gears/biliup/plugins/bili_webup.py diff --git a/biliup/plugins/bili_webup_sync.py b/crates/stream-gears/biliup/plugins/bili_webup_sync.py similarity index 100% rename from biliup/plugins/bili_webup_sync.py rename to crates/stream-gears/biliup/plugins/bili_webup_sync.py diff --git a/pyproject.toml b/crates/stream-gears/pyproject.toml similarity index 72% rename from pyproject.toml rename to crates/stream-gears/pyproject.toml index c2e355a..299b08e 100644 --- a/pyproject.toml +++ b/crates/stream-gears/pyproject.toml @@ -8,18 +8,15 @@ features = ["pyo3/extension-module"] # Include additional files #include = [ "biliup/web/public/**/*" ] #data = "biliup/web/public" -# Mixed layout: `crates/stream-gears/stream_gears/` (`__init__.py`, stubs, `py.typed`) -# ships alongside the native module, which becomes `stream_gears.stream_gears`. -python-source = "crates/stream-gears" +# Mixed layout: `stream_gears/` (`__init__.py`, stubs, `py.typed`) ships +# alongside the native module, which becomes `stream_gears.stream_gears`. module-name = "stream_gears.stream_gears" -# `python-packages` is resolved under `python-source`, so the root `biliup/` -# package goes in through `include` instead. -include = [{ path = "biliup/**/*.py", format = ["sdist", "wheel"] }] -manifest-path = "crates/stream-gears/Cargo.toml" +python-packages = ["biliup"] [project] name = "biliup" -readme = "README.md" +readme = "../../README.md" +license = { file = "../../LICENSE" } authors = [{ name = "ForgQi" }] description = "stream download and upload" keywords = ["bilibili douyu huya"] diff --git a/crates/stream-gears/tests/test_package.py b/crates/stream-gears/tests/test_package.py index 1ef1adc..8aaf457 100644 --- a/crates/stream-gears/tests/test_package.py +++ b/crates/stream-gears/tests/test_package.py @@ -6,6 +6,8 @@ Run against an installed wheel: ``pytest crates/stream-gears/tests``. import importlib.machinery import importlib.metadata import inspect +import json +import os import subprocess import sys import textwrap @@ -20,6 +22,7 @@ PACKAGE_FILES = { "stream_gears/py.typed", "stream_gears/stream_gears.pyi", } +PYTHON_SOURCE = Path(__file__).resolve().parents[1] def test_top_level_names(): @@ -45,12 +48,45 @@ def test_all_matches_native_module(): } +def is_editable_install(): + direct_url = importlib.metadata.distribution("biliup").read_text("direct_url.json") + return bool(direct_url) and json.loads(direct_url).get("dir_info", {}).get( + "editable", False + ) + + def test_wheel_ships_stubs(): - files = {str(f).replace("\\", "/") for f in importlib.metadata.files("biliup")} - assert PACKAGE_FILES <= files package_dir = Path(stream_gears.__file__).parent assert (package_dir / "py.typed").is_file() assert (package_dir / "stream_gears.pyi").is_file() + # An editable install's RECORD lists the .pth, not the package files. + if not is_editable_install(): + files = {str(f).replace("\\", "/") for f in importlib.metadata.files("biliup")} + assert PACKAGE_FILES <= files + + +def test_biliup_resolves_from_python_source(tmp_path): + """Editable installs put only `python-source` on sys.path, so `biliup` has + to live there next to `stream_gears`.""" + code = ( + "import importlib.util, biliup\n" + "print(biliup.__file__)\n" + "print(importlib.util.find_spec('biliup.__main__').origin)\n" + ) + result = subprocess.run( + [sys.executable, "-c", code], + cwd=tmp_path, + env={**os.environ, "PYTHONPATH": str(PYTHON_SOURCE)}, + capture_output=True, + text=True, + timeout=60, + ) + assert result.returncode == 0, result.stderr + package = PYTHON_SOURCE / "biliup" + assert result.stdout.splitlines() == [ + str(package / "__init__.py"), + str(package / "__main__.py"), + ] def test_upload_text_signature_is_accepted(): diff --git a/docs/content/docs/guide/introduction.md b/docs/content/docs/guide/introduction.md index a8e2926..fc565bc 100644 --- a/docs/content/docs/guide/introduction.md +++ b/docs/content/docs/guide/introduction.md @@ -113,13 +113,13 @@ sudo docker exec -it imageId /bin/bash ## 从源码运行biliup * 下载源码: `git clone https://github.com/ForgQi/bilibiliupload.git` -* 安装: `pip3 install -e .` +* 安装: `pip3 install -e ./crates/stream-gears` * 启动: `python3 -m biliup` * 构建: ```shell $ npm install $ npm run build - $ python3 -m build + $ python3 -m build crates/stream-gears ``` * 调试 webUI: `python3 -m biliup --static-dir public`