Skip to content

Commit 8dd1dcc

Browse files
committed
Add GitHub Actions build/publish/sign/release workflow and Python 3.12 support.
1 parent 71f9cdb commit 8dd1dcc

File tree

5 files changed

+115
-42
lines changed

5 files changed

+115
-42
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: build-publish-sign-release
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
jobs:
7+
call-workflow-lint-test-cover-docs:
8+
name: Call linting/testing workflow.
9+
uses: ./.github/workflows/lint-test-cover-docs.yml
10+
secrets: inherit
11+
build:
12+
name: Build package.
13+
needs:
14+
- call-workflow-lint-test-cover-docs
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Install Python.
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: 3.12
22+
architecture: x64
23+
- name: Install pypa/build.
24+
run: python -m pip install .[publish]
25+
- name: Build a source tarball and a binary wheel.
26+
run: python -m build --sdist --wheel .
27+
- name: Store the package distributions.
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: python-package-distributions
31+
path: dist/
32+
publish:
33+
name: Publish package to PyPI.
34+
if: startsWith(github.ref, 'refs/tags/') # Publish on tag pushes.
35+
needs:
36+
- build
37+
runs-on: ubuntu-latest
38+
environment:
39+
name: pypi
40+
url: https://pypi.org/p/modulo
41+
permissions:
42+
id-token: write
43+
steps:
44+
- name: Download all the package distributions.
45+
uses: actions/download-artifact@v4
46+
with:
47+
name: python-package-distributions
48+
path: dist/
49+
- name: Publish package to PyPI.
50+
uses: pypa/gh-action-pypi-publish@release/v1
51+
sign-release:
52+
name: Sign package distributions with Sigstore and upload them to a GitHub release.
53+
needs:
54+
- publish
55+
runs-on: ubuntu-latest
56+
permissions:
57+
contents: write # For GitHub.
58+
id-token: write # For Sigstore.
59+
steps:
60+
- name: Download all the package distributions.
61+
uses: actions/download-artifact@v4
62+
with:
63+
name: python-package-distributions
64+
path: dist/
65+
- name: Sign the package distributions with Sigstore.
66+
uses: sigstore/[email protected]
67+
with:
68+
inputs: >-
69+
./dist/*.tar.gz
70+
./dist/*.whl
71+
- name: Create a GitHub release.
72+
env:
73+
GITHUB_TOKEN: ${{ github.token }}
74+
run: gh release create '${{ github.ref_name }}' --repo '${{ github.repository }}'
75+
- name: Upload package distributions and signatures/certificates to the GitHub release.
76+
env:
77+
GITHUB_TOKEN: ${{ github.token }}
78+
run: >-
79+
gh release upload
80+
'${{ github.ref_name }}' dist/**
81+
--repo '${{ github.repository }}'

.github/workflows/lint-test-cover-docs.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
name: lint-test-cover-docs
22
on:
3-
push
3+
push:
4+
branches:
5+
- '**'
6+
workflow_call: # If invoked by build-publish-sign-release workflow.
47
jobs:
58
lint_test_cover_docs:
6-
runs-on: ubuntu-latest
9+
runs-on: ubuntu-20.04
710
strategy:
811
matrix:
9-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
10-
name: "Python ${{ matrix.python-version }}"
12+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
13+
name: Python ${{ matrix.python-version }}
1114
steps:
12-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1316
- name: Install Python.
14-
uses: actions/setup-python@v4
17+
uses: actions/setup-python@v5
1518
with:
1619
python-version: ${{ matrix.python-version }}
1720
architecture: x64
@@ -20,11 +23,12 @@ jobs:
2023
pip install -U .[lint,test]
2124
python -m pylint modulo # Check against linting rules.
2225
python -m pytest # Run tests.
26+
python src/modulo/modulo.py -v # Run tests via execution.
2327
- name: Publish coverage results.
2428
run: |
2529
pip install -U .[coveralls]
2630
python -m coveralls --service=github # Submit to coveralls.
27-
if: matrix.python-version == '3.11'
31+
if: matrix.python-version == '3.12'
2832
env:
2933
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3034
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

README.rst

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ Pure-Python library for working with modular arithmetic, congruence classes, and
66

77
|pypi| |readthedocs| |actions| |coveralls|
88

9-
.. |pypi| image:: https://badge.fury.io/py/modulo.svg
9+
.. |pypi| image:: https://badge.fury.io/py/modulo.svg#
1010
:target: https://badge.fury.io/py/modulo
1111
:alt: PyPI version and link.
1212

1313
.. |readthedocs| image:: https://readthedocs.org/projects/modulo-lib/badge/?version=latest
1414
:target: https://modulo-lib.readthedocs.io/en/latest/?badge=latest
1515
:alt: Read the Docs documentation status.
1616

17-
.. |actions| image:: https://github.com/lapets/modulo/workflows/lint-test-cover-docs/badge.svg
17+
.. |actions| image:: https://github.com/lapets/modulo/workflows/lint-test-cover-docs/badge.svg#
1818
:target: https://github.com/lapets/modulo/actions/workflows/lint-test-cover-docs.yml
1919
:alt: GitHub Actions status.
2020

@@ -34,7 +34,7 @@ This library is available as a `package on PyPI <https://pypi.org/project/modulo
3434
3535
python -m pip install modulo
3636
37-
The library can be imported in the usual way:
37+
The library can be imported in the usual ways:
3838

3939
.. code-block:: python
4040
@@ -157,15 +157,15 @@ All installation and development dependencies are fully specified in ``pyproject
157157

158158
.. code-block:: bash
159159
160-
python -m pip install .[docs,lint]
160+
python -m pip install ".[docs,lint]"
161161
162162
Documentation
163163
^^^^^^^^^^^^^
164164
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:
165165

166166
.. code-block:: bash
167167
168-
python -m pip install .[docs]
168+
python -m pip install ".[docs]"
169169
cd docs
170170
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html
171171
@@ -175,7 +175,7 @@ All unit tests are executed and their coverage is measured when using `pytest <h
175175

176176
.. code-block:: bash
177177
178-
python -m pip install .[test]
178+
python -m pip install ".[test]"
179179
python -m pytest
180180
181181
Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:
@@ -188,7 +188,7 @@ Style conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:
188188

189189
.. code-block:: bash
190190
191-
python -m pip install .[lint]
191+
python -m pip install ".[lint]"
192192
python -m pylint src/modulo
193193
194194
Contributions
@@ -201,28 +201,13 @@ Beginning with version 0.2.0, the version number format for this library and the
201201

202202
Publishing
203203
^^^^^^^^^^
204-
This library can be published as a `package on PyPI <https://pypi.org/project/modulo>`__ by a package maintainer. First, install the dependencies required for packaging and publishing:
204+
This library can be published as a `package on PyPI <https://pypi.org/project/modulo>`__ via the GitHub Actions workflow found in ``.github/workflows/build-publish-sign-release.yml`` that follows the `recommendations found in the Python Packaging User Guide <https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/>`__.
205205

206-
.. code-block:: bash
207-
208-
python -m pip install .[publish]
206+
Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions.
209207

210-
Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number):
208+
To publish the package, create and push a tag for the version being published (replacing ``?.?.?`` with the version number):
211209

212210
.. code-block:: bash
213211
214212
git tag ?.?.?
215213
git push origin ?.?.?
216-
217-
Remove any old build/distribution files. Then, package the source into a distribution archive:
218-
219-
.. code-block:: bash
220-
221-
rm -rf build dist src/*.egg-info
222-
python -m build --sdist --wheel .
223-
224-
Finally, upload the package distribution archive to `PyPI <https://pypi.org>`__:
225-
226-
.. code-block:: bash
227-
228-
python -m twine upload dist/*

pyproject.toml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "modulo"
3-
version = "2.1.0"
3+
version = "3.0.0"
44
description = """\
55
Pure-Python library for working with modular arithmetic, \
66
congruence classes, and finite fields.\
@@ -13,7 +13,7 @@ authors = [
1313
readme = "README.rst"
1414
requires-python = ">=3.7"
1515
dependencies = [
16-
"egcd~=0.5"
16+
"egcd~=1.0"
1717
]
1818

1919
[project.urls]
@@ -23,18 +23,21 @@ Documentation = "https://modulo-lib.readthedocs.io"
2323
[project.optional-dependencies]
2424
docs = [
2525
"toml~=0.10.2",
26-
"sphinx~=4.2.0",
27-
"sphinx-rtd-theme~=1.0.0"
26+
"sphinx~=5.0",
27+
"sphinx-rtd-theme~=2.0.0"
2828
]
2929
test = [
30-
"pytest~=7.2",
31-
"pytest-cov~=4.0"
30+
"pytest~=7.4; python_version < '3.12'",
31+
"pytest~=8.2; python_version >= '3.12'",
32+
"pytest-cov~=4.1; python_version < '3.12'",
33+
"pytest-cov~=5.0; python_version >= '3.12'"
3234
]
3335
lint = [
34-
"pylint~=2.17.0"
36+
"pylint~=2.17.0; python_version < '3.12'",
37+
"pylint~=3.2.0; python_version >= '3.12'"
3538
]
3639
coveralls = [
37-
"coveralls~=3.3.1"
40+
"coveralls~=4.0"
3841
]
3942
publish = [
4043
"build~=0.10",
@@ -43,7 +46,7 @@ publish = [
4346

4447
[build-system]
4548
requires = [
46-
"setuptools~=67.6"
49+
"setuptools>=68.0"
4750
]
4851
build-backend = "setuptools.build_meta"
4952

src/modulo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
"""Gives users direct access to class and synonyms."""
1+
"""Allow users to access the class and synonyms directly."""
22
from modulo.modulo import modulo, mod, Z

0 commit comments

Comments
 (0)