Skip to content

Commit 6ce5282

Browse files
authored
Amjith/modernize setup ci publish (#154)
* Modernize the project to use uv, pyproject.toml and github trusted publisher. * Make the version dynamic. * Update precommit hook. * Ruff format fixes. * Ruff lint fixes. * Update DEVELOP.rst file. * Rename DEVELOP to CONTRIBUTING. * Update PR template.
1 parent 85962ba commit 6ce5282

18 files changed

+259
-319
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
## Checklist
77
<!--- We appreciate your help and want to give you credit. Please take a moment to put an `x` in the boxes below as you complete them. -->
88
- [ ] I've added this contribution to the `changelog.rst`.
9-
- [ ] I installed pre-commit hooks (`pip install pre-commit && pre-commit install`), and ran `black` on my code.
9+
- [ ] I installed pre-commit hooks (`pip install pre-commit && pre-commit install`).
1010
- [x] Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

.github/workflows/ci.yml

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,8 @@ jobs:
1111

1212
strategy:
1313
matrix:
14-
include:
15-
- python-version: '3.7'
16-
postgres-version: '10'
17-
- python-version: '3.8'
18-
postgres-version: '11'
19-
- python-version: '3.9'
20-
postgres-version: '12'
21-
- python-version: '3.10'
22-
postgres-version: '13'
23-
- python-version: '3.11'
24-
postgres-version: '14'
25-
- python-version: '3.11'
26-
postgres-version: '15'
14+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
15+
postgres-version: ["10", "11", "12", "13", "14", "15"]
2716

2817
services:
2918
postgres:
@@ -40,29 +29,24 @@ jobs:
4029
--health-retries 5
4130
4231
steps:
43-
- uses: actions/checkout@v2
32+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34+
- uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
35+
with:
36+
version: "latest"
4437

4538
- name: Set up Python ${{ matrix.python-version }}
46-
uses: actions/setup-python@v2
39+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
4740
with:
4841
python-version: ${{ matrix.python-version }}
4942

50-
- name: Install requirements
51-
run: |
52-
pip install -U pip setuptools
53-
pip install --no-cache-dir .
54-
pip install -r requirements-dev.txt
43+
- name: Install dependencies
44+
run: uv sync --all-extras -p ${{ matrix.python-version }}
5545

5646
- name: Run unit tests
5747
env:
5848
LANG: en_US.UTF-8
59-
run: coverage run --source pgspecial -m pytest
60-
61-
- name: Run Black
62-
run: black --check .
63-
if: matrix.python-version == '3.7'
49+
run: uv run tox -e py${{ matrix.python-version }}
6450

65-
- name: Coverage
66-
run: |
67-
coverage report
68-
codecov
51+
- name: Run Style Checks
52+
run: uv run tox -e style

.github/workflows/publish.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Publish Python Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
17+
postgres-version: ["10", "11", "12", "13", "14", "15"]
18+
19+
services:
20+
postgres:
21+
image: postgres:${{ matrix.postgres-version }}
22+
env:
23+
POSTGRES_USER: postgres
24+
POSTGRES_PASSWORD: postgres
25+
ports:
26+
- 5432:5432
27+
options: >-
28+
--health-cmd pg_isready
29+
--health-interval 10s
30+
--health-timeout 5s
31+
--health-retries 5
32+
33+
steps:
34+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
35+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
36+
- uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
37+
with:
38+
version: "latest"
39+
40+
- name: Set up Python ${{ matrix.python-version }}
41+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
42+
with:
43+
python-version: ${{ matrix.python-version }}
44+
45+
- name: Install dependencies
46+
run: uv sync --all-extras -p ${{ matrix.python-version }}
47+
48+
- name: Run unit tests
49+
env:
50+
LANG: en_US.UTF-8
51+
run: uv run tox -e py${{ matrix.python-version }}
52+
53+
- name: Run Style Checks
54+
run: uv run tox -e style
55+
56+
build:
57+
runs-on: ubuntu-latest
58+
needs: [test]
59+
60+
steps:
61+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
62+
- uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
63+
with:
64+
version: "latest"
65+
66+
- name: Set up Python
67+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
68+
with:
69+
python-version: '3.13'
70+
71+
- name: Install dependencies
72+
run: uv sync --all-extras -p 3.13
73+
74+
- name: Build
75+
run: uv build
76+
77+
- name: Store the distribution packages
78+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
79+
with:
80+
name: python-packages
81+
path: dist/
82+
83+
publish:
84+
name: Publish to PyPI
85+
runs-on: ubuntu-latest
86+
if: startsWith(github.ref, 'refs/tags/')
87+
needs: [build]
88+
environment: release
89+
permissions:
90+
id-token: write
91+
steps:
92+
- name: Download distribution packages
93+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
94+
with:
95+
name: python-packages
96+
path: dist/
97+
- name: Publish to PyPI
98+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4

.pre-commit-config.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: stable
4-
hooks:
5-
- id: black
6-
language_version: python3.11
7-
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.11.7
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: [ --fix ]
9+
# Run the formatter.
10+
- id: ruff-format

DEVELOP.rst renamed to CONTRIBUTING.rst

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ Make the changes and create the commits in your local machine. Then push those
1212
changes to your fork. Then click on the pull request icon on github and create
1313
a new pull request. Add a description about the change and send it along. I
1414
promise to review the pull request in a reasonable window of time and get back
15-
to you.
15+
to you.
1616

1717
In order to keep your fork up to date with any changes from mainline, add a new
1818
git remote to your local copy called 'upstream' and point it to the main
1919
``pgspecial`` repo.
2020

21-
::
21+
::
2222

2323
$ git remote add upstream git@github.com:dbcli/pgspecial.git
2424

2525
Once the 'upstream' end point is added you can then periodically do a ``git
2626
pull upstream master`` to update your local copy and then do a ``git push
27-
origin master`` to keep your own fork up to date.
27+
origin master`` to keep your own fork up to date.
2828

2929
Local Setup
3030
-----------
@@ -34,28 +34,24 @@ The installation instructions in the README file are intended for users of
3434
a slightly different way so you can see the effects of your changes right away
3535
without having to go through the install cycle every time you change the code.
3636

37-
It is highly recommended to use virtualenv for development. If you don't know
38-
what a virtualenv is, this `guide
39-
<http://docs.python-guide.org/en/latest/dev/virtualenvs/#virtual-environments>`_
40-
will help you get started.
41-
42-
Create a virtualenv (let's call it ``pgspecial-dev``). Activate it:
37+
Set up [uv](https://docs.astral.sh/uv/getting-started/installation/) for development:
4338

4439
::
4540

46-
virtualenv ./pgspecial-dev
41+
cd pgspecial
42+
uv venv
4743
source ./pgspecial-dev/bin/activate
4844

4945
Once the virtualenv is activated, `cd` into the local clone of pgspecial folder
5046
and install pgspecial using pip as follows:
5147

5248
::
5349

54-
$ pip install --editable .
50+
$ uv pip install --editable .[dev]
5551

5652
or
5753

58-
$ pip install -e .
54+
$ pip install -e .[dev]
5955

6056
This will install the necessary dependencies as well as install pgspecial from
6157
the working folder into the virtualenv. By installing it using `pip install -e`
@@ -111,41 +107,32 @@ First, install the requirements for testing:
111107

112108
::
113109

114-
$ pip install -r requirements-dev.txt
110+
uv pip install -e .[dev]
115111

116112
After that, tests can be run with:
117113

118114
::
119115

120-
$ py.test
116+
pytest
121117

122118
Pytest configuration can be found in the ``tool.pytest.ini_options`` table of the ``pyproject.toml`` file.
123119

124120
Enforcing the code style (linting)
125-
------------------------------
121+
----------------------------------
126122

127123
When you submit a PR, the changeset is checked for pep8 compliance using
128-
`black <https://github.com/psf/black>`_. If you see a build failing because
129-
of these checks, install ``black`` and apply style fixes:
124+
`ruff <https://docs.astral.sh/ruff/>`_. You can run the linter and formatter locally:
130125

131126
::
132127

133-
$ pip install black
134-
$ black .
128+
$ tox -e style
135129

136130
Then commit and push the fixes.
137131

138-
To enforce ``black`` applied on every commit, we also suggest installing ``pre-commit`` and
132+
To enforce ``ruff`` applied on every commit, we also suggest installing ``pre-commit`` and
139133
using the ``pre-commit`` hooks available in this repo:
140134

141135
::
142136

143137
$ pip install pre-commit
144138
$ pre-commit install
145-
146-
Git blame
147-
---------
148-
149-
Use ``git blame my_file.py --ignore-revs-file .git-blame-ignore-revs`` to exclude irrelevant commits
150-
(specifically Black) from ``git blame``. For more information,
151-
see `here <https://github.com/psf/black#migrating-your-code-style-without-ruining-git-blame>`_.

changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2+
Unreleased (TBD)
3+
==================
4+
5+
* Moderize the repository
6+
* Use uv instead of pip
7+
* Use github trusted publisher for pypi release
8+
19
2.1.3 (2024-11-25)
210
==================
311

pgspecial/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import importlib.metadata
2+
3+
__version__ = importlib.metadata.version("pgspecial")
14
__all__ = []
2-
__version__ = "2.1.3"
35

46

57
def export(defn):
@@ -9,4 +11,4 @@ def export(defn):
911
return defn
1012

1113

12-
from . import dbcommands, iocommands
14+
from . import dbcommands, iocommands # noqa

0 commit comments

Comments
 (0)