From 7a22ca8d95b396e3de0b26285f5e71309d5a8189 Mon Sep 17 00:00:00 2001 From: AlexandreKempf Date: Thu, 8 Feb 2024 18:49:46 +0100 Subject: [PATCH 1/2] add toml and yaml formatters to pre-commit --- {{cookiecutter.project_name}}/.pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/{{cookiecutter.project_name}}/.pre-commit-config.yaml index 6c523f2..51d22fe 100644 --- a/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -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] + - id: pretty-format-yaml + args: [--autofix, --indent, '2', '--offset', '2', --preserve-quotes] \ No newline at end of file From 4a27c3a72ceff93c2147435e7138af80d8d2b0c4 Mon Sep 17 00:00:00 2001 From: AlexandreKempf Date: Fri, 9 Feb 2024 08:55:37 +0100 Subject: [PATCH 2/2] preformat yaml and toml of the futur repo --- .github/workflows/tests.yml | 72 ++++++------ action.yml | 110 +++++++++--------- .../.github/workflows/release.yml | 36 +++--- .../.github/workflows/tests.yml | 49 ++++---- .../.github/workflows/update-template.yaml | 8 +- .../.pre-commit-config.yaml | 4 +- {{cookiecutter.project_name}}/mkdocs.yml | 24 ++-- {{cookiecutter.project_name}}/pyproject.toml | 72 ++++++------ 8 files changed, 188 insertions(+), 187 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d209c41..7f12106 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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/nox@2023.04.22 - with: - python-versions: "3.8, 3.9, 3.10, 3.11, pypy-3.8, pypy-3.9" + - name: Setup nox + uses: wntrblm/nox@2023.04.22 + 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'}} diff --git a/action.yml b/action.yml index 4a27ed1..81b58f4 100644 --- a/action.yml +++ b/action.yml @@ -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<> $GITHUB_OUTPUT - test -f /tmp/conflicts && cat /tmp/conflicts >> $GITHUB_OUTPUT - echo 'EOF' >> $GITHUB_OUTPUT - done + echo 'conflicts<> $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<> $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<> $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 }}. diff --git a/{{cookiecutter.project_name}}/.github/workflows/release.yml b/{{cookiecutter.project_name}}/.github/workflows/release.yml index 2433883..c0e3d29 100644 --- a/{{cookiecutter.project_name}}/.github/workflows/release.yml +++ b/{{cookiecutter.project_name}}/.github/workflows/release.yml @@ -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 diff --git a/{{cookiecutter.project_name}}/.github/workflows/tests.yml b/{{cookiecutter.project_name}}/.github/workflows/tests.yml index da99318..5a2221c 100644 --- a/{{cookiecutter.project_name}}/.github/workflows/tests.yml +++ b/{{cookiecutter.project_name}}/.github/workflows/tests.yml @@ -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 -%} diff --git a/{{cookiecutter.project_name}}/.github/workflows/update-template.yaml b/{{cookiecutter.project_name}}/.github/workflows/update-template.yaml index 59f0b2e..0b91f76 100644 --- a/{{cookiecutter.project_name}}/.github/workflows/update-template.yaml +++ b/{{cookiecutter.project_name}}/.github/workflows/update-template.yaml @@ -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 diff --git a/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/{{cookiecutter.project_name}}/.pre-commit-config.yaml index 51d22fe..b2bf94c 100644 --- a/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -33,6 +33,6 @@ repos: rev: v2.12.0 hooks: - id: pretty-format-toml - args: [--autofix] + args: [--autofix, --no-sort] - id: pretty-format-yaml - args: [--autofix, --indent, '2', '--offset', '2', --preserve-quotes] \ No newline at end of file + args: [--autofix, --indent, '2', '--offset', '2', --preserve-quotes] diff --git a/{{cookiecutter.project_name}}/mkdocs.yml b/{{cookiecutter.project_name}}/mkdocs.yml index 72dc128..627ad02 100644 --- a/{{cookiecutter.project_name}}/mkdocs.yml +++ b/{{cookiecutter.project_name}}/mkdocs.yml @@ -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}} diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index 845b859..1535dbf 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -2,21 +2,19 @@ requires = ["setuptools>=48", "setuptools_scm[toml]>=6.3.1"] build-backend = "setuptools.build_meta" -[tool.setuptools_scm] - [project] name = "{{ cookiecutter.project_name }}" description = "{{ cookiecutter.short_description or cookiecutter.friendly_name }}" readme = "README.rst" license = {text = "{{ cookiecutter.license }}"} -authors = [{ name = "{{ cookiecutter.author }}", email = "{{ cookiecutter.email }}" }] +authors = [{name = "{{ cookiecutter.author }}", email = "{{ cookiecutter.email }}"}] classifiers = [ - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "{{cookiecutter.development_status}}", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "{{cookiecutter.development_status}}" ] requires-python = ">=3.8" dynamic = ["version"] @@ -29,27 +27,29 @@ Source = "https://github.com/{{cookiecutter.github_user}}/{{ cookiecutter.projec [project.optional-dependencies] {%- if cookiecutter.docs != "False" %} docs = [ - "mkdocs==1.5.2", - "mkdocs-gen-files==0.5.0", - "mkdocs-material==9.3.1", - "mkdocs-section-index==0.3.6", - "mkdocstrings-python==1.6.3", + "mkdocs==1.5.2", + "mkdocs-gen-files==0.5.0", + "mkdocs-material==9.3.1", + "mkdocs-section-index==0.3.6", + "mkdocstrings-python==1.6.3" ] {%- endif %} tests = [ - "pytest==7.2.0", - "pytest-sugar==0.9.5", - "pytest-cov==3.0.0", - "pytest-mock==3.8.2", - "mypy==0.971", + "pytest==7.2.0", + "pytest-sugar==0.9.5", + "pytest-cov==3.0.0", + "pytest-mock==3.8.2", + "mypy==0.971" ] dev = [ - "{{ cookiecutter.project_name }}[tests]", + "{{ cookiecutter.project_name }}[tests]", {%- if cookiecutter.docs != "False" %} - "{{ cookiecutter.project_name }}[docs]", + "{{ cookiecutter.project_name }}[docs]" {%- endif %} ] +[tool.setuptools_scm] + [tool.setuptools.packages.find] where = ["src"] namespaces = false @@ -67,13 +67,13 @@ source = ["src", "*/site-packages"] [tool.coverage.report] show_missing = true exclude_lines = [ - "pragma: no cover", - "if __name__ == .__main__.:", - "if typing.TYPE_CHECKING:", - "if TYPE_CHECKING:", - "raise NotImplementedError", - "raise AssertionError", - "@overload", + "pragma: no cover", + "if __name__ == .__main__.:", + "if typing.TYPE_CHECKING:", + "if TYPE_CHECKING:", + "raise NotImplementedError", + "raise AssertionError", + "@overload" ] [tool.mypy] @@ -95,14 +95,14 @@ ignore-words-list = " " [tool.ruff] ignore = [ - "S101", # assert - "PLR2004", # magic-value-comparison - "PLW2901", # redefined-loop-name - "ISC001", # single-line-implicit-string-concatenation - "SIM105", # suppressible-exception - "SIM108", # if-else-block-instead-of-if-exp - "D203", # one blank line before class - "D213", # multi-line-summary-second-line + "S101", # assert + "PLR2004", # magic-value-comparison + "PLW2901", # redefined-loop-name + "ISC001", # single-line-implicit-string-concatenation + "SIM105", # suppressible-exception + "SIM108", # if-else-block-instead-of-if-exp + "D203", # one blank line before class + "D213" # multi-line-summary-second-line ] select = ["ALL"] show-source = true