Skip to content

Commit 85abf2e

Browse files
committed
refactor: Add Astral/Uv Python project/package manager
Replace setup tools and configure to unified Uv with pyproject based setup. Set minimum default python to 3.9 as python 3.8 is EOL. Project file pyproject.toml now replaced all linters for a unified solution using ruff and mypy and integrated pytest configurations. Signed-off-by: Helio Chissini de Castro <[email protected]>
1 parent 31990dd commit 85abf2e

12 files changed

+2459
-683
lines changed

.github/workflows/docs-ci.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ jobs:
1515
- name: Checkout code
1616
uses: actions/checkout@v3
1717

18-
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v4
18+
- name: Setup uv
19+
uses: astral-sh/setup-uv@22695119d769bdb6f7032ad67b9bca0ef8c4a174 # v5.4.0
2020
with:
21-
python-version: ${{ matrix.python-version }}
22-
23-
- name: Give permission to run scripts
24-
run: chmod +x ./docs/scripts/doc8_style_check.sh
21+
enable-cache: true
22+
pyproject-file: "pyproject.toml"
2523

2624
- name: Install Dependencies
2725
run: pip install -e .[docs]

.github/workflows/pypi-release.yml

+43-51
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,75 @@
1-
name: Create library release archives, create a GH release and publish PyPI wheel and sdist on tag in main branch
2-
3-
4-
# This is executed automatically on a tag in the main branch
5-
6-
# Summary of the steps:
7-
# - build wheels and sdist
8-
# - upload wheels and sdist to PyPI
9-
# - create gh-release and upload wheels and dists there
10-
# TODO: smoke test wheels and sdist
11-
# TODO: add changelog to release text body
12-
13-
# WARNING: this is designed only for packages building as pure Python wheels
1+
name: Build and Publish
142

153
on:
164
workflow_dispatch:
5+
pull_request:
176
push:
187
tags:
19-
- "v*.*.*"
8+
- "v*"
209

2110
jobs:
22-
build-pypi-distribs:
23-
name: Build and publish library to PyPI
24-
runs-on: ubuntu-20.04
11+
build_and_upload:
12+
name: Build and Upload Archive
13+
runs-on: ubuntu-24.04
2514

2615
steps:
2716
- uses: actions/checkout@v4
28-
- name: Set up Python
29-
uses: actions/setup-python@v4
30-
with:
31-
python-version: 3.9
32-
33-
- name: Install pypa/build
34-
run: python -m pip install build --user
3517

