Skip to content

Commit 1bbd9e5

Browse files
committed
Adopt src/ layout and revamp CI/CD
Migrate all source code from `lighter/` to `src/lighter/` to align with modern Python packaging standards. Overhaul GitHub Actions by replacing `ci.yml` with dedicated workflows for: - `tests.yml`: Run unit and integration tests. - `code_quality.yml`: Enforce linting and formatting. - `publish.yml`: Handle package publishing. - `check_pull_request_title.yml`: Ensure PR title compliance. Transition from `Makefile` to `justfile` for task automation. Add `tox.ini` for multi-environment testing. Update `pyproject.toml`, `.pre-commit-config.yaml`, and documentation (`CONTRIBUTING.md`, `README.md`, `docs/gen_ref_pages.py`) to reflect these changes. Update `uv.lock` for dependency consistency.
1 parent 78a39f5 commit 1bbd9e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1385
-341
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: "Check PR title"
2+
on:
3+
pull_request:
4+
types: [edited, opened, synchronize, reopened]
5+
6+
jobs:
7+
pr-title-check:
8+
runs-on: ubuntu-latest
9+
if: ${{ github.event.pull_request.user.login != 'allcontributors[bot]' }}
10+
steps:
11+
# Echo the user's login
12+
- name: Echo user login
13+
run: echo ${{ github.event.pull_request.user.login }}
14+
15+
- uses: naveenk1223/action-pr-title@master
16+
with:
17+
# ^ Start of string
18+
# [A-Z] First character must be an uppercase ASCII letter
19+
# [a-zA-Z]* Followed by zero or more ASCII letters
20+
# (?<![^s]s) Negative lookbehind: disallow a single 's' at the end of the first word
21+
# ( .+)+ At least one space and one or more characters (requires more words)
22+
# [^.] Final character must not be a period
23+
# $ End of string
24+
regex: "^[A-Z][a-zA-Z]*(?<![^s]s)( .+)+[^.]$"
25+
# Valid titles:
26+
# - "Do something"
27+
# - "Address something"
28+
# Invalid title:
29+
# - "do something"
30+
# - "Do something."
31+
# - "Does something"
32+
# - "Do"
33+
# - "Addresses something"
34+
min_length: 10
35+
max_length: 72

.github/workflows/ci.yml

Lines changed: 0 additions & 71 deletions
This file was deleted.

.github/workflows/code_quality.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Code quality
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
schedule:
10+
- cron: "0 4 * * *"
11+
12+
env:
13+
FORCE_COLOR: 1
14+
15+
jobs:
16+
check:
17+
name: tox env ${{ matrix.tox_env }}
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
tox_env:
23+
- format
24+
- lint
25+
- types
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Install the latest version of uv
34+
uses: astral-sh/setup-uv@v6
35+
36+
- name: Run check for tox env "${{ matrix.tox_env }}"
37+
run: uvx --with tox-uv -- tox -e ${{ matrix.tox_env }}

.github/workflows/docs-publish.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ jobs:
1414
run: |
1515
git config user.name github-actions[bot]
1616
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
17-
- uses: actions/setup-python@v5
18-
with:
19-
python-version: 3.x
20-
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
21-
- uses: actions/cache@v4
22-
with:
23-
key: mkdocs-material-${{ env.cache_id }}
24-
path: .cache
25-
restore-keys: |
26-
mkdocs-material-
27-
- run: pip install mkdocs-material mkdocs-autorefs mkdocstrings mkdocs-gen-files mkdocs-literate-nav mkdocs-section-index mkdocstrings-python
28-
- run: mkdocs gh-deploy --force
17+
- name: Install the latest version of uv
18+
uses: astral-sh/setup-uv@v6
19+
20+
- name: Install dependencies
21+
run: uv sync --only-group docs
22+
23+
- name: Deploy docs
24+
run: uv run --only-group docs mkdocs gh-deploy --force

