From e16f1ead56c4d31b2c1ade15c445330c50d4980d Mon Sep 17 00:00:00 2001 From: Rune Michael Dominik Date: Wed, 11 Jan 2023 13:02:01 +0100 Subject: [PATCH 1/7] Add towncrier as github action --- .github/workflows/ci.yml | 6 +++++- docs/changes/README.md | 22 ++++++++++++++++++++ docs/changes/template.rst | 43 +++++++++++++++++++++++++++++++++++++++ environment.yml | 1 + pyproject.toml | 32 +++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 docs/changes/README.md create mode 100644 docs/changes/template.rst diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5339bca58..370aa83a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,11 +58,15 @@ jobs: - name: Install doc dependencies run: | sudo apt update --yes && sudo apt install --yes git build-essential pandoc curl graphviz - pip install -U pip setuptools wheel + pip install -U pip setuptools wheel towncrier pip install -e .[docs] git describe --tags python -c 'import pyirf; print(pyirf.__version__)' + - name: Produce Changelog + run: | + towncrier build --yes + - name: Build docs run: cd docs && make html SPHINXOPTS="-W --keep-going -n --color -j auto" diff --git a/docs/changes/README.md b/docs/changes/README.md new file mode 100644 index 000000000..f3578f739 --- /dev/null +++ b/docs/changes/README.md @@ -0,0 +1,22 @@ +# How to use `towncrier` + +A tutorial can be found [here](https://towncrier.readthedocs.io/en/stable/tutorial.html). + +1. Create a new file for your changes `..rst` in the corresponding folder. The following types are available: + - feature: `New feature` + - bugfix: `Bugfix` + - api: `API Changes` + - optimization: `Refactoring and Optimization` + - maintenance: `Maintenance` + + +2. Write a suitable message for the change: + ``` + Fixed ``crazy_function`` to be consistent with ``not_so_crazy_function`` + ``` + +3. (For maintainers) How to generate a change log: + - Execute the following command in the base directory of the project + ``` + towncrier build --version= + ``` diff --git a/docs/changes/template.rst b/docs/changes/template.rst new file mode 100644 index 000000000..1fdc15948 --- /dev/null +++ b/docs/changes/template.rst @@ -0,0 +1,43 @@ +{% if render_title %} +{% if versiondata.name %} +{{ versiondata.name }} {{ versiondata.version }} ({{ versiondata.date }}) +{{ top_underline * ((versiondata.name + versiondata.version + versiondata.date)|length + 4)}} +{% else %} +{{ versiondata.version }} ({{ versiondata.date }}) +{{ top_underline * ((versiondata.version + versiondata.date)|length + 3)}} +{% endif %} +{% endif %} + +{% for category, val in definitions.items() %} + +{% set underline = underlines[0] %} +{{ definitions[category]['name'] }} +{{ underline * definitions[category]['name']|length }} +{% set underline = underlines[1] %} + +{% for section, _ in sections.items() %} +{% if section and category in sections[section] %} +{{section}} +{{ underline * section|length }} + +{% endif %} +{% if sections[section] and category in sections[section] %} +{% if definitions[category]['showcontent'] %} +{% for text, values in sections[section][category].items() %} +- {{ text }} [{{ values|join(', ') }}] + +{% endfor %} +{% else %} +- {{ sections[section][category]['']|join(', ') }} + +{% endif %} +{% if sections[section][category]|length == 0 %} +No significant changes. + +{% else %} +{% endif %} +{% else %} +{# No significant changes. #} +{% endif %} +{% endfor %} +{% endfor %} \ No newline at end of file diff --git a/environment.yml b/environment.yml index 7f986b5ad..709a47776 100644 --- a/environment.yml +++ b/environment.yml @@ -17,6 +17,7 @@ dependencies: - pytest - pytest-cov # docs + - towncrier - numpydoc - pytables - nbsphinx diff --git a/pyproject.toml b/pyproject.toml index 59727c9dd..51f3b9859 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,35 @@ [build-system] requires = ["setuptools >= 40.6.0", "setuptools_scm[toml]>=3.4"] build-backend = "setuptools.build_meta" + +[tool.towncrier] + package = "pyirf" + directory = "docs/changes" + filename = "CHANGES.rst" + template = "docs/changes/template.rst" + # let towncrier create proper links to the merged PR + issue_format = "`#{issue} `__" + + [tool.towncrier.fragment.feature] + name = "New Features" + showcontent = true + + [tool.towncrier.fragment.bugfix] + name = "Bug Fixes" + showcontent = true + + [tool.towncrier.fragment.api] + name = "API Changes" + showcontent = true + + [tool.towncrier.fragment.optimization] + name = "Refactoring and Optimization" + showcontent = true + + [tool.towncrier.fragment.maintenance] + name = "Maintenance" + showcontent = true + + [[tool.towncrier.section]] + name = "" + path = "" \ No newline at end of file From 63109da92799ae00dceb656708770898fc211262 Mon Sep 17 00:00:00 2001 From: Rune Michael Dominik Date: Wed, 11 Jan 2023 13:02:25 +0100 Subject: [PATCH 2/7] Add section on towncrier to how-to contribute --- docs/contribute.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/contribute.rst b/docs/contribute.rst index 6db029416..c35121715 100644 --- a/docs/contribute.rst +++ b/docs/contribute.rst @@ -44,6 +44,10 @@ See the `GitHub tutorial on forks Date: Wed, 11 Jan 2023 14:14:01 +0100 Subject: [PATCH 3/7] Add newsfragments for old changes for testing --- docs/changes/180.feature.rst | 2 ++ docs/changes/200.bugfix.rst | 1 + docs/changes/202.maintenance.rst | 1 + 3 files changed, 4 insertions(+) create mode 100644 docs/changes/180.feature.rst create mode 100644 docs/changes/200.bugfix.rst create mode 100644 docs/changes/202.maintenance.rst diff --git a/docs/changes/180.feature.rst b/docs/changes/180.feature.rst new file mode 100644 index 000000000..333301ea2 --- /dev/null +++ b/docs/changes/180.feature.rst @@ -0,0 +1,2 @@ +Add interpolation function for RAD_MAX tables. +There is now a ``interpolate_rad_max`` function in ``pyirf.interpolation`` that is a simple wrapper around ``scipy.interpolate.griddata``. \ No newline at end of file diff --git a/docs/changes/200.bugfix.rst b/docs/changes/200.bugfix.rst new file mode 100644 index 000000000..aa3135ceb --- /dev/null +++ b/docs/changes/200.bugfix.rst @@ -0,0 +1 @@ +Units are now correctly handled in ``pyirf.spectral.PowerLaw``. \ No newline at end of file diff --git a/docs/changes/202.maintenance.rst b/docs/changes/202.maintenance.rst new file mode 100644 index 000000000..ce956f9f9 --- /dev/null +++ b/docs/changes/202.maintenance.rst @@ -0,0 +1 @@ +Updates ``gammapy`` dependency to version 1. \ No newline at end of file From b10c4a5d391ff4179f1e4747a4b3a42d534d9cbf Mon Sep 17 00:00:00 2001 From: Rune Michael Dominik Date: Wed, 11 Jan 2023 14:16:18 +0100 Subject: [PATCH 4/7] Add changelog --- docs/changes/207.maintenance.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/207.maintenance.rst diff --git a/docs/changes/207.maintenance.rst b/docs/changes/207.maintenance.rst new file mode 100644 index 000000000..8003e15c5 --- /dev/null +++ b/docs/changes/207.maintenance.rst @@ -0,0 +1 @@ +Add and enable ``towncrier`` in CI. \ No newline at end of file From ef407f953ce6bbb77a263273f0fae742b6a92223 Mon Sep 17 00:00:00 2001 From: Rune Michael Dominik Date: Wed, 11 Jan 2023 15:07:01 +0100 Subject: [PATCH 5/7] Exclude changes dir from source-files search, reformat README --- docs/changes/README.md | 1 - docs/conf.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/changes/README.md b/docs/changes/README.md index f3578f739..acd0ce78c 100644 --- a/docs/changes/README.md +++ b/docs/changes/README.md @@ -9,7 +9,6 @@ A tutorial can be found [here](https://towncrier.readthedocs.io/en/stable/tutori - optimization: `Refactoring and Optimization` - maintenance: `Maintenance` - 2. Write a suitable message for the change: ``` Fixed ``crazy_function`` to be consistent with ``not_so_crazy_function`` diff --git a/docs/conf.py b/docs/conf.py index cd21ce74e..dbab33d87 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -72,7 +72,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "changes"] # -- Options for HTML output ------------------------------------------------- From d465f81a7f3f3da60ba47d0f6b19133dc4392343 Mon Sep 17 00:00:00 2001 From: Rune Michael Dominik Date: Wed, 11 Jan 2023 15:07:24 +0100 Subject: [PATCH 6/7] Create changelog CI job --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 370aa83a5..8e6a7cbd4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,7 @@ on: [push, pull_request] env: MPLBACKEND: Agg PYTEST_ADDOPTS: --color=yes + GITHUB_PR_NUMBER: ${{ github.event.number }} jobs: tests: @@ -80,3 +81,19 @@ jobs: FOLDER: docs/_build/html CLEAN: true SINGLE_COMMIT: true + + changelog: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set environment + run: echo FRAGMENT_NAME="docs/changes/${GITHUB_PR_NUMBER}.*.rst" >> $GITHUB_ENV + + - name: Check for news fragment + uses: andstor/file-existence-action@v2 + with: + files: ${{ env.FRAGMENT_NAME }} + fail: true \ No newline at end of file From dc1d39f9d74cf31944ce162a15104f53093196ab Mon Sep 17 00:00:00 2001 From: Rune Michael Dominik Date: Fri, 20 Jan 2023 14:21:06 +0100 Subject: [PATCH 7/7] Limit push actions to master --- .github/workflows/ci.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e6a7cbd4..fa8fa21bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,12 @@ name: CI -on: [push, pull_request] +on: + push: + branches: + - master + tags: + - '**' + pull_request: env: MPLBACKEND: Agg @@ -96,4 +102,4 @@ jobs: uses: andstor/file-existence-action@v2 with: files: ${{ env.FRAGMENT_NAME }} - fail: true \ No newline at end of file + fail: true