From 099915e230177872715f076cf85ef0e40dc90e54 Mon Sep 17 00:00:00 2001 From: Patrick Kunzmann Date: Mon, 23 Dec 2024 14:00:18 +0100 Subject: [PATCH 1/2] Use trusted publishing --- .github/workflows/test_and_deploy.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml index d57390fbb..d3b80f4a2 100644 --- a/.github/workflows/test_and_deploy.yml +++ b/.github/workflows/test_and_deploy.yml @@ -326,6 +326,7 @@ jobs: name: Upload package to GitHub Releases & PyPI permissions: contents: write + id-token: write needs: - lint - test-and-build @@ -333,6 +334,9 @@ jobs: - test-interfaces - test-muscle5 runs-on: ubuntu-latest + environment: + name: publish + url: https://pypi.org/p/biotite steps: - uses: actions/download-artifact@v4 with: @@ -347,10 +351,8 @@ jobs: with: files: dist//* - name: Upload to PyPI - uses: pypa/gh-action-pypi-publish@v1.9.0 + uses: pypa/gh-action-pypi-publish@release/v1 if: github.event_name == 'release' && github.event.action == 'published' - with: - password: ${{ secrets.PYPI_TOKEN }} upload-ccd: From 197a8fc218545e18be13bb361df59abb8ebe41de Mon Sep 17 00:00:00 2001 From: Patrick Kunzmann Date: Mon, 23 Dec 2024 14:27:12 +0100 Subject: [PATCH 2/2] Use preamble also for example gallery --- doc/conf.py | 4 ++-- doc/key.py | 11 ----------- doc/preamble.py | 29 +++++++++++++++++++++++++++++ doc/tutorial/preamble.rst | 24 ++++-------------------- 4 files changed, 35 insertions(+), 33 deletions(-) delete mode 100644 doc/key.py create mode 100644 doc/preamble.py diff --git a/doc/conf.py b/doc/conf.py index d9d511858..eee7fc572 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -30,7 +30,7 @@ sys.path.insert(0, DOC_PATH) import apidoc import bibliography -import key +import preamble import scraper import switcher import viewcode @@ -206,7 +206,7 @@ "backreferences_dir": "examples/backreferences", "doc_module": ("biotite",), # Set the NCBI API key - "reset_modules": (key.set_ncbi_api_key_from_env,), + "reset_modules": (preamble.setup_script), "remove_config_comments": True, } diff --git a/doc/key.py b/doc/key.py deleted file mode 100644 index b7a2b4334..000000000 --- a/doc/key.py +++ /dev/null @@ -1,11 +0,0 @@ -import os - - -def set_ncbi_api_key_from_env(*args, **kwargs): - # Import inside function as Biotite may not be known - # at the time of function definition - import biotite.database.entrez as entrez - - ncbi_api_key = os.environ.get("NCBI_API_KEY") - if ncbi_api_key is not None and ncbi_api_key != "": - entrez.set_api_key(ncbi_api_key) diff --git a/doc/preamble.py b/doc/preamble.py new file mode 100644 index 000000000..93ee07e33 --- /dev/null +++ b/doc/preamble.py @@ -0,0 +1,29 @@ +import os +import numpy as np + + +def setup_script(): + """ + Prepare API keys, formatting, etc. for running a tutorial or example script. + """ + # Import inside function as Biotite may not be known + # at the time of function definition + import biotite.application.blast as blast + import biotite.database.entrez as entrez + + # Improve readability of large arrays + np.set_printoptions(precision=2) + + # Use API key to increase request limit + ncbi_api_key = os.environ.get("NCBI_API_KEY") + if ncbi_api_key is not None and ncbi_api_key != "": + entrez.set_api_key(ncbi_api_key) + + # Mock the BlastWebApp class + # to allow subsequent BLAST calls when building the tutorial + class MockedBlastApp(blast.BlastWebApp): + def __init__(self, *args, **kwargs): + kwargs["obey_rules"] = False + super().__init__(*args, **kwargs) + + blast.BlastWebApp = MockedBlastApp diff --git a/doc/tutorial/preamble.rst b/doc/tutorial/preamble.rst index 14079a70f..710ca0c69 100644 --- a/doc/tutorial/preamble.rst +++ b/doc/tutorial/preamble.rst @@ -1,23 +1,7 @@ -.. jupyter-execute:: +.. jupyter-execute:: /preamble.py :hide-code: - import os - import numpy as np - import biotite.database.entrez as entrez - import biotite.application.blast as blast - - # Improve readability of large arrays - np.set_printoptions(precision=2) - - # Use API key to increase request limit - ncbi_api_key = os.environ.get("NCBI_API_KEY") - if ncbi_api_key is not None and ncbi_api_key != "": - entrez.set_api_key(ncbi_api_key) +.. jupyter-execute:: + :hide-code: - # Mock the BlastWebApp class - # to allow subsequent BLAST calls when building the tutorial - class MockedBlastApp(blast.BlastWebApp): - def __init__(self, *args, **kwargs): - kwargs["obey_rules"] = False - super().__init__(*args, **kwargs) - blast.BlastWebApp = MockedBlastApp \ No newline at end of file + setup_script() \ No newline at end of file