Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of Cruft support #45

Merged
merged 10 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/sub_package_update.yml
Cadair marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Update SunPy Sub Packages
permissions:
contents: write
pull-requests: write

on:
pull_request:
branches:
main
jobs:
update:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
include:
- add-paths: .
body: Use this to merge the changes to the repo
branch: cruft/update
commit-message: "SunPy package template update"
title: New Updates to SunPy Template
- add-paths: .cruft.json
body: Use this to reject changes in the repo
branch: cruft/reject
commit-message: "Chore: reject this cruft update"
title: Reject new SunPy template updates

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install Cruft
run: pip3 install cruft

- name: Check if update is available
continue-on-error: false
id: check
run: |
CHANGES=0
if [ -f .cruft.json ]; then
if ! cruft check; then
CHANGES=1
fi
else
echo "No .cruft.json file"
fi

echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT"

- name: Run update if available
if: steps.check.outputs.has_changes == '1'
# this needs to be sunpy details I think?
run: |
git config --global user.email ""
git config --global user.name "SunPy Org"

cruft update --skip-apply-ask --refresh-private-variables
git restore --staged

- name: Create pull request
if: steps.check.output.has_changes == '1'
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: ${{ matrix.add-paths }}
commit-message: ${{ matrix.commit-message }}
branch: ${{ matrix.branch }}
delete-branch: true
branch-suffix: timestamp
title: ${{ matrix.title }}
body: |
This is an autogenerated PR. ${{ matrix.body }}
[Cruft](https://cruft.github.io/cruft/) has detected updates from the SunPy Package Template

3 changes: 2 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"_install_requires": "",
"_copy_without_render": [
"docs/_templates",
"docs/_static"
"docs/_static",
".github/workflows/sub_package_update.yml"
]
}
16 changes: 15 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ Using the Template

With this guide is a `cookiecutter <https://cookiecutter.readthedocs.io/>`__ template which allows you to get started quickly with a package as described in this guide.

To get started run:
To create a new package based on the template run:

.. code-block:: console
$ pip install cookiecutter cruft
CyclingNinja marked this conversation as resolved.
Show resolved Hide resolved
CyclingNinja marked this conversation as resolved.
Show resolved Hide resolved
$ cruft create https://github.com/OpenAstronomy/packaging-guide

and go through the steps offered in the cli naming your package and filling in your details.
Cruft is built on cookiecutter, and enables the updating of the template from the source.
This takes the form of pull requests to the repository that the new package is pushed to.
If a package already has a cookiecutter template, it can be linked to the parent repository using ``cruft link url-to-template``.

To manually check whether the current environment matches with the template then ``cruft check`` will tell you what the current status is.
``cruft update`` will manually trigger an updating of the package to the template.

If you would like to stick to simply the cookiecutter approach, the template still supports that functionality thusly:

.. code-block:: console

Expand Down
CyclingNinja marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Update SunPy Sub Packages
permissions:
contents: write
pull-requests: write

on:
pull_request:
branches:
main
jobs:
update:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
include:
- add-paths: .
body: Use this to merge the changes to the repo
branch: cruft/update
commit-message: "SunPy package template update"
title: New Updates to SunPy Template
- add-paths: .cruft.json
body: Use this to reject changes in the repo
branch: cruft/reject
commit-message: "Chore: reject this cruft update"
title: Reject new SunPy template updates

steps:
- uses: actions/checkout@v3
CyclingNinja marked this conversation as resolved.
Show resolved Hide resolved

- uses: actions/setup-python@v4
CyclingNinja marked this conversation as resolved.
Show resolved Hide resolved
with:
python-version: "3.10"
CyclingNinja marked this conversation as resolved.
Show resolved Hide resolved

- name: Install Cruft
run: pip3 install cruft

- name: Check if update is available
continue-on-error: false
id: check
run: |
CHANGES=0
if [ -f .cruft.json ]; then
if ! cruft check; then
CHANGES=1
fi
else
echo "No .cruft.json file"
fi

echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT"

- name: Run update if available
if: steps.check.outputs.has_changes == '1'
# this needs to be sunpy details I think?
CyclingNinja marked this conversation as resolved.
Show resolved Hide resolved
run: |
git config --global user.email ""
git config --global user.name "SunPy Org"
Cadair marked this conversation as resolved.
Show resolved Hide resolved

cruft update --skip-apply-ask --refresh-private-variables
git restore --staged

- name: Create pull request
if: steps.check.output.has_changes == '1'
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: ${{ matrix.add-paths }}
commit-message: ${{ matrix.commit-message }}
branch: ${{ matrix.branch }}
delete-branch: true
branch-suffix: timestamp
title: ${{ matrix.title }}
body: |
This is an autogenerated PR. ${{ matrix.body }}
[Cruft](https://cruft.github.io/cruft/) has detected updates from the SunPy Package Template

5 changes: 5 additions & 0 deletions {{ cookiecutter.package_name }}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
{%- if cookiecutter.enable_dynamic_dev_versions == 'y' %}
{{ cookiecutter.module_name }}/_version.py
{% else %}
{{ cookiecutter.module_name }}/version.py
{% endif -%}

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
4 changes: 2 additions & 2 deletions {{ cookiecutter.package_name }}/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ prune build
prune docs/_build
prune docs/api
global-exclude *.pyc *.o
{% if cookiecutter.enable_dynamic_dev_versions == 'y' %}
{%- if cookiecutter.enable_dynamic_dev_versions == 'y' %}

# This subpackage is only used in development checkouts
# and should not be included in built tarballs
prune {{ cookiecutter.module_name }}/_dev
{% endif %}
{% endif -%}
14 changes: 7 additions & 7 deletions {{ cookiecutter.package_name }}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = [
"setuptools>=61.2",
"setuptools>=62.1",
"setuptools_scm[toml]>=6.2",
"wheel",
{% if cookiecutter.use_compiled_extensions == 'y' %}
Expand Down Expand Up @@ -38,15 +38,15 @@ docs = [
"tomli; python_version <\"3.11\"",
]

{% if cookiecutter.include_example_code == 'y' %}
{%0 if cookiecutter.include_example_code == 'y' %}
Cadair marked this conversation as resolved.
Show resolved Hide resolved
[project.scripts]
astropy_package_template_example = "{{ cookiecutter.module_name }}.example_mod:main"
{% endif %}
{% endif -%}

{% if cookiecutter.project_url %}
{%- if cookiecutter.project_url %}
[project.urls]
repository = "{{ cookiecutter.project_url }}"
{% endif %}
{% endif -%}

[tool.setuptools]
zip-safe = false
Expand All @@ -55,11 +55,11 @@ include-package-data = true
[tool.setuptools.packages.find]

[tool.setuptools_scm]
{% if cookiecutter.enable_dynamic_dev_versions == 'y' %}
{%- if cookiecutter.enable_dynamic_dev_versions == 'y' %}
write_to = "{{ cookiecutter.module_name }}/_version.py"
{% else %}
write_to = "{{ cookiecutter.module_name }}/version.py"
{% endif %}
{% endif -%}


[tool.pytest.ini_options]
Expand Down
8 changes: 4 additions & 4 deletions {{ cookiecutter.package_name }}/setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python
from setuptools import setup
{% if cookiecutter.use_compiled_extensions == 'y' %}
{%- if cookiecutter.use_compiled_extensions == 'y' %}
from extension_helpers import get_extensions
{% endif %}
{% endif -%}

{%- if cookiecutter.use_compiled_extensions == 'y' %}
setup(
{% if cookiecutter.use_compiled_extensions == 'y' %}
ext_modules=get_extensions()
{% endif %}
)
{% endif -%}
Cadair marked this conversation as resolved.
Show resolved Hide resolved
Loading