-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/pip/urllib3-2.0.7
- Loading branch information
Showing
49 changed files
with
2,240 additions
and
646 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "3.11.0" | ||
__version__ = "3.12.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from __future__ import annotations | ||
|
||
from typing import ClassVar, Protocol | ||
|
||
import importlib_metadata as metadata | ||
|
||
from commitizen.changelog import Metadata | ||
from commitizen.exceptions import ChangelogFormatUnknown | ||
from commitizen.config.base_config import BaseConfig | ||
|
||
|
||
CHANGELOG_FORMAT_ENTRYPOINT = "commitizen.changelog_format" | ||
TEMPLATE_EXTENSION = "j2" | ||
|
||
|
||
class ChangelogFormat(Protocol): | ||
extension: ClassVar[str] | ||
"""Standard known extension associated with this format""" | ||
|
||
alternative_extensions: ClassVar[set[str]] | ||
"""Known alternatives extensions for this format""" | ||
|
||
config: BaseConfig | ||
|
||
def __init__(self, config: BaseConfig): | ||
self.config = config | ||
|
||
@property | ||
def ext(self) -> str: | ||
"""Dotted version of extensions, as in `pathlib` and `os` modules""" | ||
return f".{self.extension}" | ||
|
||
@property | ||
def template(self) -> str: | ||
"""Expected template name for this format""" | ||
return f"CHANGELOG.{self.extension}.{TEMPLATE_EXTENSION}" | ||
|
||
@property | ||
def default_changelog_file(self) -> str: | ||
return f"CHANGELOG.{self.extension}" | ||
|
||
def get_metadata(self, filepath: str) -> Metadata: | ||
""" | ||
Extract the changelog metadata. | ||
""" | ||
raise NotImplementedError | ||
|
||
|
||
KNOWN_CHANGELOG_FORMATS: dict[str, type[ChangelogFormat]] = { | ||
ep.name: ep.load() | ||
for ep in metadata.entry_points(group=CHANGELOG_FORMAT_ENTRYPOINT) | ||
} | ||
|
||
|
||
def get_changelog_format( | ||
config: BaseConfig, filename: str | None = None | ||
) -> ChangelogFormat: | ||
""" | ||
Get a format from its name | ||
:raises FormatUnknown: if a non-empty name is provided but cannot be found in the known formats | ||
""" | ||
name: str | None = config.settings.get("changelog_format") | ||
format: type[ChangelogFormat] | None = guess_changelog_format(filename) | ||
|
||
if name and name in KNOWN_CHANGELOG_FORMATS: | ||
format = KNOWN_CHANGELOG_FORMATS[name] | ||
|
||
if not format: | ||
raise ChangelogFormatUnknown(f"Unknown changelog format '{name}'") | ||
|
||
return format(config) | ||
|
||
|
||
def guess_changelog_format(filename: str | None) -> type[ChangelogFormat] | None: | ||
""" | ||
Try guessing the file format from the filename. | ||
Algorithm is basic, extension-based, and won't work | ||
for extension-less file names like `CHANGELOG` or `NEWS`. | ||
""" | ||
if not filename or not isinstance(filename, str): | ||
return None | ||
for format in KNOWN_CHANGELOG_FORMATS.values(): | ||
if filename.endswith(f".{format.extension}"): | ||
return format | ||
for alt_extension in format.alternative_extensions: | ||
if filename.endswith(f".{alt_extension}"): | ||
return format | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from __future__ import annotations | ||
|
||
import re | ||
|
||
from .base import BaseFormat | ||
|
||
|
||
class AsciiDoc(BaseFormat): | ||
extension = "adoc" | ||
|
||
RE_TITLE = re.compile(r"^(?P<level>=+) (?P<title>.*)$") | ||
|
||
def parse_version_from_title(self, line: str) -> str | None: | ||
m = self.RE_TITLE.match(line) | ||
if not m: | ||
return None | ||
# Capture last match as AsciiDoc use postfixed URL labels | ||
matches = list(re.finditer(self.version_parser, m.group("title"))) | ||
if not matches: | ||
return None | ||
return matches[-1].group("version") | ||
|
||
def parse_title_level(self, line: str) -> int | None: | ||
m = self.RE_TITLE.match(line) | ||
if not m: | ||
return None | ||
return len(m.group("level")) |
Oops, something went wrong.