Skip to content

Commit a8ded3f

Browse files
committed
Updated configuration.
- Fixed `DEFAULT_IGNORE_PATTERNS` with commas - Updated `DEFAULT_STARTING_TAG_PIPELINE` with better pattern - Added `chg` to ``DEFAULT_SECTION_PATTERNS` - Added `DEFAULT_OUTPUT_PIPELINE` for incremental changes - Added `valid_author_tokens` to configuration
1 parent 6cbdc83 commit a8ded3f

3 files changed

Lines changed: 65 additions & 12 deletions

File tree

clgen/configuration.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
StrOrCallable = Union[str, Callable[[], str]]
1111
"""The type should be either a string or a callable that returns a string."""
1212

13+
IntOrCallable = Union[int, Callable[[], int]]
14+
"""The type should be either an int or a callable that returns an int."""
15+
1316
DEFAULT_CONFIG_FILE_NAME = ".clgen"
1417
"""Base default configuration file name"""
1518

@@ -34,20 +37,18 @@
3437
]
3538

3639
DEFAULT_IGNORE_PATTERNS = [
37-
"[@!]minor"
38-
"[@!]cosmetic"
39-
"[@!]refactor"
40-
"[@!]wip"
41-
"[Ff]irst commit"
42-
"[Ii]nitial commit"
43-
"^$" # ignore commits with empty messages
44-
"^Merge branch"
45-
"^Merge pull"
40+
"[@!]minor",
41+
"[@!]cosmetic",
42+
"[@!]refactor",
43+
"[@!]wip",
44+
"^$", # ignore commits with empty messages
45+
"^Merge branch",
46+
"^Merge pull",
4647
]
4748

4849
DEFAULT_SECTION_PATTERNS = {
4950
"New": [r"(?i)^(?:new|add)[^\n]*$"],
50-
"Updates": [r"(?i)^(?:update|change|rename|remove|delete|improve|refactor)[^\n]*$"],
51+
"Updates": [r"(?i)^(?:update|change|rename|remove|delete|improve|refactor|chg)[^\n]*$"],
5152
"Fixes": [r"(?i)^(?:fix)[^\n]*$"],
5253
"Other": None, # Match all lines
5354
}
@@ -56,9 +57,9 @@
5657
DEFAULT_STARTING_TAG_PIPELINE = [
5758
{"action": "ReadFile", "kwargs": {"filename": "CHANGELOG.md"}},
5859
{
59-
"action": "GetFirstRegExMatch",
60+
"action": "FirstRegExMatch",
6061
"kwargs": {
61-
"pattern": r"^## (?P<rev>[0-9]+\.[0-9]+(?:\.[0-9]+)?)\s+\([0-9]+-[0-9]{2}-[0-9]{2}\)$",
62+
"pattern": r"(?im)^## (?P<rev>\d+\.\d+(?:\.\d+)?)\s+\(\d+-\d{2}-\d{2}\)$",
6263
"named_subgroup": "rev",
6364
},
6465
},
@@ -84,6 +85,16 @@
8485
}
8586
]
8687

88+
DEFAULT_OUTPUT_PIPELINE = [
89+
{
90+
"action": "IncrementalFileInsert",
91+
"kwargs": {
92+
"filename": "CHANGELOG.md",
93+
"last_heading_pattern": r"(?im)^## \d+\.\d+(?:\.\d+)?\s+\([0-9]+-[0-9]{2}-[0-9]{2}\)$",
94+
},
95+
},
96+
]
97+
8798

8899
@dataclass
89100
class Configuration:
@@ -128,6 +139,9 @@ class Configuration:
128139
section_patterns: dict = field(default_factory=dict)
129140
"""Group commits into groups if they match any of these regular expressions."""
130141

142+
valid_author_tokens: list = field(default_factory=list)
143+
"""Tokens in git commit trailers that indicate authorship."""
144+
131145
def update_from_file(self, filename: Path):
132146
"""Updates the configuration from a YAML file."""
133147
file_path = filename.expanduser().resolve()
@@ -156,6 +170,7 @@ def get_default_config() -> Configuration:
156170
body_pipeline=DEFAULT_BODY_PIPELINE,
157171
subject_pipeline=DEFAULT_SUBJECT_PIPELINE,
158172
starting_tag_pipeline=DEFAULT_STARTING_TAG_PIPELINE,
173+
output_pipeline=DEFAULT_OUTPUT_PIPELINE,
159174
)
160175

161176

test/fixtures/sample_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
unreleased_label: Not Done Yet
2+
not_valid: true

test/test_configuration.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Test configuration."""
2+
from pathlib import Path
3+
4+
import click.exceptions
5+
import pytest
6+
7+
from clgen import configuration
8+
9+
FIXTURES_DIR = Path(__file__).parent / "fixtures"
10+
11+
12+
def test_update_from_file():
13+
"""A configuration file should update the default configuration."""
14+
config_file_path = FIXTURES_DIR / "sample_config.yml"
15+
configuration.CONFIG.update_from_file(config_file_path)
16+
assert configuration.CONFIG.unreleased_label == "Not Done Yet"
17+
assert not hasattr(configuration.CONFIG, "not_valid")
18+
19+
with pytest.raises(click.exceptions.Exit):
20+
configuration.CONFIG.update_from_file(FIXTURES_DIR / "missing.yml")
21+
22+
with pytest.raises(click.exceptions.Exit):
23+
configuration.CONFIG.update_from_file(FIXTURES_DIR)
24+
25+
26+
def test_write_default_config(tmp_path):
27+
"""Writing a default config should be accurate."""
28+
test_config_file = tmp_path / "test_config.yml"
29+
configuration.write_default_config(test_config_file)
30+
31+
default_config = configuration.get_default_config()
32+
test_config = configuration.Configuration()
33+
assert default_config != test_config
34+
35+
test_config.update_from_file(test_config_file)
36+
assert default_config == test_config

0 commit comments

Comments
 (0)