Pārlūkot izejas kodu

PyPI publishing (#120)

PyPI publishing and CI through github actions with `uv build`
Johan Edstedt 7 mēneši atpakaļ
vecāks
revīzija
3d3b2ce27a

+ 25 - 0
.github/actions/uv-build/action.yml

@@ -0,0 +1,25 @@
+name: uv-build
+description: Build the project with uv and run smoke tests
+inputs:
+  python-version:
+    description: Python version to install
+    required: true
+runs:
+  using: composite
+  steps:
+    - name: Install uv
+      uses: astral-sh/setup-uv@v6
+    - name: Install Python
+      shell: bash
+      run: uv python install ${{ inputs.python-version }}
+    - name: Build
+      shell: bash
+      run: uv build
+    - name: Smoke test (wheel)
+      shell: bash
+      run: uv run --isolated --no-project --with dist/*.whl tests/smoke_test.py
+    - name: Smoke test (source distribution)
+      shell: bash
+      run: uv run --isolated --no-project --with dist/*.tar.gz tests/smoke_test.py
+
+

+ 22 - 0
.github/workflows/build.yml

@@ -0,0 +1,22 @@
+name: Build
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    branches:
+      - main
+jobs:
+  run:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v5
+      - name: Build and smoke test
+        uses: ./.github/actions/uv-build
+        with:
+          python-version: ${{ matrix.python-version }}

+ 39 - 0
.github/workflows/publish.yml

@@ -0,0 +1,39 @@
+name: PyPI Publish
+
+on:
+  push:
+    tags:
+      # Publish on any tag starting with a `v`, e.g., v0.1.0
+      - v*
+  workflow_dispatch:
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v5
+      - name: Build and smoke test
+        uses: ./.github/actions/uv-build
+        with:
+          python-version: ${{ matrix.python-version }}
+
+  publish:
+    runs-on: ubuntu-latest
+    needs: build
+    environment:
+      name: pypi
+    permissions:
+      id-token: write
+      contents: read
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v5
+      - name: Build and smoke test
+        uses: ./.github/actions/uv-build
+        with:
+          python-version: '3.12'
+      - name: Publish
+        run: uv publish

+ 12 - 0
tests/smoke_test.py

@@ -0,0 +1,12 @@
+def test_smoke():
+    import torch
+    from romatch import roma_outdoor
+    device = torch.device('cpu')
+    model = roma_outdoor(device=device)
+    assert model._get_device() == device
+    assert model.w_resized == 560, f"Expected 560, got {model.w_resized}"
+    assert model.h_resized == 560, f"Expected 560, got {model.h_resized}"
+    assert model.upsample_res == (864, 864), f"Expected (864, 864), got {model.upsample_res}"
+
+if __name__ == "__main__":
+    test_smoke()