36-
- name: Build a binary wheel and a source tarball
37-
run: python -m build --sdist --wheel --outdir dist/
38-
39-
- name: Upload built archives
40-
uses: actions/upload-artifact@v4
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@22695119d769bdb6f7032ad67b9bca0ef8c4a174 # v5.4.0
20+
with:
21+
enable-cache: true
22+
pyproject-file: "pyproject.toml"
23+
24+
- name: Build 📦 package
25+
run: |
26+
uv sync
27+
uv build
28+
shell: bash
29+
30+
- name: Upload artifacts
31+
if: github.event_name == 'push'
32+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
4133
with:
4234
name: pypi_archives
43-
path: dist/*
44-
35+
path: dist/python_inspector-*-py3-none-any.whl
36+
overwrite: true
4537

4638
create-gh-release:
4739
name: Create GH release
48-
needs:
49-
- build-pypi-distribs
50-
runs-on: ubuntu-20.04
40+
runs-on: ubuntu-24.04
41+
needs: build_and_upload
5142

5243
steps:
5344
- name: Download built archives
54-
uses: actions/download-artifact@v4
45+
if: github.event_name == 'push'
46+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # 4.2.1
5547
with:
5648
name: pypi_archives
5749
path: dist
5850

5951
- name: Create GH release
60-
uses: softprops/action-gh-release@v1
52+
if: github.event_name == 'push'
53+
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # 2.2.1
6154
with:
6255
draft: true
6356
files: dist/*
6457

65-
6658
create-pypi-release:
6759
name: Create PyPI release
68-
needs:
69-
- create-gh-release
70-
runs-on: ubuntu-20.04
71-
60+
needs: create-gh-release
61+
runs-on: ubuntu-24.04
7262
steps:
73-
- name: Download built archives
74-
uses: actions/download-artifact@v4
75-
with:
76-
name: pypi_archives
77-
path: dist
78-
79-
- name: Publish to PyPI
80-
if: startsWith(github.ref, 'refs/tags')
81-
uses: pypa/gh-action-pypi-publish@release/v1
63+
- name: Install uv
64+
if: github.event_name == 'push'
65+
uses: astral-sh/setup-uv@22695119d769bdb6f7032ad67b9bca0ef8c4a174 # v5.4.0
8266
with:
83-
password: ${{ secrets.PYPI_API_TOKEN }}
67+
enable-cache: true
68+
pyproject-file: "pyproject.toml"
69+
70+
- name: Publish
71+
if: github.event_name == 'push'
72+
env:
73+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
74+
run: |
75+
uv publish dist/*

.pre-commit-config.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
default_language_version:
2+
python: python3.9
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v5.0.0
6+
hooks:
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
10+
- repo: https://github.com/pre-commit/mirrors-mypy
11+
rev: v1.15.0
12+
hooks:
13+
- id: mypy
14+
additional_dependencies:
15+
- pydantic
16+
- types-PyYaml==6.0.12.12
17+
- types-toml
18+
- types-requests
19+
args: [--config, pyproject.toml]
20+
21+
- repo: https://github.com/astral-sh/ruff-pre-commit
22+
rev: "v0.11.2"
23+
hooks:
24+
- id: ruff
25+
26+
- repo: https://github.com/astral-sh/uv-pre-commit
27+
# uv version.
28+
rev: 0.6.10
29+
hooks:
30+
- id: uv-lock

README.rst

+55-4
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,66 @@ The goal of python-inspector is to be a comprehensive library
2828
that can handle every style of Python package layouts, manifests and lockfiles.
2929

3030

31+
Developing
32+
----------
33+
34+
- `Install Astral Uv <https://docs.astral.sh/uv/getting-started/installation/>`_. For convenience:
35+
36+
- Regular: ``pip install uv``
37+
- Isolated ( if you have pipx installed): ``pipx install uv``
38+
39+
- (Optional) Configure pre-commit for commit linter checks:
40+
41+
.. code-block:: bash
42+
pre-commit install
43+
pre-commit install --hook-type commit-msg
44+
45+
46+
- Run from development tree. A virtual .venv will be created if you not have one
47+
48+
- You can run using uv direct
49+
.. code-block:: bash
50+
uv run python-inspector --help
51+
52+
- Or if you have a virtual env activated do:
53+
.. code-block:: bash
54+
uv sync # One single time
55+
python-inspector --help
56+
57+
3158
Testing
3259
--------
3360

34-
- Run the tests with::
61+
- Run the tests. Tests have a special dependency group with their requirements for text exclusively:
62+
63+
.. code-block:: bash
64+
uv sync --group=test
65+
66+
If you want to use Uv ( which enable possibility to use multiple python versions)
67+
68+
.. code-block:: bash
69+
uv run -p 3.9 pytest -vvs
70+
71+
Or if you have a virtualenv activated with the deps installed
72+
73+
.. code-block:: bash
74+
uv run -p 3.9 pytest -vvs
75+
76+
- These are live tests to regenerate the tests with updated data run::
77+
78+
.. code-block:: bash
79+
uv sync
80+
PYINSP_REGEN_TEST_FIXTURES=yes uv run pytest -vvs
81+
82+
83+
Documentation
84+
-------------
3585

36-
pytest -vvs
86+
.. code-block:: bash
87+
uv sync --all-groups
88+
hatch run validate-docs
3789
38-
- These are live tests to regenrate the tests with updated data run::
3990
40-
PYINSP_REGEN_TEST_FIXTURES=yes pytest -vvs
4191
4292
Usage
4393
--------
@@ -86,6 +136,7 @@ This project is funded, supported and sponsored by:
86136
- Google, including the Google Summer of Code and the Google Seasons of Doc programmes
87137
- Mercedes-Benz Group
88138
- Microsoft and Microsoft Azure
139+
- Cariad SE
89140
- AboutCode ASBL
90141
- nexB Inc.
91142

0 commit comments

Comments
 (0)