.github/workflows/publish.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*" # Push events to matching v*, i.e. v1.0.0, v0.1.0
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
name: Build the package
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v6
21+
22+
- name: Build a binary wheel and a source tarball
23+
run: uv build
24+
25+
- name: Upload dist directory
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: dist
29+
path: dist
30+
31+
publish:
32+
name: Publish the package
33+
needs: build
34+
runs-on: ubuntu-latest
35+
permissions:
36+
id-token: write
37+
38+
steps:
39+
- name: Print ref
40+
run: echo ${{ github.ref }}
41+
42+
- name: Download all workflow run artifacts
43+
uses: actions/download-artifact@v4
44+
with:
45+
name: dist
46+
path: dist
47+
48+
- name: Publish package to TestPyPI
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
with:
51+
repository-url: https://test.pypi.org/legacy/
52+
skip-existing: true
53+
54+
- name: Install uv if commit is tagged
55+
if: startsWith(github.ref, 'refs/tags')
56+
uses: astral-sh/setup-uv@v6
57+
58+
- name: Publish package to PyPI if commit is tagged
59+
# Publish only tagged commits
60+
if: startsWith(github.ref, 'refs/tags')
61+
run: uv publish --verbose

.github/workflows/tests.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
schedule:
10+
- cron: "0 4 * * *"
11+
12+
env:
13+
FORCE_COLOR: 1
14+
15+
jobs:
16+
pytest:
17+
name: Unit tests
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest]
21+
python: ["3.10", "3.11", "3.12"]
22+
fail-fast: false
23+
24+
runs-on: ${{ matrix.os }}
25+
env:
26+
OS: ${{ matrix.os }}
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Install the latest version of uv
35+
uses: astral-sh/setup-uv@v6
36+
37+
- name: Setup test suite
38+
run: tox run -v --notest --skip-missing-interpreters false -e ${{ matrix.python }}
39+
40+
# Run all tests on schedule, but only non-slow tests on push
41+
- name: Run pytest
42+
run: |
43+
if [ "${{ github.event_name }}" == "schedule" ]; then
44+
tox -e pytest
45+
else
46+
tox -e pytest -- -m "not slow"
47+
fi
48+
shell: bash # this wouldn't work on Powershell
49+
50+
- name: Upload coverage reports to Codecov
51+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python == '3.12' }}
52+
uses: codecov/[email protected]
53+
env:
54+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.pre-commit-config.yaml

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
1-
default_stages: [commit, push]
2-
31
repos:
42
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v2.5.0
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-ast # Simply check whether the files parse as valid python
6+
- id: check-case-conflict # Check for files that would conflict in case-insensitive filesystems
7+
- id: check-merge-conflict # Check for files that contain merge conflict strings
8+
- id: check-toml # Attempts to load all TOML files to verify syntax
9+
- id: check-yaml # Attempts to load all YAML files to verify syntax
10+
- id: check-vcs-permalinks # Ensures that links to VCS websites are permalinks
11+
- id: debug-statements # Check for debugger imports and py37+ `breakpoint()` calls in python source
12+
- id: detect-private-key # Detects the presence of private keys
13+
- id: end-of-file-fixer # Ensures that a file is either empty, or ends with one newline
14+
- id: mixed-line-ending # Replaces or checks mixed line ending
15+
- id: trailing-whitespace # Trims trailing whitespace
16+
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.11.7
619
hooks:
7-
- id: check-yaml
8-
- id: end-of-file-fixer
9-
exclude: LICENSE
10-
- id: trailing-whitespace
20+
- id: ruff
21+
- id: ruff-format
1122

12-
- repo: local
23+
- repo: https://github.com/pre-commit/pygrep-hooks
24+
rev: v1.10.0
1325
hooks:
14-
- id: isort
15-
name: isort
16-
entry: uvx run isort --settings-path pyproject.toml
17-
types: [python]
18-
language: system
26+
- id: python-check-blanket-noqa # enforce that noqa annotations always occur with specific codes
27+
- id: python-check-blanket-type-ignore # enforce that # type: ignore annotations always occur with specific codes
28+
- id: python-no-log-warn # check for the deprecated .warn() method of python loggers
29+
- id: python-use-type-annotations # enforce that type annotations are used instead of type comments
30+
- id: rst-backticks # detect common mistake of using single backticks when writing rst
31+
- id: rst-directive-colons # detect mistake of rst directive not ending with double colon
32+
- id: rst-inline-touching-normal # detect mistake of inline code touching normal text in rst
1933

20-
- repo: local
34+
- repo: https://github.com/asottile/pyupgrade
35+
rev: v3.19.1
2136
hooks:
22-
- id: black
23-
name: black
24-
entry: uvx run black --config pyproject.toml
25-
types: [python]
26-
language: system
37+
- id: pyupgrade
38+
args: ['--py39-plus']
39+
40+
ci:
41+
autoupdate_commit_msg: Autoupdate pre-commit hooks
42+
autoupdate_schedule: quarterly

0 commit comments

Comments
 (0)