Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4bb9131

Browse files
committed
refactor: speed up testing and wait for tags
1 parent cd5e68a commit 4bb9131

File tree

11 files changed

+99
-70
lines changed

11 files changed

+99
-70
lines changed

‎commitizen/bump.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ def _version_to_regex(version: str):
196196
return re.compile(f"{clean_regex}")
197197

198198

199-
def create_tag(version: Union[Version, str], tag_format: Optional[str] = None) -> str:
199+
def normalize_tag(
200+
version: Union[Version, str], tag_format: Optional[str] = None
201+
) -> str:
200202
"""The tag and the software version might be different.
201203
202204
That's why this function exists.

‎commitizen/changelog.py‎

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from jinja2 import Environment, PackageLoader
3535

3636
from commitizen import defaults
37+
from commitizen.bump import normalize_tag
3738
from commitizen.exceptions import InvalidConfigurationError
3839
from commitizen.git import GitCommit, GitTag
3940

@@ -284,22 +285,22 @@ def incremental_build(new_content: str, lines: List, metadata: Dict) -> List:
284285

285286

286287
def get_smart_tag_range(
287-
tags: List[GitTag], start: str, end: Optional[str] = None
288+
tags: List[GitTag], newest: str, oldest: Optional[str] = None
288289
) -> List[GitTag]:
289290
"""Smart because it finds the N+1 tag.
290291
291292
This is because we need to find until the next tag
292293
"""
293294
accumulator = []
294295
keep = False
295-
if not end:
296-
end = start
296+
if not oldest:
297+
oldest = newest
297298
for index, tag in enumerate(tags):
298-
if tag.name == start:
299+
if tag.name == newest:
299300
keep = True
300301
if keep:
301302
accumulator.append(tag)
302-
if tag.name == end:
303+
if tag.name == oldest:
303304
keep = False
304305
try:
305306
accumulator.append(tags[index + 1])
@@ -309,43 +310,43 @@ def get_smart_tag_range(
309310
return accumulator
310311

311312

312-
def get_start_and_end_rev(
313-
tags: List[GitTag], version: str, tag_format: str, create_tag: Callable
313+
def get_oldest_and_newest_rev(
314+
tags: List[GitTag], version: str, tag_format: str
314315
) -> Tuple[Optional[str], Optional[str]]:
315316
"""Find the tags for the given version.
316317
317318
`version` may come in different formats:
318319
- `0.1.0..0.4.0`: as a range
319320
- `0.3.0`: as a single version
320321
"""
321-
start: Optional[str] = None
322-
end: Optional[str] = None
322+
oldest: Optional[str] = None
323+
newest: Optional[str] = None
323324
try:
324-
start, end = version.split("..")
325+
oldest, newest = version.split("..")
325326
except ValueError:
326-
end = version
327+
newest = version
327328

328-
end_tag = create_tag(end, tag_format=tag_format)
329+
newest_tag = normalize_tag(newest, tag_format=tag_format)
329330

330-
start_tag = None
331-
if start:
332-
start_tag = create_tag(start, tag_format=tag_format)
331+
oldest_tag = None
332+
if oldest:
333+
oldest_tag = normalize_tag(oldest, tag_format=tag_format)
333334

334-
tags_range = get_smart_tag_range(tags, start=end_tag, end=start_tag)
335-
if len(tags_range) ==0:
335+
tags_range = get_smart_tag_range(tags, newest=newest_tag, oldest=oldest_tag)
336+
if nottags_range:
336337
return None, None
337338

338-
start_rev: Optional[str] = tags_range[-1].name
339-
end_rev = end_tag
339+
oldest_rev: Optional[str] = tags_range[-1].name
340+
newest_rev = newest_tag
340341

341342
# check if it's the first tag created
342343
# and it's also being requested as part of the range
343-
if start_rev == tags[-1].name and start_rev == start_tag:
344-
return None, end_rev
344+
if oldest_rev == tags[-1].name and oldest_rev == oldest_tag:
345+
return None, newest_rev
345346

346347
# when they are the same, and it's also the
347-
# first tag crated
348-
if start_rev == end_rev:
349-
return None, end_rev
348+
# first tag created
349+
if oldest_rev == newest_rev:
350+
return None, newest_rev
350351

351-
return start_rev, end_rev
352+
return oldest_rev, newest_rev

‎commitizen/commands/bump.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __call__(self): # noqa: C901
101101
is_files_only: Optional[bool] = self.arguments["files_only"]
102102
is_local_version: Optional[bool] = self.arguments["local_version"]
103103

104-
current_tag_version: str = bump.create_tag(
104+
current_tag_version: str = bump.normalize_tag(
105105
current_version, tag_format=tag_format
106106
)
107107

@@ -149,7 +149,7 @@ def __call__(self): # noqa: C901
149149
is_local_version=is_local_version,
150150
)
151151

152-
new_tag_version = bump.create_tag(new_version, tag_format=tag_format)
152+
new_tag_version = bump.normalize_tag(new_version, tag_format=tag_format)
153153
message = bump.create_commit_message(
154154
current_version, new_version, bump_commit_message
155155
)

‎commitizen/commands/changelog.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from operator import itemgetter
44
from typing import Callable, Dict, List, Optional
55

6-
from commitizen import bump, changelog, factory, git, out
6+
from commitizen import changelog, factory, git, out
77
from commitizen.config import BaseConfig
88
from commitizen.exceptions import (
99
DryRunExit,
@@ -125,7 +125,7 @@ def __call__(self):
125125
if not tags:
126126
tags = []
127127

128-
end_rev = "HEAD"
128+
end_rev = ""
129129

130130
if self.incremental:
131131
changelog_meta = changelog.get_metadata(self.file_name)
@@ -134,11 +134,10 @@ def __call__(self):
134134
start_rev = self._find_incremental_rev(latest_version, tags)
135135

136136
if self.rev_range and self.tag_format:
137-
start_rev, end_rev = changelog.get_start_and_end_rev(
137+
start_rev, end_rev = changelog.get_oldest_and_newest_rev(
138138
tags,
139139
version=self.rev_range,
140140
tag_format=self.tag_format,
141-
create_tag=bump.create_tag,
142141
)
143142

144143
commits = git.get_commits(

‎commitizen/git.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ def get_commits(
8686
)
8787

8888
if start:
89-
c = cmd.run(f"{git_log_cmd} {start}..{end}")
89+
command = f"{git_log_cmd} {start}..{end}"
9090
else:
91-
c = cmd.run(f"{git_log_cmd} {end}")
92-
91+
command = f"{git_log_cmd} {end}"
92+
c=cmd.run(command)
9393
if not c.out:
9494
return []
9595

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ types-termcolor = "^0.1.1"
7979
mkdocs = "^1.0"
8080
mkdocs-material = "^4.1"
8181
pydocstyle = "^5.0.2"
82+
pytest-xdist = "^2.5.0"
8283

8384
[tool.poetry.scripts]
8485
cz = "commitizen.cli:main"

‎scripts/test‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if [ -d 'venv' ] ; then
55
export PREFIX="venv/bin/"
66
fi
77

8-
${PREFIX}pytest --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/
8+
${PREFIX}pytest -n 3 --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/
99
${PREFIX}black commitizen tests --check
1010
${PREFIX}isort --check-only commitizen tests
1111
${PREFIX}flake8 commitizen/ tests/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /