Skip to content

Commit

Permalink
feat: add publish pypi workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lwasser authored Aug 29, 2024
2 parents 8b2cb17 + e4c1055 commit 679ace2
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 19 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ jobs:
run: |
python3 -m pip install --upgrade pip
- name: Install dependencies
run: python3 -m pip install nox
- name: Install Hatch
run: |
pipx install hatch
pip list
- name: Build project
run: nox -s build-project
- name: Build package using Hatch
run: |
hatch build
echo ""
echo "Generated files:"
ls -lh dist/
- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down
106 changes: 106 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Publish to PyPI
on:
release:
types: [published]
push:
branches:
- main
jobs:
# setup build separate from publish
# See https://github.com/pypa/gh-action-pypi-publish/issues/217#issuecomment-1965727093
build:
runs-on: ubuntu-latest
# This ensures that the publish action only runs in the main repository
# rather than forks
# Environment is encouraged so adding
environment: build
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# This fetch element is only important if you are use SCM based
# versioning (that looks at git tags to gather the version)
fetch-depth: 100

# Need the tags so that setuptools-scm can form a valid version number
- name: Fetch git tags
run: git fetch origin 'refs/tags/*:refs/tags/*'

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Hatch
run: |
pipx install hatch
pip list
- name: Build package using Hatch
run: |
hatch build
echo ""
echo "Generated files:"
ls -lh dist/
# Store an artifact of the build to use in the publish step below
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
publish:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: github.repository_owner == 'pyopensci'
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pyos-sphinx-theme
permissions:
id-token: write # this permission is mandatory for pypi publishing
steps:
# Version 4 doesn't support github enterprise yet
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish package to PyPI
# Only publish to real PyPI on release
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
sign-files:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
# Only sign on release
if: github.repository_owner == 'pyopensci' && github.event_name == 'release'
needs:
- publish
runs-on: ubuntu-latest
permissions:
contents: write # this permission is mandatory for modifying GitHub Releases
id-token: write # this permission is mandatory for sigstore
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
8 changes: 0 additions & 8 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,3 @@ def linkcheck(session):
OUTPUT_DIR,
*session.posargs,
)


@nox.session(name="build-project")
def build_project(session):
"""Build the project and create a wheel distribution for pyproject.toml file."""
session.install("build", "twine")
session.run("python", "-m", "build")
session.run("twine", "check", "dist/*")
13 changes: 8 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[build-system]
requires = [
"sphinx-theme-builder @ https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip",
]
requires = ["hatchling", "hatch-vcs", "sphinx-theme-builder @ https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip",]
build-backend = "sphinx_theme_builder"

[tool.sphinx-theme-builder]
Expand All @@ -13,6 +11,10 @@ name = "pyos-sphinx-theme"
description = "PyOS Documentation Theme."
dynamic = ["version"]
readme = "README.md"
authors = [{ name = "Leah Wasser", email = "[email protected]" }]
maintainers = [
{ name = "pyOpenSci", email = "[email protected]" }, # Optional
]

requires-python = ">=3.9"
dependencies = [
Expand All @@ -35,10 +37,8 @@ classifiers = [
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: OS Independent",
"Topic :: Documentation",
"Topic :: Software Development :: Documentation",
Expand All @@ -54,6 +54,9 @@ docs = [
"IPython",
]

[tool.hatch]
version.source = "vcs"

[project.entry-points."sphinx.html_themes"]
"pyos_sphinx_theme" = "pyos_sphinx_theme"

Expand Down
12 changes: 10 additions & 2 deletions src/pyos_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
"""A lightweight theme for pyOpenSci."""

from datetime import datetime
from pathlib import Path

from pydata_sphinx_theme.utils import config_provided_by_user

# from sphinx_book_theme import hash_assets_for_files
from sphinx.util import logging

__version__ = "0.0.1dev0"
__version__ = "0.1.dev0"
current_year = datetime.now().year
organization_name = "pyOpenSci"

LOGGER = logging.getLogger(__name__)

THIS_PATH = Path(__file__).parent.resolve()
THEME_PATH = THIS_PATH / "theme" / "pyos_sphinx_theme"
TEMPLATE_PATH = THEME_PATH / "templates"
LOGO_LIGHT = str((THEME_PATH / "static" / "images" / "logo-light-mode.png").absolute()).replace(
"\\", "/"
)
Expand Down Expand Up @@ -73,7 +78,9 @@ def update_config(app):
"image": "_static/pyopensci-logo-package-guide.png",
}

# If no html_logo is set then use a stock 2i2c logo
app.config.copyright = f"{current_year}, {organization_name}"

# If no html_logo is set then use a stock pyOpenSci logo
if not config_provided_by_user(app, "html_logo") and not social_cards.get("image"):
line_color = "#6D597A"
social_cards["image"] = str(LOGO_LIGHT)
Expand Down Expand Up @@ -112,6 +119,7 @@ def setup(app):
app.add_html_theme("pyos_sphinx_theme", THEME_PATH)
app.config.html_favicon = "https://www.pyopensci.org/images/favicon.ico"
app.connect("builder-inited", update_config)
app.config.templates_path.append(str(TEMPLATE_PATH))
# app.connect("html-page-context", redirect_from_html_to_dirhtml)
# app.add_css_file("static/styles/pyos-sphinx-theme.css")
# app.add_js_file("static/scripts/matomo.js")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>
pyOpensci is dedicated to creating a welcoming, supportive and diverse
community around the open source Python tools that drive open science. Our
<a
href="https://www.pyopensci.org/handbook/CODE_OF_CONDUCT.html"
target="_blank"
>Code of Conduct</a
>
defines expected behavior and guidelines that help create such a community.
</p>
2 changes: 2 additions & 0 deletions src/pyos_sphinx_theme/theme/pyos_sphinx_theme/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ stylesheet = styles/pyos-sphinx-theme.css

# Myst syntax extensions
myst_enable_extensions = ["colon_fence",]
footer_start = code_of_conduct, copyright
footer_end =

0 comments on commit 679ace2

Please sign in to comment.