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

Add toml and yaml formatters to pre-commit #121

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
72 changes: 36 additions & 36 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,47 @@ jobs:
strategy:
matrix:
context:
- {project_name: testing-123}
- {project_name: testing-123-with-docs, docs: true}
- {project_name: testing-123}
- {project_name: testing-123-with-docs, docs: true}

name: ${{ matrix.context.project_name }}
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup nox
uses: wntrblm/[email protected]
with:
python-versions: "3.8, 3.9, 3.10, 3.11, pypy-3.8, pypy-3.9"
- name: Setup nox
uses: wntrblm/[email protected]
with:
python-versions: "3.8, 3.9, 3.10, 3.11, pypy-3.8, pypy-3.9"

- name: Generate template via cruft
run: |
pip install cruft
cruft create -y --extra-context '${{ toJSON(matrix.context) }}' .
- name: Generate template via cruft
run: |
pip install cruft
cruft create -y --extra-context '${{ toJSON(matrix.context) }}' .

- name: Show directory structure and file contents
run: |
cd ${{ matrix.context.project_name }}
echo "::group::tree" && tree -a && echo "::endgroup::"
echo "::group::.cruft.json" && cat .cruft.json && echo "::endgroup::"
echo "::group::pyproject.toml" && cat pyproject.toml && echo "::endgroup::"
echo "::group::CONTRIBUTING.rst" && cat CONTRIBUTING.rst && echo "::endgroup::"
echo "::group::noxfile.py" && cat noxfile.py && echo "::endgroup::"
echo "::group::tests.yml" && cat .github/workflows/tests.yml && echo "::endgroup::"
- name: Show directory structure and file contents
run: |
cd ${{ matrix.context.project_name }}
echo "::group::tree" && tree -a && echo "::endgroup::"
echo "::group::.cruft.json" && cat .cruft.json && echo "::endgroup::"
echo "::group::pyproject.toml" && cat pyproject.toml && echo "::endgroup::"
echo "::group::CONTRIBUTING.rst" && cat CONTRIBUTING.rst && echo "::endgroup::"
echo "::group::noxfile.py" && cat noxfile.py && echo "::endgroup::"
echo "::group::tests.yml" && cat .github/workflows/tests.yml && echo "::endgroup::"

- name: Initialize repository
run: |
cd ${{ matrix.context.project_name }}
git init
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "init"
- name: Initialize repository
run: |
cd ${{ matrix.context.project_name }}
git init
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "init"

- name: Run nox
run: |
cd ${{ matrix.context.project_name }}
nox
nox -s lint safety build dev ${{ matrix.context.docs && 'docs'}}
- name: Run nox
run: |
cd ${{ matrix.context.project_name }}
nox
nox -s lint safety build dev ${{ matrix.context.docs && 'docs'}}
110 changes: 55 additions & 55 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,67 @@ inputs:
runs:
using: composite
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install cruft
shell: bash
run: pip install cruft==2.15.0 # renovate: datasource=pypi
- name: Install cruft
shell: bash
run: pip install cruft==2.15.0 # renovate: datasource=pypi

- name: Update template via cruft
shell: bash
id: cruft
run: |
echo "template=$(cat .cruft.json | jq '.template' -r)" >> $GITHUB_OUTPUT
echo "old_commit=$(cat .cruft.json | jq '.commit' -r)" >> $GITHUB_OUTPUT
cruft update -y
echo "new_commit=$(cat .cruft.json | jq '.commit' -r)" >> $GITHUB_OUTPUT
- name: Update template via cruft
shell: bash
id: cruft
run: |
echo "template=$(cat .cruft.json | jq '.template' -r)" >> $GITHUB_OUTPUT
echo "old_commit=$(cat .cruft.json | jq '.commit' -r)" >> $GITHUB_OUTPUT
cruft update -y
echo "new_commit=$(cat .cruft.json | jq '.commit' -r)" >> $GITHUB_OUTPUT

- name: Check current state
shell: bash
run: |
git status --untracked-files=all
git diff
- name: Check current state
shell: bash
run: |
git status --untracked-files=all
git diff

- name: Try to apply reject hunks
shell: bash
id: apply-rejects
run: |
for reject in $(git ls-files --others --exclude-standard '*.rej'); do
file=${reject%.rej}
cat ${reject}
patch -p1 --merge --no-backup-if-mismatch ${file} < ${reject} || echo " - \`${file}\`" >> /tmp/conflicts
rm ${reject}
echo
- name: Try to apply reject hunks
shell: bash
id: apply-rejects
run: |
for reject in $(git ls-files --others --exclude-standard '*.rej'); do
file=${reject%.rej}
cat ${reject}
patch -p1 --merge --no-backup-if-mismatch ${file} < ${reject} || echo " - \`${file}\`" >> /tmp/conflicts
rm ${reject}
echo

echo 'conflicts<<EOF' >> $GITHUB_OUTPUT
test -f /tmp/conflicts && cat /tmp/conflicts >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
done
echo 'conflicts<<EOF' >> $GITHUB_OUTPUT
test -f /tmp/conflicts && cat /tmp/conflicts >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
done

