Skip to content

Commit 2fedc38

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 2fedc38

File tree

13 files changed

+2558
-866
lines changed

13 files changed

+2558
-866
lines changed

.github/workflows/docs-ci.yml

Lines changed: 4 additions & 6 deletions
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

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,73 @@
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: Buld 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+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # 4.2.1
5546
with:
5647
name: pypi_archives
5748
path: dist
5849

5950
- name: Create GH release
60-
uses: softprops/action-gh-release@v1
51+
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # 2.2.1
6152
with:
6253
draft: true
6354
files: dist/*
6455

65-
6656
create-pypi-release:
6757
name: Create PyPI release
68-
needs:
69-
- create-gh-release
70-
runs-on: ubuntu-20.04
71-
58+
needs: create-gh-release
59+
runs-on: ubuntu-24.04
7260
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
61+
- name: Install uv
62+
if: github.event_name == 'push'
63+
uses: astral-sh/setup-uv@22695119d769bdb6f7032ad67b9bca0ef8c4a174 # v5.4.0
8264
with:
83-
password: ${{ secrets.PYPI_API_TOKEN }}
65+
enable-cache: true
66+
pyproject-file: "pyproject.toml"
67+
68+
- name: Publish
69+
if: github.event_name == 'push'
70+
env:
71+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
72+
run: |
73+
uv publish dist/*

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
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.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
python-inspector - inspect Python packages dependencies and metadata
2+
=====================================================================
3+
4+
Copyright (c) nexB Inc. and others.
5+
SPDX-License-Identifier: Apache-2.0
6+
Homepage: https://github.com/aboutcode-org/python-inspector and https://www.aboutcode.org/
7+
8+
``python-inspector`` is a collection of utilities to:
9+
10+
- resolve PyPI packages dependencies
11+
12+
- parse various requirements.txt files and setup.py files as input
13+
for resolving dependencies.
14+
15+
- parse additionally various manifests and packages files such as
16+
Pipfile, pyproject.toml, poetry.lock and setup.cfg and legacy and
17+
current metadata file formats for eggs, wheels and sdist. These
18+
have not been wired with the command line yet.
19+
20+
- query PyPI JSON and simple APIs for package information
21+
22+
It grew out of ScanCode toolkit to find and analyze PyPI archives and
23+
installed Python packages and their files.
24+
25+
The goal of python-inspector is to be a comprehensive library
26+
that can handle every style of Python package layouts, manifests and lockfiles.
27+
28+
Developing
29+
----------
30+
31+
- [Install Astral Uv](https://docs.astral.sh/uv/getting-started/installation/). For convenience:
32+
33+
- Isolated: `pipx install uv`
34+
- Regular: `pip install uv`
35+
36+
- (Optional) Configure pre-commit for commit linter checks:
37+
38+
```bash
39+
pre-commit install
40+
pre-commit install --hook-type commit-msg
41+
```
42+
43+
- Run from development. A virtual .venv will be created if you not have one
44+
45+
```bash
46+
uv run python-inspector --help
47+
```
48+
49+
Testing
50+
--------
51+
52+
- Run the tests. Tests have a special dependency group with their requirements for text exclusively:
53+
54+
```bash
55+
uv sync --group=test
56+
uv pytest -vvs
57+
```
58+
59+
- These are live tests to regenrate the tests with updated data run::
60+
61+
```bash
62+
uv sync
63+
PYINSP_REGEN_TEST_FIXTURES=yes uv run pytest -vvs
64+
```
65+
66+
Documentation
67+
-------------
68+
69+
```bash
70+
uv sync --all-groups
71+
hatch run validate-docs
72+
```
73+
74+
Usage
75+
--------
76+
77+
- Install with pip:
78+
79+
```bash
80+
pip install git+https://github.com/aboutcode-org/python-inspector
81+
```
82+
83+
- Run the command line utility with::
84+
85+
```bash
86+
python-inspector --help
87+
```
88+
89+
Its companion libraries are:
90+
91+
- ``pip-requirements-parser``, a mostly correct pip requirements parsing
92+
library extracted from pip.
93+
94+
- ``pkginfo2``, a safer fork of pkginfo to parse various installed and extracted
95+
package layouts and their metadata files.
96+
97+
- ``dparse2``, a safer fork of dparse to parse various package manifests
98+
99+
- ``resolvelib``, the library used by pip for dependency resolution
100+
101+
- ``packaging``, the official Python packaging utility library to process
102+
versions, specifiers, markers and other packaging data formats.
103+
104+
- ``importlib_metadata``, the official Python utility library to process
105+
installed site-packages and their metadata formats.
106+
107+
- ``packageurl-python`` to use Package URL to reference Python packages
108+
109+
Acknowledgements, Funding, Support and Sponsoring
110+
--------------------------------------------------------
111+
112+
This project is funded, supported and sponsored by:
113+
114+
- Generous support and contributions from users like you!
115+
- the European Commission NGI programme
116+
- the NLnet Foundation
117+
- the Swiss State Secretariat for Education, Research and Innovation (SERI)
118+
- Google, including the Google Summer of Code and the Google Seasons of Doc programmes
119+
- Mercedes-Benz Group
120+
- Microsoft and Microsoft Azure
121+
- AboutCode ASBL
122+
- nexB Inc.
123+
- Cariad SE
124+
125+
<p align="left">
126+
<a href="http://ec.europa.eu/index_en.htm" target="_blank"><img src="https://ngi.eu/wp-content/uploads/sites/77/2017/10/bandiera_stelle.png" height="40" alt="Europa logo"></a>
127+
&nbsp;&nbsp;&nbsp;
128+
<a href="https://commission.europa.eu/about-european-commission/departments-and-executive-agencies/communications-networks-content-and-technology_en" target="_blank"><img src="https://commission.europa.eu/themes/contrib/oe_theme/dist/ec/images/logo/positive/logo-ec--en.svg" height="40" alt="EC DG Connect logo"></a>
129+
</p>
130+
131+
<p align="left">
132+
<a href="https://ngi.eu35" target="_blank"><img src="https://ngi.eu/wp-content/uploads/thegem-logos/logo_8269bc6efcf731d34b6385775d76511d_1x.png" height="50" alt="NGI logo"></a>
133+
&nbsp;&nbsp;&nbsp;
134+
<a href="https://nlnet.nl" target="_blank"><img src="https://nlnet.nl/logo/banner.png" height="50" alt="NLnet foundation logo"></a>
135+
</p>
136+
137+
<p align="left">
138+
<a href="https://aboutcode.org/" target="_blank"><img src="https://aboutcode.org/wp-content/uploads/2023/10/AboutCode.svg" height="30" alt="AboutCode logo"></a>
139+
&nbsp;&nbsp;&nbsp;
140+
<a href="https://nexb.com" target="_blank"><img src="https://nexb.com/wp-content/uploads/2022/04/nexB.svg" height="30" alt="nexB logo"></a>
141+
</p>
142+
143+
This project was funded through the NGI0 Discovery Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet programme, under the aegis of DG Communications Networks, Content and Technology under grant agreement No 825322.
144+
145+
<p align="left">
146+
<a href="https://nlnet.nl/project/vulnerabilitydatabase/" target="_blank"><img src="https://nlnet.nl/image/logos/NGI0Discovery_tag.svg" height="40" alt="NGI Discovery logo"></a>
147+
</p>
148+
149+
This project was funded through the NGI0 Core Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet programme, under the aegis of DG Communications Networks, Content and Technology under grant agreement No 101092990.
150+
151+
<p align="left">
152+
<a href="https://nlnet.nl/project/Back2source-next/" target="_blank"><img src="https://nlnet.nl/image/logos/NGI0_tag.svg" height="40" alt="NGI Zero Core Logo"></a>
153+
</p>

0 commit comments

Comments
 (0)