From 851f7e59d98cd75198cb4d3de90276bce14e7be9 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Sun, 1 Sep 2024 21:15:03 -0700 Subject: [PATCH] Support uv, enable trusted publishing (#236) --- .github/workflows/build.yml | 57 ---------------------------- .github/workflows/ci.yml | 75 +++++++++++++++++++++++++++++++++++++ makefile | 21 +++++++---- pyproject.toml | 4 +- 4 files changed, 90 insertions(+), 67 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 3955e0d..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Build -on: - push: - branches: - - main - tags: - - v* - pull_request: - -jobs: - ufmt: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] - os: [macOS-latest, ubuntu-latest, windows-latest] - - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set Up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - cache: pip - cache-dependency-path: pyproject.toml - python-version: ${{ matrix.python-version }} - allow-prereleases: true - - name: Install - run: | - pip install -U pip - pip install -U .[dev] - - name: Test - run: make test - - name: Lint - run: make lint - - # deps: - # runs-on: ${{ matrix.os }} - # strategy: - # fail-fast: false - # matrix: - # python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - # os: [ubuntu-latest] - # steps: - # - name: Checkout - # uses: actions/checkout@v1 - # - name: Set Up Python ${{ matrix.python-version }} - # uses: actions/setup-python@v2 - # with: - # python-version: ${{ matrix.python-version }} - # - name: Install - # run: | - # pip install -U pip - # pip install -Ur requirements-dev.txt - # - name: Deps - # run: make deps diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6743f9a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,75 @@ +name: CI +on: + push: + branches: + - main + tags: + - v* + pull_request: + +permissions: + contents: read + +env: + UV_SYSTEM_PYTHON: 1 + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + os: [macOS-latest, ubuntu-latest, windows-latest] + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set Up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + allow-prereleases: true + - uses: hynek/setup-cached-uv@v2 + with: + cache-dependency-path: pyproject.toml + - name: Install + run: make EXTRAS=dev install + - name: Test + run: make test + - name: Lint + run: make lint + + build: + needs: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - uses: hynek/setup-cached-uv@v2 + with: + cache-dependency-path: pyproject.toml + - name: Install + run: make EXTRAS=dev install + - name: Build + run: python -m build + - name: Upload + uses: actions/upload-artifact@v3 + with: + name: sdist + path: dist + + publish: + needs: build + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v3 + with: + name: sdist + path: dist + - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/makefile b/makefile index a251699..c9ff4c8 100644 --- a/makefile +++ b/makefile @@ -7,19 +7,24 @@ else ACTIVATE:=.venv/bin/activate endif +UV:=$(shell uv --version) +ifdef UV + VENV:=uv venv + PIP:=uv pip +else + VENV:=python -m venv + PIP:=python -m pip +endif + .venv: - python -m venv .venv - source $(ACTIVATE) && make install - echo 'run `source $(ACTIVATE)` to use virtualenv' + $(VENV) .venv venv: .venv + source $(ACTIVATE) && make install + echo 'run `source $(ACTIVATE)` to use virtualenv' install: - python -m pip install -U pip - python -m pip install -Ue .[$(EXTRAS)] - -release: lint test clean - flit publish + $(PIP) install -Ue .[$(EXTRAS)] format: python -m ufmt format $(SRCS) diff --git a/pyproject.toml b/pyproject.toml index 0719154..3f37360 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,8 +39,8 @@ ruff = [ dev = [ "attribution==1.8.0", "black==24.8.0", - "coverage==7.6.1", - "flit==3.9.0", + "build>=1.2", + "coverage>=7", "flake8==7.1.1", "mypy==1.11.2", "pygls==1.3.1",