- name: Check diff
id: diff
shell: bash
run: |
git status --untracked-files=all
echo 'changes<<EOF' >> $GITHUB_OUTPUT
git diff >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Check diff
id: diff
shell: bash
run: |
git status --untracked-files=all
echo 'changes<<EOF' >> $GITHUB_OUTPUT
git diff >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT

- name: Create PR
if: ${{ steps.diff.outputs.changes != '' }}
uses: peter-evans/create-pull-request@v5
with:
token: ${{ inputs.token }}
commit-message: update template
title: update template
draft: true
body: |
Automated changes to update template with ${{ steps.cruft.outputs.template }}.
- name: Create PR
if: ${{ steps.diff.outputs.changes != '' }}
uses: peter-evans/create-pull-request@v5
with:
token: ${{ inputs.token }}
commit-message: update template
title: update template
draft: true
body: |
Automated changes to update template with ${{ steps.cruft.outputs.template }}.

${{ steps.apply-rejects.outputs.conflicts != '' && 'There may be merge conflicts in these files that may need to be resolved manually:' || '' }}
${{ steps.apply-rejects.outputs.conflicts }}
${{ steps.apply-rejects.outputs.conflicts != '' && 'There may be merge conflicts in these files that may need to be resolved manually:' || '' }}
${{ steps.apply-rejects.outputs.conflicts }}

__See Changelog__: ${{ steps.cruft.outputs.template }}/compare/${{ steps.cruft.outputs.old_commit }}...${{ steps.cruft.outputs.new_commit }}.
__See Changelog__: ${{ steps.cruft.outputs.template }}/compare/${{ steps.cruft.outputs.old_commit }}...${{ steps.cruft.outputs.new_commit }}.
36 changes: 18 additions & 18 deletions {{cookiecutter.project_name}}/.github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ jobs:
id-token: write
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Upgrade pip and nox
run: |
pip install --upgrade pip nox
pip --version
nox --version
- name: Upgrade pip and nox
run: |
pip install --upgrade pip nox
pip --version
nox --version

- name: Build package
run: nox -s build
- name: Build package
run: nox -s build

- name: Upload package
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
- name: Upload package
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
49 changes: 25 additions & 24 deletions {{cookiecutter.project_name}}/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,38 @@ jobs:
os: [ubuntu-20.04, windows-latest, macos-latest]
pyv: ['3.8', '3.9', '3.10', '3.11']
include:
- {os: ubuntu-latest, pyv: 'pypy3.8'}
- {os: ubuntu-latest, pyv: 'pypy3.8'}

steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python {% raw %}${{ matrix.pyv }}{% endraw %}
uses: actions/setup-python@v5
with:
python-version: {% raw %}${{ matrix.pyv }}{% endraw %}
- name: Set up Python {% raw %}${{ matrix.pyv }}{% endraw %}
uses: actions/setup-python@v5
with:
python-version: {% raw %}${{ matrix.pyv }}{% endraw %}

- name: Upgrade pip and nox
run: |
python -m pip install --upgrade pip nox
pip --version
nox --version
- name: Upgrade pip and nox
run: |
python -m pip install --upgrade pip nox
pip --version
nox --version

- name: Lint code and check dependencies
run: nox -s lint safety
- name: Lint code and check dependencies
run: nox -s lint safety

- name: Run tests
run: nox -s tests-{% raw %}${{ matrix.nox_pyv || matrix.pyv }}{% endraw %} -- --cov-report=xml
- name: Run tests
run: nox -s tests-{% raw %}${{ matrix.nox_pyv || matrix.pyv }}{% endraw %} -- --cov-report=xml

- name: Upload coverage report
uses: codecov/codecov-action@v3
- name: Upload coverage report
uses: codecov/codecov-action@v3

- name: Build package
run: nox -s build

- name: Build package
run: nox -s build
{% if cookiecutter.docs != "False" %}
- name: Build docs
run: nox -s docs
- name: Build docs
run: nox -s docs
{% endif -%}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4
- name: Check out the repository
uses: actions/checkout@v4

- name: Update template
uses: iterative/py-template@main
- name: Update template
uses: iterative/py-template@main
7 changes: 7 additions & 0 deletions {{cookiecutter.project_name}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ repos:
hooks:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
hooks:
- id: pretty-format-toml
args: [--autofix, --no-sort]
- id: pretty-format-yaml
args: [--autofix, --indent, '2', '--offset', '2', --preserve-quotes]
24 changes: 12 additions & 12 deletions {{cookiecutter.project_name}}/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ extra:
link: https://github.com/iterative/

plugins:
- search
- gen-files:
scripts:
- docs/gen_ref_pages.py
- section-index
- mkdocstrings:
handlers:
python:
rendering:
show_submodules: no
watch:
- src/{{cookiecutter.package_name}}
- search
- gen-files:
scripts:
- docs/gen_ref_pages.py
- section-index
- mkdocstrings:
handlers:
python:
rendering:
show_submodules: no
watch:
- src/{{cookiecutter.package_name}}
Loading
Loading