diff options
author | James R. Barlow <james@purplerock.ca> | 2022-07-25 15:10:22 -0700 |
---|---|---|
committer | James R. Barlow <james@purplerock.ca> | 2022-07-25 15:10:22 -0700 |
commit | 55f4fc0714e3979a2b24be355d8b566bae974263 (patch) | |
tree | 933fb606063b0fe5b6cb178706409c4e2b8e7001 | |
parent | 5f6fe3b4bf117dfbfd240cff51fa10ca3fc7f495 (diff) | |
parent | 5cf8805dcdf6ebcb027d9d34f01c9d060268fe6b (diff) |
Merge commit '5cf8805dcdf6ebcb027d9d34f01c9d060268fe6b'
-rw-r--r-- | .github/workflows/build.yml | 17 | ||||
-rw-r--r-- | docs/conf.py | 55 | ||||
-rw-r--r-- | docs/requirements.txt | 4 | ||||
-rw-r--r-- | setup.cfg | 1 |
4 files changed, 46 insertions, 31 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5f1daf3..40dd5e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: uses: actions/upload-artifact@v3 if: matrix.platform == 'manylinux_x86_64' with: - name: rtd-wheel-${{ github.sha }} + name: rtd-wheel path: ./wheelhouse/pikepdf-*-cp39-*.manylinux2014_x86_64.whl if-no-files-found: error @@ -233,7 +233,7 @@ 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: Check for secrets id: setvar @@ -247,12 +247,15 @@ jobs: echo "Secrets to use trigger ReadTheDocs were not configured" echo "::set-output name=have_secrets::false" fi + - name: Get branch name + id: get_branch + run: | + echo "::set-output name=branch::${GITHUB_REF##refs/heads/}" - name: Trigger ReadTheDocs webhook - uses: dfm/rtds-action@v1 - with: - webhook_url: ${{ secrets.RTDS_WEBHOOK_URL }} - webhook_token: ${{ secrets.RTDS_WEBHOOK_TOKEN }} - commit_ref: ${{ github.ref }} + run: | + curl -X POST -d "branches=${{ steps.get_branch.outputs.branch }}" \ + -d "token=${{ secrets.RTDS_WEBHOOK_TOKEN }}" \ + "${{ secrets.RTDS_WEBHOOK_URL }}" if: ${{ steps.setvar.outputs.have_secrets == 'true' }} upload_pypi: diff --git a/docs/conf.py b/docs/conf.py index 16804b8..9de0b34 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,6 +13,7 @@ from __future__ import annotations +import io import os import subprocess import sys @@ -39,47 +40,58 @@ extensions = [ on_rtd = os.environ.get('READTHEDOCS') == 'True' if on_rtd: - extensions.append('rtds_action') + import tempfile + import zipfile -if on_rtd: - github_token = os.environ['GITHUB_TOKEN'] - # The name of your GitHub repository - rtds_action_github_repo = "pikepdf/pikepdf" - - # The path where the artifact should be extracted - # Note: this is relative to the conf.py file! - rtds_action_path = "." + import git + import github + import requests - # The "prefix" used in the `upload-artifact` step of the action - rtds_action_artifact_prefix = "rtd-wheel-" + # 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 - # A GitHub personal access token is required, more info below - rtds_action_github_token = os.environ["GITHUB_TOKEN"] + github_token = os.environ['GITHUB_TOKEN'] + head_sha = git.Repo(search_parent_directories=True).head.commit.hexsha + g = github.Github() - # Whether or not to raise an error on Read the Docs if the - # artifact can't be downloaded (optional) - rtds_action_error_if_missing = True + 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 + ) def pip(*args): subprocess.run([sys.executable, '-m', 'pip', *args], check=True) - wheel = next(Path('.').glob('*.whl')) - pip('install', '--force-reinstall', wheel) + 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]}') 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 ------------------------------------------------ @@ -87,7 +99,6 @@ import pikepdf # isort:skip pylint: disable=unused-import # If your documentation needs a minimal Sphinx version, state it here. # needs_sphinx = '1.0' - issues_github_path = "pikepdf/pikepdf" ipython_execlines = ['import pikepdf', 'from pikepdf import Pdf'] diff --git a/docs/requirements.txt b/docs/requirements.txt index d951506..d5c92e3 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -17,4 +17,6 @@ sphinx-design sphinx-rtd-theme tomli; python_version < '3.11' -rtds-action +GitPython +PyGithub +requests @@ -62,7 +62,6 @@ docs = matplotlib pybind11 requests - rtds-action setuptools-scm sphinx-design sphinx-issues |