Skip to content

Commit 679ace2

Browse files
authored
feat: add publish pypi workflow
2 parents 8b2cb17 + e4c1055 commit 679ace2

File tree

7 files changed

+146
-19
lines changed

7 files changed

+146
-19
lines changed

.github/workflows/build-test.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,17 @@ jobs:
7474
run: |
7575
python3 -m pip install --upgrade pip
7676
77-
- name: Install dependencies
78-
run: python3 -m pip install nox
77+
- name: Install Hatch
78+
run: |
79+
pipx install hatch
80+
pip list
7981
80-
- name: Build project
81-
run: nox -s build-project
82+
- name: Build package using Hatch
83+
run: |
84+
hatch build
85+
echo ""
86+
echo "Generated files:"
87+
ls -lh dist/
8288
8389
- name: Upload artifact
8490
uses: actions/upload-artifact@v4

.github/workflows/publish-pypi.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Publish to PyPI
2+
on:
3+
release:
4+
types: [published]
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
# setup build separate from publish
10+
# See https://github.com/pypa/gh-action-pypi-publish/issues/217#issuecomment-1965727093
11+
build:
12+
runs-on: ubuntu-latest
13+
# This ensures that the publish action only runs in the main repository
14+
# rather than forks
15+
# Environment is encouraged so adding
16+
environment: build
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
# This fetch element is only important if you are use SCM based
22+
# versioning (that looks at git tags to gather the version)
23+
fetch-depth: 100
24+
25+
# Need the tags so that setuptools-scm can form a valid version number
26+
- name: Fetch git tags
27+
run: git fetch origin 'refs/tags/*:refs/tags/*'
28+
29+
- name: Setup Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: "3.10"
33+
- name: Install Hatch
34+
run: |
35+
pipx install hatch
36+
pip list
37+
38+
- name: Build package using Hatch
39+
run: |
40+
hatch build
41+
echo ""
42+
echo "Generated files:"
43+
ls -lh dist/
44+
# Store an artifact of the build to use in the publish step below
45+
- name: Store the distribution packages
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: python-package-distributions
49+
path: dist/
50+
publish:
51+
name: >-
52+
Publish Python 🐍 distribution 📦 to PyPI
53+
if: github.repository_owner == 'pyopensci'
54+
needs:
55+
- build
56+
runs-on: ubuntu-latest
57+
environment:
58+
name: pypi
59+
url: https://pypi.org/p/pyos-sphinx-theme
60+
permissions:
61+
id-token: write # this permission is mandatory for pypi publishing
62+
steps:
63+
# Version 4 doesn't support github enterprise yet
64+
- name: Download all the dists
65+
uses: actions/download-artifact@v4
66+
with:
67+
name: python-package-distributions
68+
path: dist/
69+
- name: Publish package to PyPI
70+
# Only publish to real PyPI on release
71+
if: github.event_name == 'release'
72+
uses: pypa/gh-action-pypi-publish@release/v1
73+
sign-files:
74+
name: >-
75+
Sign the Python 🐍 distribution 📦 with Sigstore
76+
and upload them to GitHub Release
77+
# Only sign on release
78+
if: github.repository_owner == 'pyopensci' && github.event_name == 'release'
79+
needs:
80+
- publish
81+
runs-on: ubuntu-latest
82+
permissions:
83+
contents: write # this permission is mandatory for modifying GitHub Releases
84+
id-token: write # this permission is mandatory for sigstore
85+
steps:
86+
- name: Download all the dists
87+
uses: actions/download-artifact@v4
88+
with:
89+
name: python-package-distributions
90+
path: dist/
91+
- name: Sign the dists with Sigstore
92+
uses: sigstore/[email protected]
93+
with:
94+
inputs: >-
95+
./dist/*.tar.gz
96+
./dist/*.whl
97+
- name: Upload artifact signatures to GitHub Release
98+
env:
99+
GITHUB_TOKEN: ${{ github.token }}
100+
# Upload to GitHub Release using the `gh` CLI.
101+
# `dist/` contains the built packages, and the
102+
# sigstore-produced signatures and certificates.
103+
run: >-
104+
gh release upload
105+
'${{ github.ref_name }}' dist/**
106+
--repo '${{ github.repository }}'

noxfile.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,3 @@ def linkcheck(session):
100100
OUTPUT_DIR,
101101
*session.posargs,
102102
)
103-
104-
105-
@nox.session(name="build-project")
106-
def build_project(session):
107-
"""Build the project and create a wheel distribution for pyproject.toml file."""
108-
session.install("build", "twine")
109-
session.run("python", "-m", "build")
110-
session.run("twine", "check", "dist/*")

pyproject.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
[build-system]
2-
requires = [
3-
"sphinx-theme-builder @ https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip",
4-
]
2+
requires = ["hatchling", "hatch-vcs", "sphinx-theme-builder @ https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip",]
53
build-backend = "sphinx_theme_builder"
64

75
[tool.sphinx-theme-builder]
@@ -13,6 +11,10 @@ name = "pyos-sphinx-theme"
1311
description = "PyOS Documentation Theme."
1412
dynamic = ["version"]
1513
readme = "README.md"
14+
authors = [{ name = "Leah Wasser", email = "[email protected]" }]
15+
maintainers = [
16+
{ name = "pyOpenSci", email = "[email protected]" }, # Optional
17+
]
1618

1719
requires-python = ">=3.9"
1820
dependencies = [
@@ -35,10 +37,8 @@ classifiers = [
3537
"Environment :: Web Environment",
3638
"Intended Audience :: Developers",
3739
"Programming Language :: Python :: 3",
38-
"Programming Language :: Python :: 3.9",
3940
"Programming Language :: Python :: 3.10",
4041
"Programming Language :: Python :: 3.11",
41-
"Programming Language :: Python :: 3.12",
4242
"Operating System :: OS Independent",
4343
"Topic :: Documentation",
4444
"Topic :: Software Development :: Documentation",
@@ -54,6 +54,9 @@ docs = [
5454
"IPython",
5555
]
5656

57+
[tool.hatch]
58+
version.source = "vcs"
59+
5760
[project.entry-points."sphinx.html_themes"]
5861
"pyos_sphinx_theme" = "pyos_sphinx_theme"
5962

src/pyos_sphinx_theme/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
"""A lightweight theme for pyOpenSci."""
22

3+
from datetime import datetime
34
from pathlib import Path
45

56
from pydata_sphinx_theme.utils import config_provided_by_user
67

78
# from sphinx_book_theme import hash_assets_for_files
89
from sphinx.util import logging
910

10-
__version__ = "0.0.1dev0"
11+
__version__ = "0.1.dev0"
12+
current_year = datetime.now().year
13+
organization_name = "pyOpenSci"
14+
1115
LOGGER = logging.getLogger(__name__)
1216

1317
THIS_PATH = Path(__file__).parent.resolve()
1418
THEME_PATH = THIS_PATH / "theme" / "pyos_sphinx_theme"
19+
TEMPLATE_PATH = THEME_PATH / "templates"
1520
LOGO_LIGHT = str((THEME_PATH / "static" / "images" / "logo-light-mode.png").absolute()).replace(
1621
"\\", "/"
1722
)
@@ -73,7 +78,9 @@ def update_config(app):
7378
"image": "_static/pyopensci-logo-package-guide.png",
7479
}
7580

76-
# If no html_logo is set then use a stock 2i2c logo
81+
app.config.copyright = f"{current_year}, {organization_name}"
82+
83+
# If no html_logo is set then use a stock pyOpenSci logo
7784
if not config_provided_by_user(app, "html_logo") and not social_cards.get("image"):
7885
line_color = "#6D597A"
7986
social_cards["image"] = str(LOGO_LIGHT)
@@ -112,6 +119,7 @@ def setup(app):
112119
app.add_html_theme("pyos_sphinx_theme", THEME_PATH)
113120
app.config.html_favicon = "https://www.pyopensci.org/images/favicon.ico"
114121
app.connect("builder-inited", update_config)
122+
app.config.templates_path.append(str(TEMPLATE_PATH))
115123
# app.connect("html-page-context", redirect_from_html_to_dirhtml)
116124
# app.add_css_file("static/styles/pyos-sphinx-theme.css")
117125
# app.add_js_file("static/scripts/matomo.js")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<p>
2+
pyOpensci is dedicated to creating a welcoming, supportive and diverse
3+
community around the open source Python tools that drive open science. Our
4+
<a
5+
href="https://www.pyopensci.org/handbook/CODE_OF_CONDUCT.html"
6+
target="_blank"
7+
>Code of Conduct</a
8+
>
9+
defines expected behavior and guidelines that help create such a community.
10+
</p>

src/pyos_sphinx_theme/theme/pyos_sphinx_theme/theme.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ stylesheet = styles/pyos-sphinx-theme.css
66

77
# Myst syntax extensions
88
myst_enable_extensions = ["colon_fence",]
9+
footer_start = code_of_conduct, copyright
10+
footer_end =

0 commit comments

Comments
 (0)