Skip to content

Commit

Permalink
Merge pull request #516 from seapagan/migrate-to-uv
Browse files Browse the repository at this point in the history
  • Loading branch information
seapagan authored Oct 7, 2024
2 parents cb07051 + a64e105 commit b030e34
Show file tree
Hide file tree
Showing 21 changed files with 2,412 additions and 2,711 deletions.
16 changes: 3 additions & 13 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
# These are supported funding model platforms

github: [seapagan]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ['https://www.buymeacoffee.com/seapagan']
github: seapagan
buy_me_a_coffee: seapagan
ko_fi: seapagan
11 changes: 0 additions & 11 deletions .github/dependabot.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
],
"labels": [
"dependencies"
],
"gitIgnoredAuthors": [
"66853113+pre-commit-ci[bot]@users.noreply.github.com"
],
"enabled": true,
"enabledManagers": [
"pep621",
"github-actions"
],
"ignoreDeps": []
}
24 changes: 24 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Type Checking

on: [push, pull_request, workflow_dispatch]

jobs:
mypy:
# uncomment the line before to disable this job if needed.
# if: false
name: mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Set up Python
run: uv python install 3.12

- name: Run mypy
run: uv run --all-extras mypy . --strict
69 changes: 21 additions & 48 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: Test Suite

on:
push:
Expand All @@ -8,64 +8,37 @@ on:
workflow_dispatch:

jobs:
test:
uv-example:
name: python
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
# ---------------------------------------------------------------------- #
# checkout repo and setup Python #
# ---------------------------------------------------------------------- #
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# ---------------------------------------------------------------------- #
# install and configure poetry #
# ---------------------------------------------------------------------- #
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
# ---------------------------------------------------------------------- #
# load cached venv if cache exists #
# ---------------------------------------------------------------------- #
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: .venv
key:
venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version
}}-${{ hashFiles('**/poetry.lock') }}
# ---------------------------------------------------------------------- #
# install dependencies if cache does not exist #
# ---------------------------------------------------------------------- #
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

# ---------------------------------------------------------------------- #
# add our project to the PYTHONPATH #
# ---------------------------------------------------------------------- #
# - name: Add project directory to PYTHONPATH
# run: echo "PYTHONPATH=${{ github.workspace }}/py_maker" >> $GITHUB_ENV
- name: Run tests
# For example, using `pytest`
run:
uv run --all-extras -p ${{ matrix.python-version }} pytest tests
--cov-report=xml

# ---------------------------------------------------------------------- #
# run Pytest #
# ---------------------------------------------------------------------- #
- name: Test with pytest
run: |
poetry run pytest --cov-report=xml
- name: Run codacy-coverage-reporter
env:
CODACY_CONFIGURED: ${{ secrets.CODACY_PROJECT_TOKEN }}
if: ${{ env.CODACY_CONFIGURED != ''}}
uses: codacy/codacy-coverage-reporter-action@v1
continue-on-error: true
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: ./coverage.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,4 @@ test-app*
.python-version
.github_changelog_generator
.changelog_generator.toml
.envrc
65 changes: 28 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ci:
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks [dependabot skip]"
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
args: [--unsafe]
Expand All @@ -11,57 +11,48 @@ repos:
- id: check-merge-conflict
- id: end-of-file-fixer

- repo: https://github.com/renovatebot/pre-commit-hooks
rev: 38.110.2
hooks:
- id: renovate-config-validator
files: ^renovate\.json$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
rev: v0.6.9
hooks:
- id: ruff
name: "lint with ruff"
- id: ruff-format

- repo: https://github.com/jackdewinter/pymarkdown
rev: v0.9.21
hooks:
- id: pymarkdown
exclude: .github/|CHANGELOG
args: [-d, "MD046", scan]
name: "format with ruff"

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.11.0"
rev: "v1.11.2" # Use the sha / tag you want to point at
hooks:
- id: mypy
name: "run mypy"
additional_dependencies:
- "types-requests"

- repo: https://github.com/python-poetry/poetry
rev: "1.8.0"
hooks:
- id: poetry-check
# - id: poetry-lock

