From 4e85d421d823829cc6b8f5844f13baf8e2b464c2 Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:51:42 -0500 Subject: [PATCH] migrate from bump2version to bump-my-version, small documentation adjustments, move flake8 configuration to .flake8, remove setup.cfg --- CONTRIBUTING.rst | 6 +-- {{cookiecutter.project_slug}}/.flake8 | 30 ++++++++++++ .../.github/workflows/bump-version.yml | 4 +- .../.github/workflows/main.yml | 2 +- .../.github/workflows/tag-testpypi.yml | 1 + .../.pre-commit-config.yaml | 8 ++- .../CONTRIBUTING.rst | 38 +++++++------- .../environment-dev.yml | 2 +- {{cookiecutter.project_slug}}/pyproject.toml | 29 ++++++++++- {{cookiecutter.project_slug}}/setup.cfg | 49 ------------------- 10 files changed, 90 insertions(+), 79 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/.flake8 delete mode 100644 {{cookiecutter.project_slug}}/setup.cfg diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 3400aeeda..e1c923482 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -127,11 +127,11 @@ Pull Request Guidelines Before you submit a pull request, check that it meets these guidelines: -1. The pull request should include tests. +#. The pull request should include tests. -2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. +#. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. -3. The pull request should work for Python 3.8, 3.9, 3.10, 3.11, and for PyPy. Check https://github.com/Ouranosinc/cookiecutter-pypackage/actions/workflows/main.yml and make sure that the tests pass for all supported Python versions. +#. The pull request should work for Python 3.8, 3.9, 3.10, 3.11, and for PyPy. Check https://github.com/Ouranosinc/cookiecutter-pypackage/actions/workflows/main.yml and make sure that the tests pass for all supported Python versions. Add a New Test -------------- diff --git a/{{cookiecutter.project_slug}}/.flake8 b/{{cookiecutter.project_slug}}/.flake8 new file mode 100644 index 000000000..1116575bc --- /dev/null +++ b/{{cookiecutter.project_slug}}/.flake8 @@ -0,0 +1,30 @@ +[flake8] +exclude = + .eggs, + .git, + build, + docs, + tests +ignore = + AZ100, + AZ200, + AZ300, + C, + D, + E, + F, + W503 +per-file-ignores = +rst-roles = + doc, + mod, + py:attr, + py:attribute, + py:class, + py:const, + py:data, + py:func, + py:meth, + py:mod, + py:obj, + py:ref diff --git a/{{cookiecutter.project_slug}}/.github/workflows/bump-version.yml b/{{cookiecutter.project_slug}}/.github/workflows/bump-version.yml index 83670a73c..d8a1a88ac 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/bump-version.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/bump-version.yml @@ -54,9 +54,9 @@ jobs: run: echo "current_version=$(grep -E '__version__' {{ cookiecutter.project_slug }}/__init__.py | cut -d ' ' -f3)" - name: Bump Patch Version run: | - pip install bump2version + pip install bump-my-version echo "Bumping version" - bump2version patch + bump-my-version bump patch echo "new_version=$(grep -E '__version__' {{ cookiecutter.project_slug }}/__init__.py | cut -d ' ' -f3)" - name: Push Changes uses: ad-m/github-push-action@master diff --git a/{{cookiecutter.project_slug}}/.github/workflows/main.yml b/{{cookiecutter.project_slug}}/.github/workflows/main.yml index c749781c7..bb90c5424 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/main.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/main.yml @@ -104,7 +104,7 @@ jobs: python -m pip check || true - name: Test with pytest run: | - python -m pytest tests + python -m pytest --cov {{ cookiecutter.project_slug }} - name: Report coverage run: | python -m coveralls diff --git a/{{cookiecutter.project_slug}}/.github/workflows/tag-testpypi.yml b/{{cookiecutter.project_slug}}/.github/workflows/tag-testpypi.yml index ae1d4d489..4418173e6 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/tag-testpypi.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/tag-testpypi.yml @@ -10,6 +10,7 @@ jobs: release: name: Create Release from tag runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') && endsWith(github.ref, '.0') steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml index ad6d8c289..bac45373c 100644 --- a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -31,16 +31,14 @@ repos: hooks: - id: rst-inline-touching-normal - repo: https://github.com/psf/black - rev: 23.10.1 + rev: 23.11.0 hooks: - id: black exclude: ^docs/ - args: [ '--target-version=py38' ] - repo: https://github.com/PyCQA/isort rev: 5.12.0 hooks: - id: isort - args: ['--settings-file=setup.cfg'] exclude: ^docs/ - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.4 @@ -51,12 +49,12 @@ repos: hooks: - id: flake8 additional_dependencies: [ 'flake8-alphabetize', 'flake8-rst-docstrings' ] - args: [ '--config=setup.cfg' ] + args: [ '--config=.flake8' ] - repo: https://github.com/keewis/blackdoc rev: v0.3.8 hooks: - id: blackdoc - additional_dependencies: [ 'black==23.10.1' ] + additional_dependencies: [ 'black==23.11.0' ] - repo: https://github.com/adrienverge/yamllint.git rev: v1.32.0 hooks: diff --git a/{{cookiecutter.project_slug}}/CONTRIBUTING.rst b/{{cookiecutter.project_slug}}/CONTRIBUTING.rst index a6d7ce93d..29cae0dd2 100644 --- a/{{cookiecutter.project_slug}}/CONTRIBUTING.rst +++ b/{{cookiecutter.project_slug}}/CONTRIBUTING.rst @@ -4,8 +4,7 @@ Contributing ============ -Contributions are welcome, and they are greatly appreciated! Every little bit -helps, and credit will always be given. +Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given. You can contribute in many ways: @@ -26,21 +25,17 @@ If you are reporting a bug, please include: Fix Bugs ~~~~~~~~ -Look through the GitHub issues for bugs. Anything tagged with "bug" and "help -wanted" is open to whoever wants to implement it. +Look through the GitHub issues for bugs. Anything tagged with "bug" and "help wanted" is open to whoever wants to implement it. Implement Features ~~~~~~~~~~~~~~~~~~ -Look through the GitHub issues for features. Anything tagged with "enhancement" -and "help wanted" is open to whoever wants to implement it. +Look through the GitHub issues for features. Anything tagged with "enhancement" and "help wanted" is open to whoever wants to implement it. Write Documentation ~~~~~~~~~~~~~~~~~~~ -{{ cookiecutter.project_name }} could always use more documentation, whether as part of the -official {{ cookiecutter.project_name }} docs, in docstrings, or even on the web in blog posts, -articles, and such. +{{ cookiecutter.project_name }} could always use more documentation, whether as part of the official {{ cookiecutter.project_name }} docs, in docstrings, or even on the web in blog posts, articles, and such. Submit Feedback ~~~~~~~~~~~~~~~ @@ -128,9 +123,11 @@ Pull Request Guidelines Before you submit a pull request, check that it meets these guidelines: -1. The pull request should include tests. -2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in ``README.rst``. -3. The pull request should work for Python 3.8, 3.9, 3.10, and 3.11. Check that the tests pass for all supported Python versions. +#. The pull request should include tests. + +#. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in ``README.rst``. + +#. The pull request should work for Python 3.8, 3.9, 3.10, and 3.11. Check that the tests pass for all supported Python versions. Tips ---- @@ -148,13 +145,20 @@ Versioning/Tagging A reminder for the maintainers on how to deploy. This section is only relevant for maintainers when they are producing a new point release for the package. -In a new branch, make sure all your release information has been committed (in ``CHANGES.rst``). Then run:: +#. Create a new branch from `main` (e.g. `release-0.2.0`). +#. Update the `CHANGES.rst` file to change the `Unreleased` section to the current date. +#. Create a pull request from your branch to `main`. +#. Once the pull request is merged, create a new release on GitHub. On the main branch, run: + + .. code-block:: shell + + $ bump-my-version bump minor # In most cases, we will be releasing a minor version + $ git push + $ git push --tags -$ bumpversion patch # possible: major / minor / patch -$ git push -$ git push --tags + This will trigger the CI to build the package and upload it to TestPyPI. In order to upload to PyPI, this can be done by publishing a new version on GitHub. This will then trigger the workflow to build and upload the package to PyPI. -This will trigger the CI to build the package and upload it to TestPyPI. In order to upload to PyPI, this can be done by publishing a new version on GitHub. This will trigger the workflow to build and upload the package to PyPI. +#. Once the release is published, it will go into a `staging` mode on Github Actions. Once the tests pass, admins can approve the release (an e-mail will be sent) and it will be published on PyPI. .. note:: diff --git a/{{cookiecutter.project_slug}}/environment-dev.yml b/{{cookiecutter.project_slug}}/environment-dev.yml index dc05a421a..5ae734a4c 100644 --- a/{{cookiecutter.project_slug}}/environment-dev.yml +++ b/{{cookiecutter.project_slug}}/environment-dev.yml @@ -5,7 +5,7 @@ dependencies: - python >=3.9,<3.12 # Dev tools and testing - pip >=23.1.2 - - bump2version >=1.0.1 + - bump-my-version >=0.12.0 - watchdog >=3.0.0 - flake8 >=6.1.0 - flake8-rst-docstrings >=0.3.0 diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 529c63146..af0e3698d 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ dev = [ # Dev tools and testing "pip>=23.1.2", - "bump2version>=1.0.1", + "bump-my-version>=0.12.0", "watchdog>=3.0.0", "flake8>=6.1.0", "flake8-rst-docstrings>=0.3.0", @@ -108,6 +108,32 @@ target-version = [ ] {%- endif %} +[tool.bumpversion] +current_version = "{{ cookiecutter.version }}" +commit = true +tag = true +tag_name = "{new_version}" +allow_dirty = false +serialize = ["{major}.{minor}.{patch}"] +parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)" + +[[tool.bumpversion.files]] +filename = "{{ cookiecutter.project_slug }}/__init__.py" +search = "__version__ = \"{current_version}\"" +replace = "__version__ = \"{new_version}\"" + +[[tool.bumpversion.files]] +filename = "tests/test_{{ cookiecutter.project_slug }}.py" +search = "__version__ = \"{current_version}\"" +replace = "__version__ = \"{new_version}\"" +{%- if cookiecutter.generated_with_cruft == 'y' %} + +[[tool.bumpversion.files]] +filename = ".cruft.json" +search = "\"version\": \"{current_version}\"" +replace = "\"version\": \"{new_version}\"" +{%- endif %} + [tool.coverage.run] relative_files = true include = ["{{ cookiecutter.project_slug }}/*"] @@ -150,6 +176,7 @@ exclude = [ "**/__pycache__", ".coveralls.yml", ".editorconfig", + ".flake8", ".gitignore", ".pre-commit-config.yaml", {%- if cookiecutter.make_docs == 'y' %} diff --git a/{{cookiecutter.project_slug}}/setup.cfg b/{{cookiecutter.project_slug}}/setup.cfg deleted file mode 100644 index 58d2beff7..000000000 --- a/{{cookiecutter.project_slug}}/setup.cfg +++ /dev/null @@ -1,49 +0,0 @@ -[bumpversion] -current_version = {{ cookiecutter.version }} -commit = True -tag = True - -[bumpversion:file:{{ cookiecutter.project_slug }}/__init__.py] -search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" - -[bumpversion:file:tests/test_{{ cookiecutter.project_slug }}.py] -search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" -{%- if cookiecutter.generated_with_cruft == 'y' %} - -[bumpversion:file:.cruft.json] -search = "version": "{current_version}", -replace = "version": "{new_version}", -{%- endif %} - -[flake8] -exclude = - .eggs, - .git, - build, - docs, - tests -ignore = - AZ100, - AZ200, - AZ300, - C, - D, - E, - F, - W503 -per-file-ignores = -rst-roles = - doc, - mod, - py:attr, - py:attribute, - py:class, - py:const, - py:data, - py:func, - py:meth, - py:mod, - py:obj, - py:ref