Skip to content

Commit

Permalink
Fixed logging and regex regression in 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Dec 6, 2023
1 parent 8188a42 commit cae12dc
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ repos:
rev: 0.27.1
hooks:
- id: check-azure-pipelines
ci:
autofix_prs: false
3 changes: 1 addition & 2 deletions bumpversion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from bumpversion.config import get_configuration
from bumpversion.config.files import find_config_file
from bumpversion.files import ConfiguredFile, modify_files
from bumpversion.logging import setup_logging
from bumpversion.show import do_show, log_list
from bumpversion.ui import print_warning
from bumpversion.ui import print_warning, setup_logging
from bumpversion.utils import get_context, get_overrides

logger = logging.getLogger(__name__)
Expand Down
29 changes: 0 additions & 29 deletions bumpversion/logging.py

This file was deleted.

4 changes: 4 additions & 0 deletions bumpversion/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from tempfile import NamedTemporaryFile
from typing import TYPE_CHECKING, ClassVar, List, MutableMapping, Optional, Type, Union

from utils import extract_regex_flags

if TYPE_CHECKING: # pragma: no-coverage
from bumpversion.config import Config

Expand Down Expand Up @@ -113,7 +115,9 @@ def get_all_tags(cls) -> List[str]:
def get_version_from_tag(cls, tag: str, tag_name: str, parse_pattern: str) -> Optional[str]:
"""Return the version from a tag."""
version_pattern = parse_pattern.replace("\\\\", "\\")
version_pattern, regex_flags = extract_regex_flags(version_pattern)
rep = tag_name.replace("{new_version}", f"(?P<current_version>{version_pattern})")
rep = f"{regex_flags}{rep}"
tag_regex = re.compile(rep)
return match["current_version"] if (match := tag_regex.match(tag)) else None

Expand Down
28 changes: 28 additions & 0 deletions bumpversion/ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
"""Utilities for user interface."""
import logging

import click
from click import UsageError, secho
from rich.logging import RichHandler

logger = logging.getLogger("bumpversion")

VERBOSITY = {
0: logging.WARNING,
1: logging.INFO,
2: logging.DEBUG,
}


def setup_logging(verbose: int = 0) -> None:
"""Configure the logging."""
logging.basicConfig(
level=VERBOSITY.get(verbose, logging.DEBUG),
format="%(message)s",
datefmt="[%X]",
handlers=[
RichHandler(
rich_tracebacks=True, show_level=False, show_path=False, show_time=False, tracebacks_suppress=[click]
)
],
)
root_logger = logging.getLogger("")
root_logger.setLevel(VERBOSITY.get(verbose, logging.DEBUG))


def print_info(msg: str) -> None:
Expand Down
19 changes: 18 additions & 1 deletion bumpversion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
import string
from collections import ChainMap
from dataclasses import asdict
from typing import TYPE_CHECKING, Any, List, Optional
from typing import TYPE_CHECKING, Any, List, Optional, Tuple

if TYPE_CHECKING: # pragma: no-coverage
from bumpversion.config import Config
from bumpversion.version_part import Version


def extract_regex_flags(regex_pattern: str) -> Tuple[str, str]:
"""
Extract the regex flags from the regex pattern.
Args:
regex_pattern: The pattern that might start with regex flags
Returns:
A tuple of the regex pattern without the flag string and regex flag string
"""
import re

flag_pattern = r"^(\(\?[aiLmsux]+\))"
bits = re.split(flag_pattern, regex_pattern)
return (regex_pattern, "") if len(bits) == 1 else (bits[2], bits[1])


def recursive_sort_dict(input_value: Any) -> Any:
"""Sort a dictionary recursively."""
if not isinstance(input_value, dict):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from bumpversion import scm
from bumpversion.exceptions import DirtyWorkingDirectoryError
from bumpversion.logging import setup_logging
from bumpversion.ui import setup_logging
from tests.conftest import get_config_data, inside_dir


Expand Down

0 comments on commit cae12dc

Please sign in to comment.