Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

refactor: improve readability and fix typos #1416

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
18 changes: 10 additions & 8 deletions commitizen/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def update_version_in_files(
"""
# TODO: separate check step and write step
updated = []
for path, regex in files_and_regexs(files, current_version):
for path, regex in _files_and_regexes(files, current_version):
current_version_found, version_file = _bump_with_regex(
path,
current_version,
Expand All @@ -99,7 +99,7 @@ def update_version_in_files(
return updated


def files_and_regexs(patterns: list[str], version: str) -> list[tuple[str, str]]:
def _files_and_regexes(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
"""
Expand Down Expand Up @@ -128,13 +128,15 @@ def _bump_with_regex(
pattern = re.compile(regex)
with open(version_filepath, encoding=encoding) as f:
for line in f:
if pattern.search(line):
bumped_line = line.replace(current_version, new_version)
if bumped_line != line:
current_version_found = True
lines.append(bumped_line)
else:
if not pattern.search(line):
lines.append(line)
continue

bumped_line = line.replace(current_version, new_version)
if bumped_line != line:
current_version_found = True
lines.append(bumped_line)

return current_version_found, "".join(lines)


Expand Down
2 changes: 1 addition & 1 deletion commitizen/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def process_commit_message(
def order_changelog_tree(tree: Iterable, change_type_order: list[str]) -> Iterable:
if len(set(change_type_order)) != len(change_type_order):
raise InvalidConfigurationError(
f"Change types contain duplicates types ({change_type_order})"
f"Change types contain duplicated types ({change_type_order})"
)

sorted_tree = []
Expand Down
8 changes: 2 additions & 6 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,10 @@ def main():
extra_args = " ".join(unknown_args[1:])
arguments["extra_cli_args"] = extra_args

if args.config:
conf = config.read_cfg(args.config)
else:
conf = config.read_cfg()

conf = config.read_cfg(args.config)
if args.name:
conf.update({"name": args.name})
elif not args.name and not conf.path:
elif not conf.path:
conf.update({"name": "cz_conventional_commits"})

if args.debug:
Expand Down
11 changes: 5 additions & 6 deletions commitizen/cz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from commitizen import git
from commitizen.cz import exceptions

_RE_LOCAL_VERSION = re.compile(r"\+.+")


def required_validator(answer, msg=None):
if not answer:
Expand All @@ -17,16 +19,13 @@ def multiple_line_breaker(answer, sep="|"):


def strip_local_version(version: str) -> str:
return re.sub(r"\+.+", "", version)
return _RE_LOCAL_VERSION.sub("", version)


def get_backup_file_path() -> str:
project_root = git.find_git_project_root()

if project_root is None:
project = ""
else:
project = project_root.as_posix().replace("/", "%")
project = project_root.as_posix().replace("/", "%") if project_root else ""

user = os.environ.get("USER", "")

return os.path.join(tempfile.gettempdir(), f"cz.commit%{user}%{project}.backup")
6 changes: 3 additions & 3 deletions commitizen/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Settings(TypedDict, total=False):
def get_tag_regexes(
version_regex: str,
) -> dict[str, str]:
regexs = {
regexes = {
"version": version_regex,
"major": r"(?P<major>\d+)",
"minor": r"(?P<minor>\d+)",
Expand All @@ -151,6 +151,6 @@ def get_tag_regexes(
"devrelease": r"(?P<devrelease>\.dev\d+)?",
}
return {
**{f"${k}": v for k, v in regexs.items()},
**{f"${{{k}}}": v for k, v in regexs.items()},
**{f"${k}": v for k, v in regexes.items()},
**{f"${{{k}}}": v for k, v in regexes.items()},
}
6 changes: 1 addition & 5 deletions commitizen/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,7 @@ def include_in_changelog(self, tag: GitTag) -> bool:
version = self.extract_version(tag)
except InvalidVersion:
return False

if self.merge_prereleases and version.is_prerelease:
return False

return True
return not (self.merge_prereleases and version.is_prerelease)

def search_version(self, text: str, last: bool = False) -> VersionTag | None:
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ def test_order_changelog_tree_raises():
with pytest.raises(InvalidConfigurationError) as excinfo:
changelog.order_changelog_tree(COMMITS_TREE, change_type_order)

assert "Change types contain duplicates types" in str(excinfo)
assert "Change types contain duplicated types" in str(excinfo)


def test_render_changelog(
Expand Down