summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames R. Barlow <james@purplerock.ca>2022-07-13 01:31:57 -0700
committerJames R. Barlow <james@purplerock.ca>2022-07-13 01:44:06 -0700
commitec857696690c34d6f5978cb6a9abd636b76aafd9 (patch)
tree506c19b5d7ab2894f2c21c26725837fa597c546a
parentd868975ed0720c419bbd32f55d8c56553e764be0 (diff)
Trigger RTD with action instead of fragile scripting
-rw-r--r--.github/workflows/build.yml15
-rw-r--r--docs/conf.py55
-rw-r--r--docs/requirements.txt4
-rw-r--r--setup.cfg1
4 files changed, 29 insertions, 46 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 2531c39..7498d49 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -224,17 +224,14 @@ jobs:
name: Trigger ReadTheDocs
runs-on: ubuntu-latest
needs: [wheels_linux]
- if: startsWith(github.ref, 'refs/heads/') && !startsWith(github.ref, 'refs/heads/actions')
+ # if: startsWith(github.ref, 'refs/heads/') && !startsWith(github.ref, 'refs/heads/actions')
steps:
- - name: Get branch name
- id: get_branch
- run: |
- echo "::set-output name=branch::${GITHUB_REF##refs/heads/}"
- name: Trigger ReadTheDocs webhook
- run: |
- curl -X POST -d "branches=${{ steps.get_branch.outputs.branch }}" \
- -d "token=${{ secrets.TOKEN_RTD }}" \
- https://readthedocs.org/api/v2/webhook/pikepdf/163029/
+ uses: dfm/rtds-action@v1
+ with:
+ webhook_url: ${{ secrets.RTDS_WEBHOOK_URL }}
+ webhook_token: ${{ secrets.RTDS_WEBHOOK_TOKEN }}
+ commit_ref: ${{ github.ref }}
upload_pypi:
needs: [wheels_linux, wheels_linux_arm, wheels_macos, wheels_windows, sdist]
diff --git a/docs/conf.py b/docs/conf.py
index 0f9760e..cb681dd 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -11,7 +11,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
-import io
import os
import subprocess
import sys
@@ -21,59 +20,44 @@ import tomli
on_rtd = os.environ.get('READTHEDOCS') == 'True'
if on_rtd:
- import tempfile
- import zipfile
+ github_token = os.environ['GITHUB_TOKEN']
+ # The name of your GitHub repository
+ rtds_action_github_repo = "pikepdf/pikepdf"
- import git
- import github
- import requests
+ # The path where the artifact should be extracted
+ # Note: this is relative to the conf.py file!
+ rtds_action_path = "."
- # Borrowed from https://github.com/YannickJadoul/Parselmouth/blob/master/docs/conf.py
- rtd_version = os.environ.get('READTHEDOCS_VERSION', '')
- branch = 'master' if rtd_version == 'latest' else rtd_version
+ # The "prefix" used in the `upload-artifact` step of the action
+ rtds_action_artifact_prefix = "rtd-wheel"
- github_token = os.environ['GITHUB_TOKEN']
- head_sha = git.Repo(search_parent_directories=True).head.commit.hexsha
- g = github.Github()
+ # A GitHub personal access token is required, more info below
+ rtds_action_github_token = os.environ["GITHUB_TOKEN"]
- runs = (
- g.get_repo('pikepdf/pikepdf').get_workflow('build.yml').get_runs(branch=branch)
- )
-
- artifacts_url = next(r for r in runs if r.head_sha == head_sha).artifacts_url
-
- archive_download_url = next(
- artifact
- for artifact in requests.get(artifacts_url).json()['artifacts']
- if artifact['name'] == 'rtd-wheel'
- )['archive_download_url']
- artifact_bin = io.BytesIO(
- requests.get(
- archive_download_url,
- headers={'Authorization': f'token {github_token}'},
- stream=True,
- ).content
- )
+ # Whether or not to raise an error on Read the Docs if the
+ # artifact containing the notebooks can't be downloaded (optional)
+ rtds_action_error_if_missing = False
def pip(*args):
subprocess.run([sys.executable, '-m', 'pip', *args], check=True)
- with zipfile.ZipFile(artifact_bin) as zf, tempfile.TemporaryDirectory() as tmpdir:
- assert len(zf.namelist()) == 1
- zf.extractall(tmpdir)
- pip('install', '--force-reinstall', f'{tmpdir}/{zf.namelist()[0]}')
+ wheel = next(Path('.').glob('*.whl'))
+ pip('install', '--force-reinstall', wheel)
else:
sys.path.insert(0, os.path.abspath(os.path.join('..', 'installed')))
+
autodoc_mock_imports = ['libxmp']
autodoc_typehints = 'description'
+
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.join(os.path.abspath('.'), './_ext'))
sys.path.insert(0, os.path.join(os.path.abspath('.'), '..'))
+
import pikepdf # isort:skip pylint: disable=unused-import
# -- General configuration ------------------------------------------------
@@ -96,6 +80,9 @@ extensions = [
'fix_pybind11_autodoc',
]
+if on_rtd:
+ extensions.append('rtds_action')
+
issues_github_path = "pikepdf/pikepdf"
ipython_execlines = ['import pikepdf', 'from pikepdf import Pdf']
diff --git a/docs/requirements.txt b/docs/requirements.txt
index e75e846..12742f9 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -17,6 +17,4 @@ sphinx-design
sphinx-rtd-theme
tomli
-GitPython
-PyGithub
-requests
+rtds-action
diff --git a/setup.cfg b/setup.cfg
index 8e707c4..03e5df8 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -62,6 +62,7 @@ docs =
matplotlib
pybind11
requests
+ rtds-action
setuptools-scm
sphinx-design
sphinx-issues