diff --git a/.github/workflows/bumpversion.yml b/.github/workflows/bumpversion.yml index ed010b4158..ed0c8cffce 100644 --- a/.github/workflows/bumpversion.yml +++ b/.github/workflows/bumpversion.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}' + token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" - name: Create bump and changelog uses: commitizen-tools/commitizen-action@master with: diff --git a/.github/workflows/docspublish.yml b/.github/workflows/docspublish.yml index 11f509b5b8..d95b464b40 100644 --- a/.github/workflows/docspublish.yml +++ b/.github/workflows/docspublish.yml @@ -9,32 +9,32 @@ jobs: publish-documentation: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}' - fetch-depth: 0 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install -U mkdocs mkdocs-material - - name: Build docs - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - python -m mkdocs build - - name: Generate Sponsors 💖 - uses: JamesIves/github-sponsors-readme-action@v1 - with: - token: ${{ secrets.PERSONAL_ACCESS_TOKEN_FOR_ORG }} - file: 'docs/README.md' - - name: Push doc to Github Page - uses: peaceiris/actions-gh-pages@v4 - with: - personal_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - publish_branch: gh-pages - publish_dir: ./site - user_name: "github-actions[bot]" - user_email: "github-actions[bot]@users.noreply.github.com" + - uses: actions/checkout@v4 + with: + token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install dependencies + run: | + python -m pip install -U mkdocs mkdocs-material + - name: Build docs + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python -m mkdocs build + - name: Generate Sponsors 💖 + uses: JamesIves/github-sponsors-readme-action@v1 + with: + token: ${{ secrets.PERSONAL_ACCESS_TOKEN_FOR_ORG }} + file: "docs/README.md" + - name: Push doc to Github Page + uses: peaceiris/actions-gh-pages@v4 + with: + personal_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + publish_branch: gh-pages + publish_dir: ./site + user_name: "github-actions[bot]" + user_email: "github-actions[bot]@users.noreply.github.com" diff --git a/.github/workflows/homebrewpublish.yml b/.github/workflows/homebrewpublish.yml index a2610229bc..84c2ca6ca0 100644 --- a/.github/workflows/homebrewpublish.yml +++ b/.github/workflows/homebrewpublish.yml @@ -11,22 +11,22 @@ jobs: runs-on: macos-latest if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install -U commitizen - - name: Set Project version env variable - run: | - echo "project_version=$(cz version --project)" >> $GITHUB_ENV - - name: Update Homebrew formula - uses: dawidd6/action-homebrew-bump-formula@v3 - with: - token: ${{secrets.PERSONAL_ACCESS_TOKEN}} - formula: commitizen - tag: v${{ env.project_version }} - force: true + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install dependencies + run: | + python -m pip install -U commitizen + - name: Set Project version env variable + run: | + echo "project_version=$(cz version --project)" >> $GITHUB_ENV + - name: Update Homebrew formula + uses: dawidd6/action-homebrew-bump-formula@v3 + with: + token: ${{secrets.PERSONAL_ACCESS_TOKEN}} + formula: commitizen + tag: v${{ env.project_version }} + force: true diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index f5967f3a93..3b5d5305a3 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -1,13 +1,13 @@ name: Python package -on: [ workflow_dispatch, pull_request ] +on: [workflow_dispatch, pull_request] jobs: python-check: strategy: matrix: - python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] - platform: [ ubuntu-20.04, macos-latest, windows-latest ] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + platform: [ubuntu-20.04, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v4 @@ -19,21 +19,20 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - # pin poetry to 1.3.2 due to https://github.com/python-poetry/poetry/issues/7611 - python -m pip install -U pip poetry==1.3.2 + python -m pip install -U pip poetry poetry --version poetry install - name: Run tests and linters run: | git config --global user.email "action@github.com" git config --global user.name "GitHub Action" - ./scripts/test + SKIP=no-commit-to-branch,commitizen-branch poetry run pre-commit run --all-files --hook-stage pre-push shell: bash - name: Upload coverage to Codecov if: runner.os == 'Linux' uses: codecov/codecov-action@v4 with: - token: ${{secrets.CODECOV_TOKEN}} + token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage.xml flags: unittests name: codecov-umbrella diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml index f31691a50b..e3b3aa6f30 100644 --- a/.github/workflows/pythonpublish.yml +++ b/.github/workflows/pythonpublish.yml @@ -3,7 +3,7 @@ name: Upload Python Package on: push: tags: - - 'v*' + - "v*" jobs: deploy: @@ -11,16 +11,15 @@ jobs: steps: - uses: actions/checkout@v4 with: - token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}' + token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.x' + python-version: "3.x" - name: Install dependencies run: | - # pin poetry to 1.3.2 due to https://github.com/python-poetry/poetry/issues/7611 - python -m pip install -U pip poetry==1.3.2 mkdocs mkdocs-material + python -m pip install -U pip poetry mkdocs mkdocs-material poetry --version poetry install - name: Publish diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 20b8d08ec6..b232a86c72 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,7 @@ repos: exclude: "poetry.lock" - repo: https://github.com/commitizen-tools/commitizen - rev: v3.22.0 # automatically updated by Commitizen + rev: v3.23.0 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index cf16e6a106..41db572536 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v3.23.0 (2024-04-18) + +### Feat + +- **bump**: `version_files` now support glob patterns (fix #1067) (#1070) + ## v3.22.0 (2024-04-11) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 659cac322f..dbea1a3912 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "3.22.0" +__version__ = "3.23.0" diff --git a/commitizen/bump.py b/commitizen/bump.py index f0e45e3432..2351dbd7ec 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -3,6 +3,7 @@ import os import re from collections import OrderedDict +from glob import iglob from string import Template from typing import cast @@ -53,23 +54,20 @@ def update_version_in_files( *, check_consistency: bool = False, encoding: str = encoding, -) -> None: +) -> list[str]: """Change old version to the new one in every file given. Note that this version is not the tag formatted one. So for example, your tag could look like `v1.0.0` while your version in the package like `1.0.0`. + + Returns the list of updated files. """ # TODO: separate check step and write step - for location in files: - drive, tail = os.path.splitdrive(location) - path, _, regex = tail.partition(":") - filepath = drive + path - if not regex: - regex = _version_to_regex(current_version) - + updated = [] + for path, regex in files_and_regexs(files, current_version): current_version_found, version_file = _bump_with_regex( - filepath, + path, current_version, new_version, regex, @@ -78,14 +76,33 @@ def update_version_in_files( if check_consistency and not current_version_found: raise CurrentVersionNotFoundError( - f"Current version {current_version} is not found in {location}.\n" + f"Current version {current_version} is not found in {path}.\n" "The version defined in commitizen configuration and the ones in " "version_files are possibly inconsistent." ) # Write the file out again - with smart_open(filepath, "w", encoding=encoding) as file: + with smart_open(path, "w", encoding=encoding) as file: file.write(version_file) + updated.append(path) + return updated + + +def files_and_regexs(patterns: list[str], version: str) -> list[tuple[str, str]]: + """ + Resolve all distinct files with their regexp from a list of glob patterns with optional regexp + """ + out = [] + for pattern in patterns: + drive, tail = os.path.splitdrive(pattern) + path, _, regex = tail.partition(":") + filepath = drive + path + if not regex: + regex = _version_to_regex(version) + + for path in iglob(filepath): + out.append((path, regex)) + return sorted(list(set(out))) def _bump_with_regex( diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index efbe1e0c3c..554e3c800b 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -1,12 +1,11 @@ from __future__ import annotations -import os import warnings from logging import getLogger import questionary -from commitizen import bump, cmd, factory, git, hooks, out +from commitizen import bump, factory, git, hooks, out from commitizen.commands.changelog import Changelog from commitizen.config import BaseConfig from commitizen.exceptions import ( @@ -286,56 +285,39 @@ def __call__(self) -> None: # noqa: C901 "The commits found are not eligible to be bumped" ) + files: list[str] = [] if self.changelog: + args = { + "unreleased_version": new_tag_version, + "template": self.template, + "extras": self.extras, + "incremental": True, + "dry_run": dry_run, + } if self.changelog_to_stdout: - changelog_cmd = Changelog( - self.config, - { - "unreleased_version": new_tag_version, - "template": self.template, - "extras": self.extras, - "incremental": True, - "dry_run": True, - }, - ) + changelog_cmd = Changelog(self.config, {**args, "dry_run": True}) try: changelog_cmd() except DryRunExit: pass - changelog_cmd = Changelog( - self.config, - { - "unreleased_version": new_tag_version, - "incremental": True, - "dry_run": dry_run, - "template": self.template, - "extras": self.extras, - "file_name": self.file_name, - }, - ) + + args["file_name"] = self.file_name + changelog_cmd = Changelog(self.config, args) changelog_cmd() - file_names = [] - for file_name in version_files: - drive, tail = os.path.splitdrive(file_name) - path, _, regex = tail.partition(":") - path = drive + path if path != "" else drive + regex - file_names.append(path) - git_add_changelog_and_version_files_command = ( - f"git add {changelog_cmd.file_name} " - f"{' '.join(name for name in file_names)}" - ) - c = cmd.run(git_add_changelog_and_version_files_command) + files.append(changelog_cmd.file_name) # Do not perform operations over files or git. if dry_run: raise DryRunExit() - bump.update_version_in_files( - str(current_version), - str(new_version), - version_files, - check_consistency=self.check_consistency, - encoding=self.encoding, + files.extend( + bump.update_version_in_files( + str(current_version), + str(new_version), + version_files, + check_consistency=self.check_consistency, + encoding=self.encoding, + ) ) provider.set_version(str(new_version)) @@ -358,12 +340,13 @@ def __call__(self) -> None: # noqa: C901 raise ExpectedExit() # FIXME: check if any changes have been staged + git.add(*files) c = git.commit(message, args=self._get_commit_args()) if self.retry and c.return_code != 0 and self.changelog: # Maybe pre-commit reformatted some files? Retry once logger.debug("1st git.commit error: %s", c.err) logger.info("1st commit attempt failed; retrying once") - cmd.run(git_add_changelog_and_version_files_command) + git.add(*files) c = git.commit(message, args=self._get_commit_args()) if c.return_code != 0: err = c.err.strip() or c.out diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index 3fc204eba9..f1b69598f1 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -4,7 +4,7 @@ from difflib import SequenceMatcher from operator import itemgetter from pathlib import Path -from typing import Callable +from typing import Callable, cast from commitizen import bump, changelog, defaults, factory, git, out @@ -38,8 +38,8 @@ def __init__(self, config: BaseConfig, args): self.start_rev = args.get("start_rev") or self.config.settings.get( "changelog_start_rev" ) - self.file_name = args.get("file_name") or self.config.settings.get( - "changelog_file" + self.file_name = args.get("file_name") or cast( + str, self.config.settings.get("changelog_file") ) if not isinstance(self.file_name, str): raise NotAllowed( diff --git a/commitizen/git.py b/commitizen/git.py index 53e7335a3f..1f758889ed 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -98,8 +98,8 @@ def tag( return c -def add(args: str = "") -> cmd.Command: - c = cmd.run(f"git add {args}") +def add(*args: str) -> cmd.Command: + c = cmd.run(f"git add {' '.join(args)}") return c diff --git a/docs/bump.md b/docs/bump.md index 0e35083b0a..05843eeab5 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -474,6 +474,10 @@ In the example above, we can see the reference `"setup.py:version"`. This means that it will find a file `setup.py` and will only make a change in a line containing the `version` substring. +!!! note + Files can be specified using relative (to the execution) paths, absolute paths + or glob patterns. + --- ### `bump_message` diff --git a/poetry.lock b/poetry.lock index 4cc8f16674..4479975b01 100644 --- a/poetry.lock +++ b/poetry.lock @@ -13,13 +13,13 @@ files = [ [[package]] name = "argcomplete" -version = "3.2.3" +version = "3.3.0" description = "Bash tab completion for argparse" optional = false python-versions = ">=3.8" files = [ - {file = "argcomplete-3.2.3-py3-none-any.whl", hash = "sha256:c12355e0494c76a2a7b73e3a59b09024ca0ba1e279fb9ed6c1b82d5b74b6a70c"}, - {file = "argcomplete-3.2.3.tar.gz", hash = "sha256:bf7900329262e481be5a15f56f19736b376df6f82ed27576fa893652c5de6c23"}, + {file = "argcomplete-3.3.0-py3-none-any.whl", hash = "sha256:c168c3723482c031df3c207d4ba8fa702717ccb9fc0bfe4117166c1f537b4a54"}, + {file = "argcomplete-3.3.0.tar.gz", hash = "sha256:fd03ff4a5b9e6580569d34b273f741e85cd9e072f3feeeee3eba4891c70eda62"}, ] [package.extras] @@ -73,33 +73,33 @@ files = [ [[package]] name = "black" -version = "24.3.0" +version = "24.4.0" description = "The uncompromising code formatter." optional = false python-versions = ">=3.8" files = [ - {file = "black-24.3.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7d5e026f8da0322b5662fa7a8e752b3fa2dac1c1cbc213c3d7ff9bdd0ab12395"}, - {file = "black-24.3.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9f50ea1132e2189d8dff0115ab75b65590a3e97de1e143795adb4ce317934995"}, - {file = "black-24.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e2af80566f43c85f5797365077fb64a393861a3730bd110971ab7a0c94e873e7"}, - {file = "black-24.3.0-cp310-cp310-win_amd64.whl", hash = "sha256:4be5bb28e090456adfc1255e03967fb67ca846a03be7aadf6249096100ee32d0"}, - {file = "black-24.3.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:4f1373a7808a8f135b774039f61d59e4be7eb56b2513d3d2f02a8b9365b8a8a9"}, - {file = "black-24.3.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:aadf7a02d947936ee418777e0247ea114f78aff0d0959461057cae8a04f20597"}, - {file = "black-24.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65c02e4ea2ae09d16314d30912a58ada9a5c4fdfedf9512d23326128ac08ac3d"}, - {file = "black-24.3.0-cp311-cp311-win_amd64.whl", hash = "sha256:bf21b7b230718a5f08bd32d5e4f1db7fc8788345c8aea1d155fc17852b3410f5"}, - {file = "black-24.3.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:2818cf72dfd5d289e48f37ccfa08b460bf469e67fb7c4abb07edc2e9f16fb63f"}, - {file = "black-24.3.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4acf672def7eb1725f41f38bf6bf425c8237248bb0804faa3965c036f7672d11"}, - {file = "black-24.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c7ed6668cbbfcd231fa0dc1b137d3e40c04c7f786e626b405c62bcd5db5857e4"}, - {file = "black-24.3.0-cp312-cp312-win_amd64.whl", hash = "sha256:56f52cfbd3dabe2798d76dbdd299faa046a901041faf2cf33288bc4e6dae57b5"}, - {file = "black-24.3.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:79dcf34b33e38ed1b17434693763301d7ccbd1c5860674a8f871bd15139e7837"}, - {file = "black-24.3.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:e19cb1c6365fd6dc38a6eae2dcb691d7d83935c10215aef8e6c38edee3f77abd"}, - {file = "black-24.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65b76c275e4c1c5ce6e9870911384bff5ca31ab63d19c76811cb1fb162678213"}, - {file = "black-24.3.0-cp38-cp38-win_amd64.whl", hash = "sha256:b5991d523eee14756f3c8d5df5231550ae8993e2286b8014e2fdea7156ed0959"}, - {file = "black-24.3.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c45f8dff244b3c431b36e3224b6be4a127c6aca780853574c00faf99258041eb"}, - {file = "black-24.3.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:6905238a754ceb7788a73f02b45637d820b2f5478b20fec82ea865e4f5d4d9f7"}, - {file = "black-24.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d7de8d330763c66663661a1ffd432274a2f92f07feeddd89ffd085b5744f85e7"}, - {file = "black-24.3.0-cp39-cp39-win_amd64.whl", hash = "sha256:7bb041dca0d784697af4646d3b62ba4a6b028276ae878e53f6b4f74ddd6db99f"}, - {file = "black-24.3.0-py3-none-any.whl", hash = "sha256:41622020d7120e01d377f74249e677039d20e6344ff5851de8a10f11f513bf93"}, - {file = "black-24.3.0.tar.gz", hash = "sha256:a0c9c4a0771afc6919578cec71ce82a3e31e054904e7197deacbc9382671c41f"}, + {file = "black-24.4.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6ad001a9ddd9b8dfd1b434d566be39b1cd502802c8d38bbb1ba612afda2ef436"}, + {file = "black-24.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e3a3a092b8b756c643fe45f4624dbd5a389f770a4ac294cf4d0fce6af86addaf"}, + {file = "black-24.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dae79397f367ac8d7adb6c779813328f6d690943f64b32983e896bcccd18cbad"}, + {file = "black-24.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:71d998b73c957444fb7c52096c3843875f4b6b47a54972598741fe9a7f737fcb"}, + {file = "black-24.4.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:8e5537f456a22cf5cfcb2707803431d2feeb82ab3748ade280d6ccd0b40ed2e8"}, + {file = "black-24.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:64e60a7edd71fd542a10a9643bf369bfd2644de95ec71e86790b063aa02ff745"}, + {file = "black-24.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5cd5b4f76056cecce3e69b0d4c228326d2595f506797f40b9233424e2524c070"}, + {file = "black-24.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:64578cf99b6b46a6301bc28bdb89f9d6f9b592b1c5837818a177c98525dbe397"}, + {file = "black-24.4.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:f95cece33329dc4aa3b0e1a771c41075812e46cf3d6e3f1dfe3d91ff09826ed2"}, + {file = "black-24.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4396ca365a4310beef84d446ca5016f671b10f07abdba3e4e4304218d2c71d33"}, + {file = "black-24.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:44d99dfdf37a2a00a6f7a8dcbd19edf361d056ee51093b2445de7ca09adac965"}, + {file = "black-24.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:21f9407063ec71c5580b8ad975653c66508d6a9f57bd008bb8691d273705adcd"}, + {file = "black-24.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:652e55bb722ca026299eb74e53880ee2315b181dfdd44dca98e43448620ddec1"}, + {file = "black-24.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7f2966b9b2b3b7104fca9d75b2ee856fe3fdd7ed9e47c753a4bb1a675f2caab8"}, + {file = "black-24.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1bb9ca06e556a09f7f7177bc7cb604e5ed2d2df1e9119e4f7d2f1f7071c32e5d"}, + {file = "black-24.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:d4e71cdebdc8efeb6deaf5f2deb28325f8614d48426bed118ecc2dcaefb9ebf3"}, + {file = "black-24.4.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6644f97a7ef6f401a150cca551a1ff97e03c25d8519ee0bbc9b0058772882665"}, + {file = "black-24.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:75a2d0b4f5eb81f7eebc31f788f9830a6ce10a68c91fbe0fade34fff7a2836e6"}, + {file = "black-24.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eb949f56a63c5e134dfdca12091e98ffb5fd446293ebae123d10fc1abad00b9e"}, + {file = "black-24.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:7852b05d02b5b9a8c893ab95863ef8986e4dda29af80bbbda94d7aee1abf8702"}, + {file = "black-24.4.0-py3-none-any.whl", hash = "sha256:74eb9b5420e26b42c00a3ff470dc0cd144b80a766128b1771d07643165e08d0e"}, + {file = "black-24.4.0.tar.gz", hash = "sha256:f07b69fda20578367eaebbd670ff8fc653ab181e1ff95d84497f9fa20e7d0641"}, ] [package.dependencies] @@ -485,13 +485,13 @@ license = ["ukkonen"] [[package]] name = "idna" -version = "3.6" +version = "3.7" description = "Internationalized Domain Names in Applications (IDNA)" optional = false python-versions = ">=3.5" files = [ - {file = "idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"}, - {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, + {file = "idna-3.7-py3-none-any.whl", hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"}, + {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, ] [[package]] @@ -779,13 +779,13 @@ min-versions = ["babel (==2.9.0)", "click (==7.0)", "colorama (==0.4)", "ghp-imp [[package]] name = "mkdocs-material" -version = "9.5.17" +version = "9.5.18" description = "Documentation that simply works" optional = false python-versions = ">=3.8" files = [ - {file = "mkdocs_material-9.5.17-py3-none-any.whl", hash = "sha256:14a2a60119a785e70e765dd033e6211367aca9fc70230e577c1cf6a326949571"}, - {file = "mkdocs_material-9.5.17.tar.gz", hash = "sha256:06ae1275a72db1989cf6209de9e9ecdfbcfdbc24c58353877b2bb927dbe413e4"}, + {file = "mkdocs_material-9.5.18-py3-none-any.whl", hash = "sha256:1e0e27fc9fe239f9064318acf548771a4629d5fd5dfd45444fd80a953fe21eb4"}, + {file = "mkdocs_material-9.5.18.tar.gz", hash = "sha256:a43f470947053fa2405c33995f282d24992c752a50114f23f30da9d8d0c57e62"}, ] [package.dependencies] @@ -1461,28 +1461,28 @@ jupyter = ["ipywidgets (>=7.5.1,<9)"] [[package]] name = "ruff" -version = "0.3.5" +version = "0.3.7" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.3.5-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:aef5bd3b89e657007e1be6b16553c8813b221ff6d92c7526b7e0227450981eac"}, - {file = "ruff-0.3.5-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:89b1e92b3bd9fca249153a97d23f29bed3992cff414b222fcd361d763fc53f12"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5e55771559c89272c3ebab23326dc23e7f813e492052391fe7950c1a5a139d89"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:dabc62195bf54b8a7876add6e789caae0268f34582333cda340497c886111c39"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3a05f3793ba25f194f395578579c546ca5d83e0195f992edc32e5907d142bfa3"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:dfd3504e881082959b4160ab02f7a205f0fadc0a9619cc481982b6837b2fd4c0"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:87258e0d4b04046cf1d6cc1c56fadbf7a880cc3de1f7294938e923234cf9e498"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:712e71283fc7d9f95047ed5f793bc019b0b0a29849b14664a60fd66c23b96da1"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a532a90b4a18d3f722c124c513ffb5e5eaff0cc4f6d3aa4bda38e691b8600c9f"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:122de171a147c76ada00f76df533b54676f6e321e61bd8656ae54be326c10296"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d80a6b18a6c3b6ed25b71b05eba183f37d9bc8b16ace9e3d700997f00b74660b"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_i686.whl", hash = "sha256:a7b6e63194c68bca8e71f81de30cfa6f58ff70393cf45aab4c20f158227d5936"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a759d33a20c72f2dfa54dae6e85e1225b8e302e8ac655773aff22e542a300985"}, - {file = "ruff-0.3.5-py3-none-win32.whl", hash = "sha256:9d8605aa990045517c911726d21293ef4baa64f87265896e491a05461cae078d"}, - {file = "ruff-0.3.5-py3-none-win_amd64.whl", hash = "sha256:dc56bb16a63c1303bd47563c60482a1512721053d93231cf7e9e1c6954395a0e"}, - {file = "ruff-0.3.5-py3-none-win_arm64.whl", hash = "sha256:faeeae9905446b975dcf6d4499dc93439b131f1443ee264055c5716dd947af55"}, - {file = "ruff-0.3.5.tar.gz", hash = "sha256:a067daaeb1dc2baf9b82a32dae67d154d95212080c80435eb052d95da647763d"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:0e8377cccb2f07abd25e84fc5b2cbe48eeb0fea9f1719cad7caedb061d70e5ce"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:15a4d1cc1e64e556fa0d67bfd388fed416b7f3b26d5d1c3e7d192c897e39ba4b"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d28bdf3d7dc71dd46929fafeec98ba89b7c3550c3f0978e36389b5631b793663"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:379b67d4f49774ba679593b232dcd90d9e10f04d96e3c8ce4a28037ae473f7bb"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c060aea8ad5ef21cdfbbe05475ab5104ce7827b639a78dd55383a6e9895b7c51"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:ebf8f615dde968272d70502c083ebf963b6781aacd3079081e03b32adfe4d58a"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d48098bd8f5c38897b03604f5428901b65e3c97d40b3952e38637b5404b739a2"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:da8a4fda219bf9024692b1bc68c9cff4b80507879ada8769dc7e985755d662ea"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c44e0149f1d8b48c4d5c33d88c677a4aa22fd09b1683d6a7ff55b816b5d074f"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3050ec0af72b709a62ecc2aca941b9cd479a7bf2b36cc4562f0033d688e44fa1"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a29cc38e4c1ab00da18a3f6777f8b50099d73326981bb7d182e54a9a21bb4ff7"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:5b15cc59c19edca917f51b1956637db47e200b0fc5e6e1878233d3a938384b0b"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:e491045781b1e38b72c91247cf4634f040f8d0cb3e6d3d64d38dcf43616650b4"}, + {file = "ruff-0.3.7-py3-none-win32.whl", hash = "sha256:bc931de87593d64fad3a22e201e55ad76271f1d5bfc44e1a1887edd0903c7d9f"}, + {file = "ruff-0.3.7-py3-none-win_amd64.whl", hash = "sha256:5ef0e501e1e39f35e03c2acb1d1238c595b8bb36cf7a170e7c1df1b73da00e74"}, + {file = "ruff-0.3.7-py3-none-win_arm64.whl", hash = "sha256:789e144f6dc7019d1f92a812891c645274ed08af6037d11fc65fcbc183b7d59f"}, + {file = "ruff-0.3.7.tar.gz", hash = "sha256:d5c1aebee5162c2226784800ae031f660c350e7a3402c4d1f8ea4e97e232e3ba"}, ] [[package]] @@ -1820,4 +1820,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.8" -content-hash = "5cd809db4e9dc8005ab2295ca7d182435021752953a7b1552bb81912b54df791" +content-hash = "abe023abef8eaadaffaa2b8725bc1958b6597cc8e07f0899cf751d5ce28cab82" diff --git a/pyproject.toml b/pyproject.toml index b6d766ef19..66a73a310d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "3.22.0" +version = "3.23.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -9,7 +9,7 @@ version_files = [ [tool.poetry] name = "commitizen" -version = "3.22.0" +version = "3.23.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" @@ -43,7 +43,7 @@ packaging = ">=19" tomlkit = ">=0.5.3,<1.0.0" jinja2 = ">=2.10.3" pyyaml = ">=3.08" -argcomplete = ">=1.12.1,<3.3" +argcomplete = ">=1.12.1,<3.4" typing-extensions = { version = "^4.0.1", python = "<3.8" } charset-normalizer = ">=2.1.0,<4" # Use the Python 3.11 and 3.12 compatible API: https://github.com/python/importlib_metadata#compatibility diff --git a/scripts/test b/scripts/test index e2fa065142..08889af8b0 100755 --- a/scripts/test +++ b/scripts/test @@ -5,7 +5,7 @@ export PREFIX='poetry run python -m ' export REGEX='^(?![.]|venv).*' ${PREFIX}pytest -n 3 --dist=loadfile --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/ -${PREFIX}black commitizen tests --check -${PREFIX}ruff commitizen/ tests/ +${PREFIX}black commitizen tests +${PREFIX}ruff check commitizen/ tests/ --fix ${PREFIX}mypy commitizen/ tests/ ${PREFIX}commitizen -nr 3 check --rev-range origin/master.. diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 6cf8a8d00c..84faf9ee82 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -812,6 +812,16 @@ def test_bump_with_git_to_stdout_arg(mocker: MockFixture, capsys, changelog_path """, id="version in __init__.py with regex", ), + pytest.param( + "pyproject.toml", + "*.toml:^version", + """ +[tool.poetry] +name = "my_package" +version = "0.1.0" +""", + id="version in pyproject.toml with glob and regex", + ), ], ) @pytest.mark.parametrize( diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 9a80d4cfd9..850b59c166 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -207,3 +207,21 @@ def test_multiplt_versions_to_bump( bump.update_version_in_files(old_version, new_version, [location], encoding="utf-8") with open(multiple_versions_to_update_poetry_lock, encoding="utf-8") as f: file_regression.check(f.read(), extension=".toml") + + +def test_update_version_in_globbed_files(commitizen_config_file, file_regression): + old_version = "1.2.3" + new_version = "2.0.0" + other = commitizen_config_file.dirpath("other.toml") + print(commitizen_config_file, other) + copyfile(commitizen_config_file, other) + + # Prepend full ppath as test assume absolute paths or cwd-relative + version_files = [commitizen_config_file.dirpath("*.toml")] + + bump.update_version_in_files( + old_version, new_version, version_files, encoding="utf-8" + ) + + for file in commitizen_config_file, other: + file_regression.check(file.read_text("utf-8"), extension=".toml") diff --git a/tests/test_bump_update_version_in_files/test_update_version_in_globbed_files.toml b/tests/test_bump_update_version_in_files/test_update_version_in_globbed_files.toml new file mode 100644 index 0000000000..bf82cfe859 --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_update_version_in_globbed_files.toml @@ -0,0 +1,3 @@ +[tool.poetry] +name = "commitizen" +version = "2.0.0"