Skip to content

refactor(default): capitalize all constants and remove unnecessary variables #1421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions commitizen/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from string import Template
from typing import cast

from commitizen.defaults import MAJOR, MINOR, PATCH, bump_message, encoding
from commitizen.defaults import BUMP_MESSAGE, ENCODING, MAJOR, MINOR, PATCH
from commitizen.exceptions import CurrentVersionNotFoundError
from commitizen.git import GitCommit, smart_open
from commitizen.version_schemes import Increment, Version
Expand Down Expand Up @@ -64,7 +64,7 @@ def update_version_in_files(
files: list[str],
*,
check_consistency: bool = False,
encoding: str = encoding,
encoding: str = ENCODING,
) -> list[str]:
"""Change old version to the new one in every file given.

Expand Down Expand Up @@ -121,7 +121,7 @@ def _bump_with_regex(
current_version: str,
new_version: str,
regex: str,
encoding: str = encoding,
encoding: str = ENCODING,
) -> tuple[bool, str]:
current_version_found = False
lines = []
Expand All @@ -148,6 +148,6 @@ def create_commit_message(
message_template: str | None = None,
) -> str:
if message_template is None:
message_template = bump_message
message_template = BUMP_MESSAGE
t = Template(message_template)
return t.safe_substitute(current_version=current_version, new_version=new_version)
2 changes: 1 addition & 1 deletion commitizen/commands/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, config: BaseConfig, args):
self.change_type_order = (
self.config.settings.get("change_type_order")
or self.cz.change_type_order
or defaults.change_type_order
or defaults.CHANGE_TYPE_ORDER
)
self.rev_range = args.get("rev_range")
self.tag_format: str = (
Expand Down
4 changes: 2 additions & 2 deletions commitizen/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from commitizen.__version__ import __version__
from commitizen.config import BaseConfig, JsonConfig, TomlConfig, YAMLConfig
from commitizen.cz import registry
from commitizen.defaults import DEFAULT_SETTINGS, config_files
from commitizen.defaults import CONFIG_FILES, DEFAULT_SETTINGS
from commitizen.exceptions import InitFailedError, NoAnswersError
from commitizen.git import get_latest_tag_name, get_tag_names, smart_open
from commitizen.version_schemes import KNOWN_SCHEMES, Version, get_version_scheme
Expand Down Expand Up @@ -165,7 +165,7 @@ def _ask_config_path(self) -> str:

name: str = questionary.select(
"Please choose a supported config file: ",
choices=config_files,
choices=CONFIG_FILES,
default=default_path,
style=self.cz.style,
).unsafe_ask()
Expand Down
2 changes: 1 addition & 1 deletion commitizen/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def read_cfg(filepath: str | None = None) -> BaseConfig:
cfg_paths = (
path / Path(filename)
for path in cfg_search_paths
for filename in defaults.config_files
for filename in defaults.CONFIG_FILES
)

for filename in cfg_paths:
Expand Down
8 changes: 4 additions & 4 deletions commitizen/cz/conventional_commits/conventional_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ def parse_subject(text):


class ConventionalCommitsCz(BaseCommitizen):
bump_pattern = defaults.bump_pattern
bump_map = defaults.bump_map
bump_map_major_version_zero = defaults.bump_map_major_version_zero
bump_pattern = defaults.BUMP_PATTERN
bump_map = defaults.BUMP_MAP
bump_map_major_version_zero = defaults.BUMP_MAP_MAJOR_VERSION_ZERO
commit_parser = r"^((?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?|\w+!):\s(?P<message>.*)?" # noqa
change_type_map = {
"feat": "Feat",
"fix": "Fix",
"refactor": "Refactor",
"perf": "Perf",
}
changelog_pattern = defaults.bump_pattern
changelog_pattern = defaults.BUMP_PATTERN

def questions(self) -> Questions:
questions: Questions = [
Expand Down
8 changes: 4 additions & 4 deletions commitizen/cz/customize/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@


class CustomizeCommitsCz(BaseCommitizen):
bump_pattern = defaults.bump_pattern
bump_map = defaults.bump_map
bump_map_major_version_zero = defaults.bump_map_major_version_zero
change_type_order = defaults.change_type_order
bump_pattern = defaults.BUMP_PATTERN
bump_map = defaults.BUMP_MAP
bump_map_major_version_zero = defaults.BUMP_MAP_MAJOR_VERSION_ZERO
change_type_order = defaults.CHANGE_TYPE_ORDER

def __init__(self, config: BaseConfig):
super().__init__(config)
Expand Down
19 changes: 9 additions & 10 deletions commitizen/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class Settings(TypedDict, total=False):
extras: dict[str, Any]


name: str = "cz_conventional_commits"
config_files: list[str] = [
CONFIG_FILES: list[str] = [
"pyproject.toml",
".cz.toml",
".cz.json",
Expand All @@ -70,10 +69,10 @@ class Settings(TypedDict, total=False):
"cz.yaml",
"cz.toml",
]
encoding: str = "utf-8"
ENCODING = "utf-8"

DEFAULT_SETTINGS: Settings = {
"name": name,
"name": "cz_conventional_commits",
"version": None,
"version_files": [],
"version_provider": "commitizen",
Expand Down Expand Up @@ -102,7 +101,7 @@ class Settings(TypedDict, total=False):
"pre_bump_hooks": [],
"post_bump_hooks": [],
"prerelease_offset": 0,
"encoding": encoding,
"encoding": ENCODING,
"always_signoff": False,
"template": None, # default provided by plugin
"extras": {},
Expand All @@ -114,8 +113,8 @@ class Settings(TypedDict, total=False):

CHANGELOG_FORMAT = "markdown"

bump_pattern = r"^((BREAKING[\-\ ]CHANGE|\w+)(\(.+\))?!?):"
bump_map = OrderedDict(
BUMP_PATTERN = r"^((BREAKING[\-\ ]CHANGE|\w+)(\(.+\))?!?):"
BUMP_MAP = OrderedDict(
(
(r"^.+!$", MAJOR),
(r"^BREAKING[\-\ ]CHANGE", MAJOR),
Expand All @@ -125,7 +124,7 @@ class Settings(TypedDict, total=False):
(r"^perf", PATCH),
)
)
bump_map_major_version_zero = OrderedDict(
BUMP_MAP_MAJOR_VERSION_ZERO = OrderedDict(
(
(r"^.+!$", MINOR),
(r"^BREAKING[\-\ ]CHANGE", MINOR),
Expand All @@ -135,8 +134,8 @@ class Settings(TypedDict, total=False):
(r"^perf", PATCH),
)
)
change_type_order = ["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"]
bump_message = "bump: version $current_version → $new_version"
CHANGE_TYPE_ORDER = ["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"]
BUMP_MESSAGE = "bump: version $current_version → $new_version"


def get_tag_regexes(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_find_git_project_root(tmpdir):


@pytest.mark.parametrize(
"config_files_manager", defaults.config_files.copy(), indirect=True
"config_files_manager", defaults.CONFIG_FILES.copy(), indirect=True
)
def test_set_key(config_files_manager):
_conf = config.read_cfg()
Expand All @@ -162,7 +162,7 @@ def test_set_key(config_files_manager):

class TestReadCfg:
@pytest.mark.parametrize(
"config_files_manager", defaults.config_files.copy(), indirect=True
"config_files_manager", defaults.CONFIG_FILES.copy(), indirect=True
)
def test_load_conf(_, config_files_manager):
cfg = config.read_cfg()
Expand Down