From 491b4aa4edc0241edbf5d77cfcf609c6de56f301 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 19:23:35 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.14 → v0.2.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.14...v0.2.0) - [github.com/psf/black: 23.12.1 → 24.1.1](https://github.com/psf/black/compare/23.12.1...24.1.1) - [github.com/python-jsonschema/check-jsonschema: 0.27.3 → 0.27.4](https://github.com/python-jsonschema/check-jsonschema/compare/0.27.3...0.27.4) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e4de8ed..d8a574f9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.1.14' + rev: 'v0.2.0' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] exclude: test.* - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black - repo: https://github.com/pre-commit/pre-commit-hooks @@ -56,7 +56,7 @@ repos: - id: interrogate exclude: test.* - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.27.3 + rev: 0.27.4 hooks: - id: check-azure-pipelines ci: From c03476ac51b94cd136c39bb9c48fee4f1a815b42 Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Sat, 10 Feb 2024 08:24:36 -0600 Subject: [PATCH 2/3] Fix encoding when reading text. Fixes #68 --- bumpversion/config/create.py | 3 ++- bumpversion/config/files.py | 8 ++++++-- bumpversion/config/files_legacy.py | 3 ++- bumpversion/files.py | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bumpversion/config/create.py b/bumpversion/config/create.py index edf51024..8020d961 100644 --- a/bumpversion/config/create.py +++ b/bumpversion/config/create.py @@ -1,4 +1,5 @@ """Module for creating a new config file.""" + from pathlib import Path from typing import Tuple @@ -57,7 +58,7 @@ def get_defaults_from_dest(destination: str) -> Tuple[dict, TOMLDocument]: config = DEFAULTS.copy() if Path(destination).exists(): - destination_config = parse(Path(destination).read_text()) + destination_config = parse(Path(destination).read_text(encoding="utf-8")) else: destination_config = document() diff --git a/bumpversion/config/files.py b/bumpversion/config/files.py index 7aa68dce..2fcad842 100644 --- a/bumpversion/config/files.py +++ b/bumpversion/config/files.py @@ -39,7 +39,11 @@ def find_config_file(explicit_file: Union[str, Path, None] = None) -> Union[Path [Path(explicit_file)] if explicit_file else [Path.cwd().joinpath(path) for path in CONFIG_FILE_SEARCH_ORDER] ) return next( - (cfg_file for cfg_file in search_paths if cfg_file.exists() and "bumpversion]" in cfg_file.read_text()), + ( + cfg_file + for cfg_file in search_paths + if cfg_file.exists() and "bumpversion]" in cfg_file.read_text(encoding="utf-8") + ), None, ) @@ -91,7 +95,7 @@ def read_toml_file(file_path: Path) -> Dict[str, Any]: import tomlkit # Load the TOML file - toml_data = tomlkit.parse(file_path.read_text()).unwrap() + toml_data = tomlkit.parse(file_path.read_text(encoding="utf-8")).unwrap() return toml_data.get("tool", {}).get("bumpversion", {}) diff --git a/bumpversion/config/files_legacy.py b/bumpversion/config/files_legacy.py index 5a9ea4de..19e5a1a1 100644 --- a/bumpversion/config/files_legacy.py +++ b/bumpversion/config/files_legacy.py @@ -1,4 +1,5 @@ """This module handles the legacy config file format.""" + from __future__ import annotations import re @@ -102,7 +103,7 @@ def update_ini_config_file( ) config_path = Path(config_file) - existing_config = config_path.read_text() + existing_config = config_path.read_text(encoding="utf-8") if config_path.suffix == ".cfg" and cfg_current_version_regex.search(existing_config): sub_str = f"\\g{new_version}" new_config = cfg_current_version_regex.sub(sub_str, existing_config) diff --git a/bumpversion/files.py b/bumpversion/files.py index 6a5eb015..f3c3fcc0 100644 --- a/bumpversion/files.py +++ b/bumpversion/files.py @@ -1,4 +1,5 @@ """Methods for changing files.""" + import os.path import re from copy import deepcopy @@ -331,7 +332,7 @@ def _update_toml_file( """Update a TOML file.""" import tomlkit - toml_data = tomlkit.parse(self.path.read_text()) + toml_data = tomlkit.parse(self.path.read_text(encoding="utf-8")) value_before = get_nested_value(toml_data, self.file_change.key_path) if value_before is None: From 9515afcde882e3e5a9cdb51cd91d43ef5d711485 Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Sat, 10 Feb 2024 08:39:51 -0600 Subject: [PATCH 3/3] Fixed linting errors --- .pre-commit-config.yaml | 9 ++--- bumpversion/__main__.py | 1 + bumpversion/aliases.py | 1 + bumpversion/bump.py | 1 + bumpversion/cli.py | 1 + bumpversion/config/__init__.py | 1 + bumpversion/config/models.py | 1 + bumpversion/config/utils.py | 1 + bumpversion/exceptions.py | 1 + bumpversion/indented_logger.py | 1 + bumpversion/show.py | 1 + bumpversion/ui.py | 1 + bumpversion/utils.py | 1 + bumpversion/version_part.py | 1 + bumpversion/versioning/conventions.py | 1 + bumpversion/versioning/functions.py | 1 + bumpversion/versioning/models.py | 1 + bumpversion/versioning/serialization.py | 1 + bumpversion/visualize.py | 1 + bumpversion/yaml_dump.py | 1 + docsrc/conf.py | 1 + pyproject.toml | 39 ++++++++++----------- tests/conftest.py | 1 + tests/test_autocast.py | 1 + tests/test_bump.py | 1 + tests/test_cli/test_bump.py | 1 + tests/test_cli/test_replace.py | 1 + tests/test_cli/test_show_bump.py | 1 + tests/test_config/test_create.py | 1 + tests/test_config/test_files.py | 1 + tests/test_configuredfile.py | 1 + tests/test_files.py | 1 + tests/test_scm.py | 1 + tests/test_utils.py | 1 + tests/test_versioning/test_serialization.py | 1 + tests/test_visualize.py | 1 + tests/test_yaml.py | 1 + 37 files changed, 57 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d8a574f9..8c42c8ff 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.2.0' + rev: 'v0.2.1' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -45,7 +45,7 @@ repos: args: [--no-strict-optional, --ignore-missing-imports] additional_dependencies: ["pydantic>2.0", "toml", "types-all"] - repo: https://github.com/jsh9/pydoclint - rev: 0.3.9 + rev: 0.4.0 hooks: - id: pydoclint args: @@ -55,9 +55,6 @@ repos: hooks: - id: interrogate exclude: test.* - - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.27.4 - hooks: - - id: check-azure-pipelines + ci: autofix_prs: false diff --git a/bumpversion/__main__.py b/bumpversion/__main__.py index a93d92ae..d0feb755 100644 --- a/bumpversion/__main__.py +++ b/bumpversion/__main__.py @@ -1,4 +1,5 @@ """Main entrypoint for module.""" + from bumpversion.cli import cli cli() diff --git a/bumpversion/aliases.py b/bumpversion/aliases.py index 92353098..3a630af9 100644 --- a/bumpversion/aliases.py +++ b/bumpversion/aliases.py @@ -1,4 +1,5 @@ """Utilities for handling command aliases.""" + from typing import List, Optional import rich_click as click diff --git a/bumpversion/bump.py b/bumpversion/bump.py index 75aea7a5..eb6f1e99 100644 --- a/bumpversion/bump.py +++ b/bumpversion/bump.py @@ -1,4 +1,5 @@ """Version changing methods.""" + import shlex from pathlib import Path from typing import TYPE_CHECKING, ChainMap, List, Optional diff --git a/bumpversion/cli.py b/bumpversion/cli.py index c3a06038..eaf23e91 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -1,4 +1,5 @@ """bump-my-version Command line interface.""" + from pathlib import Path from typing import List, Optional diff --git a/bumpversion/config/__init__.py b/bumpversion/config/__init__.py index 12de9b7e..6bb68846 100644 --- a/bumpversion/config/__init__.py +++ b/bumpversion/config/__init__.py @@ -1,4 +1,5 @@ """Configuration management.""" + from __future__ import annotations from typing import TYPE_CHECKING, Union diff --git a/bumpversion/config/models.py b/bumpversion/config/models.py index f7cfbce6..261efa59 100644 --- a/bumpversion/config/models.py +++ b/bumpversion/config/models.py @@ -1,4 +1,5 @@ """Bump My Version configuration models.""" + from __future__ import annotations import re diff --git a/bumpversion/config/utils.py b/bumpversion/config/utils.py index 9c6d3df5..ffb5f939 100644 --- a/bumpversion/config/utils.py +++ b/bumpversion/config/utils.py @@ -1,4 +1,5 @@ """Helper functions for the config module.""" + from __future__ import annotations import glob diff --git a/bumpversion/exceptions.py b/bumpversion/exceptions.py index 8ca84bc0..7c9a5b25 100644 --- a/bumpversion/exceptions.py +++ b/bumpversion/exceptions.py @@ -1,4 +1,5 @@ """Custom exceptions for BumpVersion.""" + from typing import Optional from click import Context, UsageError diff --git a/bumpversion/indented_logger.py b/bumpversion/indented_logger.py index a8b8faad..41374f66 100644 --- a/bumpversion/indented_logger.py +++ b/bumpversion/indented_logger.py @@ -1,4 +1,5 @@ """A logger adapter that adds an indent to the beginning of each message.""" + import logging from contextvars import ContextVar from typing import Any, MutableMapping, Optional, Tuple diff --git a/bumpversion/show.py b/bumpversion/show.py index 31f75800..3107334f 100644 --- a/bumpversion/show.py +++ b/bumpversion/show.py @@ -1,4 +1,5 @@ """Functions for displaying information about the version.""" + import dataclasses from io import StringIO from pprint import pprint diff --git a/bumpversion/ui.py b/bumpversion/ui.py index a1a367e3..8b8fa110 100644 --- a/bumpversion/ui.py +++ b/bumpversion/ui.py @@ -1,4 +1,5 @@ """Utilities for user interface.""" + import logging import click diff --git a/bumpversion/utils.py b/bumpversion/utils.py index 7ceb3cff..9cab66df 100644 --- a/bumpversion/utils.py +++ b/bumpversion/utils.py @@ -1,4 +1,5 @@ """General utilities.""" + import datetime import string from collections import ChainMap diff --git a/bumpversion/version_part.py b/bumpversion/version_part.py index 57cde5db..e8b1ad6f 100644 --- a/bumpversion/version_part.py +++ b/bumpversion/version_part.py @@ -1,4 +1,5 @@ """Module for managing Versions and their internal parts.""" + import re from typing import Any, Dict, List, MutableMapping, Optional, Tuple diff --git a/bumpversion/versioning/conventions.py b/bumpversion/versioning/conventions.py index 9a956f9d..7036a2e2 100644 --- a/bumpversion/versioning/conventions.py +++ b/bumpversion/versioning/conventions.py @@ -1,4 +1,5 @@ """Standard version conventions.""" + from bumpversion.versioning.models import VersionComponentSpec, VersionSpec # Adapted from https://packaging.python.org/en/latest/specifications/version-specifiers/ diff --git a/bumpversion/versioning/functions.py b/bumpversion/versioning/functions.py index 3d4c5a8c..7a9cff5c 100644 --- a/bumpversion/versioning/functions.py +++ b/bumpversion/versioning/functions.py @@ -1,4 +1,5 @@ """Generators for version parts.""" + import re from typing import List, Optional, Union diff --git a/bumpversion/versioning/models.py b/bumpversion/versioning/models.py index 181140d3..a37d3d99 100644 --- a/bumpversion/versioning/models.py +++ b/bumpversion/versioning/models.py @@ -1,4 +1,5 @@ """Models for managing versioning of software projects.""" + from __future__ import annotations from collections import defaultdict, deque diff --git a/bumpversion/versioning/serialization.py b/bumpversion/versioning/serialization.py index 926266b2..b119d652 100644 --- a/bumpversion/versioning/serialization.py +++ b/bumpversion/versioning/serialization.py @@ -1,4 +1,5 @@ """Functions for serializing and deserializing version objects.""" + import re from copy import copy from operator import itemgetter diff --git a/bumpversion/visualize.py b/bumpversion/visualize.py index 29e505b0..d9c959f5 100644 --- a/bumpversion/visualize.py +++ b/bumpversion/visualize.py @@ -1,4 +1,5 @@ """Visualize the bumpversion process.""" + from dataclasses import dataclass from typing import List, Optional diff --git a/bumpversion/yaml_dump.py b/bumpversion/yaml_dump.py index c4ab0acf..fc6eab46 100644 --- a/bumpversion/yaml_dump.py +++ b/bumpversion/yaml_dump.py @@ -1,4 +1,5 @@ """A simple YAML dumper to avoid extra dependencies.""" + import datetime from collections import UserDict from io import StringIO diff --git a/docsrc/conf.py b/docsrc/conf.py index abd4eb87..873020ef 100644 --- a/docsrc/conf.py +++ b/docsrc/conf.py @@ -1,6 +1,7 @@ """ Sphinx configuration. """ + # flake8: noqa import os import sys diff --git a/pyproject.toml b/pyproject.toml index cf8aeaf2..a1c32b78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -147,22 +147,6 @@ color = true line-length = 119 [tool.ruff] -# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. -# "UP" "TRY" "PLR" -select = ["E", "W", "F", "I", "N", "B", "BLE", "C", "D", "E", "F", "I", "N", "S", "T", "W", "RUF", "NPY", "PD", "PGH", "ANN", "C90", "PLC", "PLE", "PLW", "TCH"] -ignore = [ - "ANN002", "ANN003", "ANN101", "ANN102", "ANN204", "ANN401", - "S101", "S104", - "D105", "D106", "D107", "D200", "D212", - "PD011", - "PLW1510", -] - -# Allow autofix for all enabled rules (when `--fix`) is provided. -fixable = ["E", "W", "F", "I", "N", "B", "BLE", "C", "D", "E", "F", "I", "N", "S", "T", "W", "RUF", "NPY", "PD", "PGH", "ANN", "C90", "PL", "PLC", "PLE", "PLW", "TCH"] -unfixable = [] - -# Exclude a variety of commonly ignored directories. exclude = [ ".bzr", ".direnv", @@ -189,22 +173,37 @@ exclude = [ # Same as Black. line-length = 119 +[tool.ruff.lint] +select = ["E", "W", "F", "I", "N", "B", "BLE", "C", "D", "E", "F", "I", "N", "S", "T", "W", "RUF", "NPY", "PD", "PGH", "ANN", "C90", "PLC", "PLE", "PLW", "TCH"] +ignore = [ + "ANN002", "ANN003", "ANN101", "ANN102", "ANN204", "ANN401", + "S101", "S104", + "D105", "D106", "D107", "D200", "D212", + "PD011", + "PLW1510", +] + +fixable = ["E", "W", "F", "I", "N", "B", "BLE", "C", "D", "E", "F", "I", "N", "S", "T", "W", "RUF", "NPY", "PD", "PGH", "ANN", "C90", "PL", "PLC", "PLE", "PLW", "TCH"] +unfixable = [] + +# Exclude a variety of commonly ignored directories. + # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" typing-modules = ["typing", "types", "typing_extensions", "mypy", "mypy_extensions"] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "tests/*" = ["S101", "PLR0913", "PLR0915", "PGH003", "ANN001", "ANN202", "ANN201", "PLR0912", "TRY301", "PLW0603", "PLR2004", "ANN101", "S106", "TRY201", "ANN003", "ANN002", "S105", "TRY003"] -[tool.ruff.mccabe] +[tool.ruff.lint.mccabe] # Unlike Flake8, default to a complexity level of 10. max-complexity = 10 -[tool.ruff.isort] +[tool.ruff.lint.isort] order-by-type = true -[tool.ruff.pydocstyle] +[tool.ruff.lint.pydocstyle] convention = "google" [tool.bumpversion] diff --git a/tests/conftest.py b/tests/conftest.py index 377eaab6..1644fa91 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ """Testing fixtures for Pytest.""" + import subprocess from contextlib import contextmanager from pathlib import Path diff --git a/tests/test_autocast.py b/tests/test_autocast.py index 10baad77..28204ad8 100644 --- a/tests/test_autocast.py +++ b/tests/test_autocast.py @@ -1,4 +1,5 @@ """Tests for the autocast module.""" + import pytest from pytest import param diff --git a/tests/test_bump.py b/tests/test_bump.py index 0c8dc9c8..8e1a8d5a 100644 --- a/tests/test_bump.py +++ b/tests/test_bump.py @@ -1,4 +1,5 @@ """Tests for the bump module.""" + from pathlib import Path from textwrap import dedent from unittest.mock import MagicMock, patch diff --git a/tests/test_cli/test_bump.py b/tests/test_cli/test_bump.py index f7a3ff89..6105e2d6 100644 --- a/tests/test_cli/test_bump.py +++ b/tests/test_cli/test_bump.py @@ -1,4 +1,5 @@ """Tests the bump CLI subcommand.""" + import shutil import subprocess from datetime import datetime diff --git a/tests/test_cli/test_replace.py b/tests/test_cli/test_replace.py index eef80cf7..d749d995 100644 --- a/tests/test_cli/test_replace.py +++ b/tests/test_cli/test_replace.py @@ -1,4 +1,5 @@ """Tests for `bumpversion` package.""" + import shutil import traceback from pathlib import Path diff --git a/tests/test_cli/test_show_bump.py b/tests/test_cli/test_show_bump.py index b9d6cb2c..97e8a752 100644 --- a/tests/test_cli/test_show_bump.py +++ b/tests/test_cli/test_show_bump.py @@ -1,4 +1,5 @@ """Tests the show_bump command.""" + import shutil from pathlib import Path diff --git a/tests/test_config/test_create.py b/tests/test_config/test_create.py index 524bc719..1e269565 100644 --- a/tests/test_config/test_create.py +++ b/tests/test_config/test_create.py @@ -1,4 +1,5 @@ """Test the create function in the config module.""" + from pathlib import Path import pytest diff --git a/tests/test_config/test_files.py b/tests/test_config/test_files.py index 2b07fed9..109a1090 100644 --- a/tests/test_config/test_files.py +++ b/tests/test_config/test_files.py @@ -1,4 +1,5 @@ """Test configuration parsing.""" + import difflib import json from pathlib import Path diff --git a/tests/test_configuredfile.py b/tests/test_configuredfile.py index 7acb3fce..2df3c0fc 100644 --- a/tests/test_configuredfile.py +++ b/tests/test_configuredfile.py @@ -1,4 +1,5 @@ """Tests for the ConfiguredFile class.""" + from bumpversion.files import ConfiguredFile, FileChange from bumpversion.version_part import VersionConfig from bumpversion.versioning.models import VersionComponentSpec diff --git a/tests/test_files.py b/tests/test_files.py index e90a7cba..5b10509b 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -1,4 +1,5 @@ """File processing tests.""" + import os import shutil from datetime import datetime, timezone diff --git a/tests/test_scm.py b/tests/test_scm.py index 1f93eb44..3743c339 100644 --- a/tests/test_scm.py +++ b/tests/test_scm.py @@ -1,4 +1,5 @@ """Tests of the VCS module.""" + import subprocess from pathlib import Path diff --git a/tests/test_utils.py b/tests/test_utils.py index 0142a553..47ab276b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,5 @@ """Tests for the utils module.""" + from itertools import combinations import pytest diff --git a/tests/test_versioning/test_serialization.py b/tests/test_versioning/test_serialization.py index 3e078c95..3cb9e56c 100644 --- a/tests/test_versioning/test_serialization.py +++ b/tests/test_versioning/test_serialization.py @@ -1,4 +1,5 @@ """Tests for the serialization of versioned objects.""" + from bumpversion.versioning.serialization import parse_version, serialize from bumpversion.versioning.conventions import semver_spec, SEMVER_PATTERN from bumpversion.versioning.models import Version, VersionSpec, VersionComponentSpec diff --git a/tests/test_visualize.py b/tests/test_visualize.py index 3044d056..04201461 100644 --- a/tests/test_visualize.py +++ b/tests/test_visualize.py @@ -1,4 +1,5 @@ """Tests of the visualize module.""" + from pathlib import Path from bumpversion.visualize import Border, BOX_CHARS, connection_str, lead_string, labeled_line, visualize diff --git a/tests/test_yaml.py b/tests/test_yaml.py index b006b43d..3e11206b 100644 --- a/tests/test_yaml.py +++ b/tests/test_yaml.py @@ -1,4 +1,5 @@ """Tests for the yaml serialization module.""" + from pathlib import Path from bumpversion import yaml_dump