- repo: https://github.com/python-poetry/poetry-plugin-export
rev: "1.8.0"
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.4.18
hooks:
- id: poetry-export
name: "export production dependencies"
# Update the uv lockfile
- id: uv-lock
- id: uv-export
name: "Export dependencies to 'requirements.txt'"
args:
[
"--without-hashes",
"-f",
"requirements.txt",
"-o",
"requirements.txt",
"--without",
"dev",
"--no-hashes",
"--no-dev",
"--no-emit-project",
"--output-file=requirements.txt",
]
- id: poetry-export
name: "export development dependencies"
- id: uv-export
name: "Export dev dependencies to 'requirements-dev.txt'"
args:
[
"--without-hashes",
"-f",
"requirements.txt",
"-o",
"requirements-dev.txt",
"--with",
"dev",
"--no-hashes",
"--no-emit-project",
"--output-file=requirements-dev.txt",
]
23 changes: 11 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Mac OS X. For Windows, you can use the
[here](https://github.com/pyenv-win/pyenv-win#installation ) for installation
instructions.

We also use [Poetry](https://python-poetry.org/) to manage our dependencies. You
should have this installed as well. You can install Poetry by following the
instructions on the [Poetry
website](https://python-poetry.org/docs/#installation).
From version `0.13.0` and forward, we use [uv](https://docs.astral.sh/uv/) to
manage our dependencies (previously we used `Poetry`), so you should have this
installed as well. You can install `uv` by following the instructions on the [uv
website](https://docs.astral.sh/uv/getting-started/installation/).

## Getting Started

Expand All @@ -59,13 +59,13 @@ To get started, follow these steps:
Run the following command to install the required dependencies:

```console
$ poetry install
$ uv sync
```

You then need to activate the virtual environment:

```console
$ poetry shell
$ source .venv/bin/activate
```

From here you can start working on the project. If you are using an IDE such as
Expand All @@ -74,16 +74,16 @@ the virtual environment that has just been created.

### Using Pip

If you prefer to use `pip` instead of `poetry`, you can install the dependencies
If you prefer to use `pip` instead of `uv`, you can install the dependencies
using the auto-generated `requirements-dev.txt` file:

```console
$ pip install -r requirements-dev.txt
```

However, [Poetry](https://python-poetry.org/){:target="_blank"} is the
recommended (and only supported) way of developing this project and is tightly
integrated with the code and tools.
However, [uv](https://docs.astral.sh/uv/){:target="_blank"} is the recommended
(and only supported) way of developing this project and is tightly integrated
with the code and tools.

## Linting

Expand All @@ -98,8 +98,7 @@ included `.vscode` folder has the settings for this.

Please install this if you are intending to contribute to the project. It will
check commits locally before they are pushed up to the Repo. The GitHub CI runs
the linting checks (and in future probably MyPy as well), and will fail if there
are any errors.
the linting checks (and MyPy), and will fail if there are any errors.

```console
$ pre-commit install
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ developing your Python applications quicker! Includes linting and Pytest
libraries, a task runner, pre-commit hooks, and optionally create a git
repository and upload to GitHub. you can also fully customize the template used.

> [!NOTE]
>
> I have migrated the project (and my own workflow) to use
> [uv](https://docs.astral.sh/uv/) as my dependency management and more, so all
> new projects I create will use that instead of Poetry. For now, I will keep
> the Poetry support as default in this project, but I will probably add a `uv`
> option in the future to create new projects using that instead.
Full documentation for this project with usage examples is available at
<https://py-maker.seapagan.net/>

Expand Down
1 change: 1 addition & 0 deletions docs/hooks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Define hooks for the documentation project."""
52 changes: 52 additions & 0 deletions docs/hooks/google_style_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Hook for MkDocs to support Google-style admonitions."""

import re
from typing import Any


def on_page_markdown(markdown: str, **_: dict[str, Any]) -> str:
"""Hook into the markdown rendering."""

def replace_admonition(match: re.Match[str]) -> str:
"""Actually replace the admonition."""
type_map: dict[str, str] = {
"NOTE": "note",
"TIP": "tip",
"WARNING": "warning",
"IMPORTANT": "info",
"CAUTION": "danger",
}
original_type: str = match.group(1)
admonition_type: str = type_map[
original_type
] # Direct mapping without .lower()
content: str = match.group(2).strip()

# Convert original type to title case
title_case_type: str = original_type.title()

# Remove '>' from the beginning of each line and strip whitespace
content_lines: list[str] = [
line.lstrip(">").strip() for line in content.split("\n")
]

# Remove any empty lines at the start of the content
while content_lines and not content_lines[0]:
content_lines.pop(0)

# Indent each non-empty line
indented_content: str = "\n".join(
f" {line}" if line else "" for line in content_lines
)

return (
f'!!! {admonition_type} "{title_case_type}"\n\n{indented_content}\n'
)

# Use a single regex to match all admonition types and their content
pattern: str = (
r"^> \[!(NOTE|TIP|WARNING|IMPORTANT|CAUTION)\]\n>"
r"([\s\S]*?)(?=\n(?!>)|\Z)"
)

return re.sub(pattern, replace_admonition, markdown, flags=re.MULTILINE)
Loading

0 comments on commit b030e34

Please sign in to comment.