Skip to content

Commit

Permalink
Switch to uv (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin authored Jan 7, 2025
1 parent 875344d commit de0b1c6
Show file tree
Hide file tree
Showing 10 changed files with 1,605 additions and 135 deletions.
116 changes: 55 additions & 61 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ on:
- '**'
pull_request: {}

env:
CI: true
COLUMNS: 120
UV_PYTHON: 3.12
UV_FROZEN: '1'

jobs:
server-lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '18.x'

Expand All @@ -27,89 +33,83 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v5
with:
python-version: '3.11'

- name: install
run: |
pip install -U pip
pip install -r requirements/cli.txt
enable-cache: true

- run: make lint
working-directory: cli
- run: make mypy
- run: uv sync
working-directory: cli

- uses: pre-commit/action@v3.0.0
with:
extra_args: --all-files --verbose
env:
SKIP: lint-js

cli-test:
name: cli-test-${{ matrix.os }}-py${{ matrix.python-version }}
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos]
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

runs-on: ${{ matrix.os }}-latest
env:
UV_PYTHON: ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

- name: install
run: |
pip install -U pip
pip install -r requirements/cli.txt
- run: pip freeze
enable-cache: true

- name: test
working-directory: cli
run: make test
- run: mkdir coverage

- name: rename coverage
- run: uv run coverage run -m pytest
working-directory: cli
run: |
mkdir coverage
mv .coverage coverage/.coverage.${{ matrix.os }}-py${{ matrix.python-version }}
env:
COVERAGE_FILE: ../coverage/.coverage.${{ matrix.os }}-py${{ matrix.python-version }}

- name: store coverage files
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage
path: cli/coverage
name: coverage-${{ matrix.os }}-py${{ matrix.python-version }}
path: coverage
include-hidden-files: true

cli-coverage-check:
# dogfooding! use smokeshow to view our coverage report
needs: [cli-test]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v5
with:
python-version: '3.11'
enable-cache: true

- name: get coverage files
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: coverage
merge-multiple: true
path: cli

- run: pip install coverage smokeshow
- run: uv sync
working-directory: cli

- name: build coverage
working-directory: cli
run: |
coverage combine
coverage html -i
uv run coverage combine
uv run coverage html -i
working-directory: cli

- run: smokeshow upload cli/htmlcov
- run: uv run -m smokeshow upload htmlcov
working-directory: cli
env:
SMOKESHOW_GITHUB_STATUS_DESCRIPTION: CLI Coverage {coverage-percentage}
SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 90
Expand All @@ -122,7 +122,7 @@ jobs:
environment: cloudflare-staging-deploy

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: cloudflare/wrangler-action@v3
with:
Expand Down Expand Up @@ -153,7 +153,7 @@ jobs:
environment: cloudflare-production-deploy

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: cloudflare/wrangler-action@v3
with:
Expand All @@ -176,27 +176,21 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v5
with:
python-version: '3.11'
enable-cache: true

- name: install
run: pip install -U build

- name: check version
id: check-version
uses: samuelcolvin/check-python-version@v4
- name: check GITHUB_REF matches package version
uses: samuelcolvin/check-python-version@v4.1
with:
version_file_path: 'cli/smokeshow/version.py'
version_file_path: 'cli/pyproject.toml'

- name: build
working-directory: cli
run: python -m build
- run: uv build

- name: Upload package to PyPI
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
packages-dir: cli/dist/
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ repos:
types: [javascript]
language: system
pass_filenames: false
- id: format-python
name: Format Python
entry: make -C cli lint
types: [python]
language: system
pass_filenames: false
- id: lint-python
name: Lint Python
entry: make -C cli lint
types: [python]
language: system
pass_filenames: false
- id: mypy
name: Mypy
entry: make -C cli mypy
- id: typecheck
name: Typecheck Python
entry: make -C cli typecheck
types: [python]
language: system
pass_filenames: false
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

.PHONY: install
install:
pip install -U pip pip-tools pre-commit
pip install -U -r requirements/cli.txt
make -C cli install
pre-commit install

.PHONY: format-js
Expand Down
5 changes: 2 additions & 3 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/env/
/env37/
/.venv/
/build/
/htmlcov/
*.lock
*.py[cod]
*.egg-info/
.cache/
.mypy_cache/
/upload.sh
.python-version
53 changes: 24 additions & 29 deletions cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,45 @@
.DEFAULT_GOAL := all
sources = smokeshow tests

.PHONY: .uv
.uv:
@uv --version || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'

.PHONY: .pre-commit
.pre-commit:
@pre-commit -V || echo 'Please install pre-commit: https://pre-commit.com/'

.PHONY: install
install: .uv .pre-commit
uv sync --frozen

.PHONY: format
format:
ruff --fix-only $(sources)
black $(sources)
uv run ruff format
uv run ruff check --fix --fix-only

.PHONY: lint
lint:
ruff $(sources)
black $(sources) --check --diff
uv run ruff format --check
uv run ruff check

.PHONY: mypy
mypy:
mypy --version
mypy smokeshow
.PHONY: typecheck
typecheck:
uv run pyright --version
uv run pyright smokeshow

.PHONY: test
test:
coverage run -m pytest
uv run coverage run -m pytest

.PHONY: test-live
test-live:
pytest tests/test_live.py --cf-auth-client --cf-wrangler-dir ..
uv run pytest tests/test_live.py --cf-auth-client --cf-wrangler-dir ..

.PHONY: testcov
testcov: test
@echo "building coverage html"
@coverage html
@uv run coverage html

.PHONY: all
all: lint mypy testcov

.PHONY: clean
clean:
rm -rf `find . -name __pycache__`
rm -f `find . -type f -name '*.py[co]' `
rm -f `find . -type f -name '*~' `
rm -f `find . -type f -name '.*~' `
rm -rf .cache
rm -rf .pytest_cache
rm -rf .mypy_cache
rm -rf htmlcov
rm -rf *.egg-info
rm -f .coverage
rm -f .coverage.*
rm -rf build
rm -rf dist
rm -rf site
all: lint typecheck testcov
Loading

0 comments on commit de0b1c6

Please sign in to comment.