Skip to content

Commit

Permalink
🏗️ refactor by cookiecutter-uv
Browse files Browse the repository at this point in the history
  • Loading branch information
zrquan committed Oct 15, 2024
1 parent c69ae1b commit 151ede6
Show file tree
Hide file tree
Showing 29 changed files with 2,112 additions and 717 deletions.
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "nmass",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.9-bullseye",
"features": {},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": ["ms-python.python", "editorconfig.editorconfig"],
"settings": {
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.defaultInterpreterPath": "/workspaces/nmass/.venv/bin/python",
"python.testing.pytestPath": "/workspaces/nmass/.venv/bin/pytest"
}
}
}
}
11 changes: 11 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env bash

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.cargo/env

# Install Dependencies
uv sync

# Install pre-commit hooks
uv run pre-commit install --install-hooks
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
max_line_length = 120

[*.json]
indent_style = space
indent_size = 4
30 changes: 30 additions & 0 deletions .github/actions/setup-python-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Setup Python Environment"
description: "Set up Python environment for the given Python version"

inputs:
python-version:
description: "Python version to use"
required: true
default: "3.9"
uv-version:
description: "uv version to use"
required: true
default: "0.4.6"

runs:
using: "composite"
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: ${{ inputs.uv-version }}
enable-cache: "true"
cache-suffix: ${{ matrix.python-version }}

- name: Install Python dependencies
run: uv sync --frozen
shell: bash
66 changes: 66 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Main

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up the environment
uses: ./.github/actions/setup-python-env

- name: Run checks
run: make check

tests-and-type-check:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
fail-fast: false
defaults:
run:
shell: bash
steps:
- name: Check out
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-python-env
with:
python-version: ${{ matrix.python-version }}

- name: Run tests
run: uv run python -m pytest tests --cov --cov-config=pyproject.toml --cov-report=xml

- name: Check typing
run: uv run mypy

- name: Upload coverage reports to Codecov with GitHub Action on Python 3.9
uses: codecov/codecov-action@v4
if: ${{ matrix.python-version == '3.9' }}

check-docs:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-python-env

- name: Check if documentation can be built
run: uv run mkdocs build -s
67 changes: 67 additions & 0 deletions .github/workflows/on-release-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: release-main

on:
release:
types: [published]
branches: [main]

jobs:
set-version:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Export tag
id: vars
run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
if: ${{ github.event_name == 'release' }}

- name: Update project version
run: |
sed -i "s/^version = \".*\"/version = \"$RELEASE_VERSION\"/" pyproject.toml
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
if: ${{ github.event_name == 'release' }}

- name: Upload updated pyproject.toml
uses: actions/upload-artifact@v4
with:
name: pyproject-toml
path: pyproject.toml

publish:
runs-on: ubuntu-latest
needs: [set-version]
steps:
- name: Check out
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-python-env

- name: Download updated pyproject.toml
uses: actions/download-artifact@v4
with:
name: pyproject-toml

- name: Build package
run: uvx --from build pyproject-build --installer uv

- name: Publish package
run: uvx twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

deploy-docs:
needs: publish
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-python-env

- name: Deploy documentation
run: uv run mkdocs gh-deploy --force
37 changes: 0 additions & 37 deletions .github/workflows/pypi-publish.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/validate-codecov-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: validate-codecov-config

on:
pull_request:
paths: [codecov.yaml]
push:
branches: [main]

jobs:
validate-codecov-config:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Validate codecov configuration
run: curl -sSL --fail-with-body --data-binary @codecov.yaml https://codecov.io/validate
Loading

0 comments on commit 151ede6

Please sign in to comment.