From a1375f9332858dd6d04811aadbfcc693c6e353a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Thu, 2 Jun 2022 13:38:09 -0300 Subject: [PATCH] Update README.rst in post-release (#2037) * Fix docs badge * Add license badge * First attempt of creating credits.rst and README.rst via templates * Working version * Restore old README.rst * Update post-release workflow * Change .gitignore * Various fixes --- .ci-helpers/update_credits.py | 77 +++++++++++++++++++ .github/workflows/post-release.yml | 29 ++++++- .gitignore | 1 - README_TEMPLATE.rst | 56 ++++++++++++++ docs/conf.py | 48 +----------- .../{credits.rst => credits_template.rst} | 2 +- 6 files changed, 163 insertions(+), 50 deletions(-) create mode 100644 .ci-helpers/update_credits.py create mode 100644 README_TEMPLATE.rst rename docs/resources/{credits.rst => credits_template.rst} (99%) diff --git a/.ci-helpers/update_credits.py b/.ci-helpers/update_credits.py new file mode 100644 index 00000000000..847df1e2eee --- /dev/null +++ b/.ci-helpers/update_credits.py @@ -0,0 +1,77 @@ +"""Script for updating `credits.rst` and `README.rst` between releases, +requires the `rst-include` package""" + +import pathlib +import re +import textwrap +import warnings + +import requests +from rst_include import rst_include + + +def generate_zenodo(): + """Generates `zenodo.rst` file with BibTeX citation + Adapted from: https://astrodata.nyc/posts/2021-04-23-zenodo-sphinx/""" + + CONCEPT_DOI = "592480" # See: https://help.zenodo.org/#versioning + zenodo_path = pathlib.Path("docs/resources/zenodo.rst") + + try: + headers = {"accept": "application/x-bibtex"} + response = requests.get( + f"https://zenodo.org/api/records/{CONCEPT_DOI}", headers=headers + ) + response.encoding = "utf-8" + citation = re.findall("@software{(.*)\,", response.text) + zenodo_record = ( + f".. |ZENODO| replace:: {citation[0]}\n\n" + ".. code-block:: bibtex\n\n" + + textwrap.indent(response.text, " " * 4) + ) + + except Exception as e: + warnings.warn( + "Failed to retrieve Zenodo record for TARDIS: " f"{str(e)}" + ) + + not_found_msg = """ + Couldn"t retrieve the TARDIS software citation from Zenodo. Get it + directly from `this link `_ . + """ + + zenodo_record = ( + ".. |ZENODO| replace:: \n\n" + ".. warning:: \n\n" + textwrap.indent(not_found_msg, " " * 4) + ) + + with open(zenodo_path, "w") as f: + f.write(zenodo_record) + + print(zenodo_record) + + +def main(): + generate_zenodo() + + rst_include.include( + source="docs/resources/credits_template.rst", + target="docs/resources/credits.rst", + quiet=False, + inplace=False, + source_encoding="utf-8", + target_encoding="utf-8", + ) + + rst_include.include( + source="README_TEMPLATE.rst", + target="README.rst", + quiet=False, + inplace=False, + source_encoding="utf-8", + target_encoding="utf-8", + ) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/post-release.yml b/.github/workflows/post-release.yml index c566836db8b..27fa47b495d 100644 --- a/.github/workflows/post-release.yml +++ b/.github/workflows/post-release.yml @@ -37,7 +37,7 @@ jobs: - uses: actions/checkout@v2 - name: Wait for Zenodo webhook - run: sleep 120 + run: sleep 180 - name: Setup Python uses: actions/setup-python@v3 @@ -57,6 +57,32 @@ jobs: name: citation path: CITATION.cff + credits: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Wait for Zenodo webhook + run: sleep 180 + + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + + - name: Install rst-include + run: pip install rst-include requests + + - name: Update README.rst + run: python .ci-helpers/update_credits.py + + - uses: actions/upload-artifact@v3 + with: + name: credits + path: | + README.rst + docs/resources/credits.rst + pull_request: needs: [changelog, citation] runs-on: ubuntu-latest @@ -71,6 +97,7 @@ jobs: run: | cp /tmp/changelog/CHANGELOG.md . cp /tmp/citation/CITATION.cff . + cp -r /tmp/credits/* . - name: Get current date run: echo "DATE=$(date +'%Y.%m.%d')" >> $GITHUB_ENV diff --git a/.gitignore b/.gitignore index 95b55b93422..6dd3f261c4a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,6 @@ MANIFEST # Sphinx docs/api docs/_build -docs/resources/ZENODO.rst docs/tutorials.rst docs/io/configuration/components/models/converters/density_parse.csv docs/io/configuration/components/models/converters/abund_parse.csv diff --git a/README_TEMPLATE.rst b/README_TEMPLATE.rst new file mode 100644 index 00000000000..2310b633728 --- /dev/null +++ b/README_TEMPLATE.rst @@ -0,0 +1,56 @@ +====== +TARDIS +====== + +.. image:: https://img.shields.io/badge/Donate-to%20TARDIS-brightgreen.svg + :target: https://numfocus.salsalabs.org/donate-to-tardis/index.html + +.. image:: https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A + :target: http://numfocus.org + +.. image:: https://badges.gitter.im/Join%20Chat.svg + :target: https://gitter.im/tardis-sn/tardis + +.. image:: https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc + :target: https://open.vscode.dev/tardis-sn/tardis +| + +TARDIS is a tool that creates synthetic observations (*spectra*) for exploding +stars (*supernovae*). + +.. image:: https://codecov.io/gh/tardis-sn/tardis/branch/master/graph/badge.svg + :target: https://codecov.io/gh/tardis-sn/tardis + +.. image:: https://img.shields.io/endpoint?url=https://jsonbin.org/tardis-bot/tardis/badges/docstr-cov + :target: https://github.com/tardis-sn/tardis/actions/workflows/docstr-cov.yml?query=branch%3Amaster + +.. image:: https://github.com/tardis-sn/tardis/actions/workflows/tests.yml/badge.svg + :target: https://github.com/tardis-sn/tardis/actions/workflows/tests.yml + +.. image:: https://github.com/tardis-sn/tardis/actions/workflows/build-docs.yml/badge.svg + :target: https://tardis-sn.github.io/tardis/index.html + +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black +| + + +.. include:: docs/resources/credits.rst + + +******* +License +******* + +.. image:: https://img.shields.io/conda/l/conda-forge/tardis-sn + :target: https://github.com/tardis-sn/tardis/blob/master/licenses/LICENSE.rst + +.. image:: http://img.shields.io/badge/powered%20by-AstroPy-orange.svg?style=flat + :target: http://www.astropy.org +| + +This project is Copyright (c) TARDIS Collaboration and licensed under +the terms of the BSD 3-Clause license. This package is based upon +the `Astropy package template `_ +which is licensed under the BSD 3-clause license. See the licenses folder for +more information. diff --git a/docs/conf.py b/docs/conf.py index 39c5183c6c7..48d98edf89b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -63,6 +63,7 @@ # directories to ignore when looking for source files. exclude_patterns.append("_templates") exclude_patterns.append("_build") +exclude_patterns.append("**_template.rst") exclude_patterns.append("**.ipynb_checkpoints") exclude_patterns.append("resources/research_done_using_TARDIS/ads.ipynb") @@ -334,54 +335,8 @@ # -- Sphinx hook-ins --------------------------------------------------------- -import re -import pathlib -import requests -import textwrap -import warnings from shutil import copyfile - -def generate_ZENODO(app): - """Creating ZENODO.rst - Adapted from: https://astrodata.nyc/posts/2021-04-23-zenodo-sphinx/""" - CONCEPT_DOI = "592480" # See: https://help.zenodo.org/#versioning - zenodo_path = pathlib.Path("resources/ZENODO.rst") - - try: - headers = {"accept": "application/x-bibtex"} - response = requests.get( - f"https://zenodo.org/api/records/{CONCEPT_DOI}", headers=headers - ) - response.encoding = "utf-8" - citation = re.findall("@software{(.*)\,", response.text) - zenodo_record = ( - f".. |ZENODO| replace:: {citation[0]}\n\n" - ".. code-block:: bibtex\n\n" - + textwrap.indent(response.text, " " * 4) - ) - - except Exception as e: - warnings.warn( - "Failed to retrieve Zenodo record for TARDIS: " f"{str(e)}" - ) - - not_found_msg = """ - Couldn"t retrieve the TARDIS software citation from Zenodo. Get it - directly from `this link `_ . - """ - - zenodo_record = ( - ".. |ZENODO| replace:: \n\n" - ".. warning:: \n\n" + textwrap.indent(not_found_msg, " " * 4) - ) - - with open(zenodo_path, "w") as f: - f.write(zenodo_record) - - print(zenodo_record) - - def generate_tutorials_page(app): """Create tutorials.rst""" notebooks = "" @@ -434,7 +389,6 @@ def create_redirect_files(app, docname): def setup(app): - app.connect("builder-inited", generate_ZENODO) app.connect("builder-inited", generate_tutorials_page) app.connect("autodoc-skip-member", autodoc_skip_member) app.connect("build-finished", create_redirect_files) diff --git a/docs/resources/credits.rst b/docs/resources/credits_template.rst similarity index 99% rename from docs/resources/credits.rst rename to docs/resources/credits_template.rst index c57155d375c..493261e08f9 100644 --- a/docs/resources/credits.rst +++ b/docs/resources/credits_template.rst @@ -72,4 +72,4 @@ The following BibTeX entries are needed for the references: adsnote = {Provided by the SAO/NASA Astrophysics Data System} } -.. include:: ZENODO.rst +.. include:: zenodo.rst