Skip to content

Commit

Permalink
Merge pull request #117 from sphinx-contrib/modernize
Browse files Browse the repository at this point in the history
Modernize CI and build system
  • Loading branch information
Holzhaus authored Oct 3, 2024
2 parents cdc9cb5 + f9384df commit 30a45ab
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 158 deletions.
122 changes: 122 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: build

on:
push:
pull_request:

jobs:
build:
name: Build and Test Package
strategy:
matrix:
version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.version }}

- name: Install package
run: pip install .

- name: Run tests
run: python -m unittest discover -v

- name: Build documentation
run: |-
mkdir html
git fetch --all
python -I -m sphinx_multiversion -W docs html
- name: Upload the Docs
uses: actions/upload-artifact@v4
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.12'
with:
name: docs
path: html/

- name: Install pypa/build
run: pip install build

- name: Build a binary wheel and a source tarball
run: python3 -m build

- name: Store the distribution packages
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.12'
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

deploy-docs:
name: Deploy Docs to GitHub Pages
if: ${{ startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
needs: [build]
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action
with:
artifact_name: docs

deploy-testpypi:
name: Deploy Distribution to Test PyPI
if: false # Currently disabled
needs: [build]
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/sphinx-multiversion
permissions:
id-token: write

steps:
- name: Download the Distributions
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

- name: Publish Distributions to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1

deploy-pypi:
name: Deploy Distribution to PyPI
if: startsWith(github.ref, 'refs/tags/')
needs: [build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/sphinx-multiversion
permissions:
id-token: write

steps:
- name: Download the Distributions
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

- name: Publish Distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: flake8
- id: check-merge-conflict
- id: check-yaml
- id: check-executables-have-shebangs
- id: mixed-line-ending
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: local
hooks:
- id: version-check
Expand Down
26 changes: 4 additions & 22 deletions .pre-commit/version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pkgutil
import re
import runpy
import subprocess
import sys

import docutils.nodes
Expand Down Expand Up @@ -79,15 +78,6 @@ def get_sphinxconfpy_version(rootdir):
return sphinx_conf["version"], sphinx_conf["release"]


def get_setuppy_version(rootdir):
"""Get version from setup.py."""
setupfile = os.path.join(rootdir, "setup.py")
cmd = (sys.executable, setupfile, "--version")
release = subprocess.check_output(cmd).decode().rstrip(os.linesep)
version = release.rpartition(".")[0]
return version, release


def get_package_version(rootdir):
"""Get version from package __init__.py."""
sys.path.insert(0, os.path.join(rootdir))
Expand All @@ -110,7 +100,6 @@ def get_package_version(rootdir):
def main():
rootdir = os.path.join(os.path.dirname(__file__), "..")

setuppy_version, setuppy_release = get_setuppy_version(rootdir)
package_version, package_release = get_package_version(rootdir)
confpy_version, confpy_release = get_sphinxconfpy_version(rootdir)
changelog_version, changelog_release = get_sphinxchangelog_version(rootdir)
Expand All @@ -121,7 +110,6 @@ def main():
len(repr(x))
for x in (
version_head,
setuppy_version,
package_version,
confpy_version,
changelog_version,
Expand All @@ -135,7 +123,6 @@ def main():
len(repr(x))
for x in (
release_head,
setuppy_release,
package_release,
confpy_release,
changelog_release,
Expand All @@ -147,9 +134,6 @@ def main():
f"File {version_head} {release_head}\n"
f"------------------------------- {'-' * version_width}"
f" {'-' * release_width}\n"
f"setup.py "
f" {setuppy_version!r:>{version_width}}"
f" {setuppy_release!r:>{release_width}}\n"
f"sphinx_multiversion/__init__.py"
f" {package_version!r:>{version_width}}"
f" {package_release!r:>{release_width}}\n"
Expand All @@ -161,13 +145,11 @@ def main():
f" {changelog_release!r:>{release_width}}\n"
)

assert setuppy_version == confpy_version
assert setuppy_version == package_version
assert setuppy_version == changelog_version
assert package_version == confpy_version
assert package_version == changelog_version

assert setuppy_release == confpy_release
assert setuppy_release == package_release
assert setuppy_release == changelog_release
assert package_release == confpy_release
assert package_release == changelog_release


if __name__ == "__main__":
Expand Down
96 changes: 0 additions & 96 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
"""Sphinx configuration file."""

import time

author = "Jan Holthuis"
Expand Down
42 changes: 41 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
[tool.black]
[build-system]
requires = ["hatchling", "hatch-requirements-txt"]
build-backend = "hatchling.build"

[project]
name = "sphinx-multiversion"
dynamic = ["version", "dependencies"]
description = "Add support for multiple versions to sphinx"
readme = "README.md"
license = "BSD-2-Clause"
authors = [
{ name = "Jan Holthuis", email = "[email protected]" },
]
classifiers = [
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[project.scripts]
sphinx-multiversion = "sphinx_multiversion:main"

[project.urls]
Homepage = "https://holzhaus.github.io/sphinx-multiversion/"

[tool.hatch.version]
path = "sphinx_multiversion/__init__.py"

[tool.hatch.metadata.hooks.requirements_txt]
files = ["requirements.txt"]

[tool.hatch.build.targets.sdist]
include = [
"/sphinx_multiversion",
]

[tool.ruff]
line-length = 79
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sphinx
sphinx>=2.1
Loading

0 comments on commit 30a45ab

Please sign in to comment.