Skip to content

Commit

Permalink
Update README.rst in post-release (tardis-sn#2037)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
epassaro committed Jun 2, 2022
1 parent 53ab7d9 commit 66b24f8
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 50 deletions.
77 changes: 77 additions & 0 deletions .ci-helpers/update_credits.py
Original file line number Diff line number Diff line change
@@ -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 <https://zenodo.org/record/{CONCEPT_DOI}>`_ .
"""

zenodo_record = (
".. |ZENODO| replace:: <TARDIS SOFTWARE CITATION HERE> \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()
29 changes: 28 additions & 1 deletion .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions README_TEMPLATE.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/astropy/package-template>`_
which is licensed under the BSD 3-clause license. See the licenses folder for
more information.
48 changes: 1 addition & 47 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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 <https://zenodo.org/record/{CONCEPT_DOI}>`_ .
"""

zenodo_record = (
".. |ZENODO| replace:: <TARDIS SOFTWARE CITATION HERE> \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 = ""
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 66b24f8

Please sign in to comment.