1- from fnmatch import fnmatch
21from os import makedirs
3- from textwrap import indent
2+ from pathlib import Path
3+ from textwrap import dedent , indent
44
55from click import echo
66from click_log import simple_verbosity_option
@@ -33,7 +33,7 @@ def changelog(ctx):
3333@app_option
3434@pass_app
3535@pass_context
36- def list_all (ctx : Context , app : App ): # noqa: ARG001
36+ def list_all (_ctx : Context , app : App ):
3737 """Print out the current set of changes"""
3838 scriv = Scriv ()
3939 fragments = scriv .fragments_to_combine ()
@@ -48,24 +48,15 @@ def list_all(ctx: Context, app: App): # noqa: ARG001
4848
4949def _echo_change (change : Diff ):
5050 """Echo the change to stdout"""
51+
5152 line = [change .change_type , change .a_path ]
5253
5354 if change .renamed_file :
54- line .extend (["->" , changelog .b_path ])
55+ line .extend (["->" , change .b_path ])
5556
5657 echo (indent (" " .join (line ), "\t " ))
5758
5859
59- def _is_source_excluded (path ) -> bool :
60- excluded_paths = ["*/changelog.d/*" , "*/CHANGELOG.md" ]
61- return any ([fnmatch (path , exclude ) for exclude in excluded_paths ]) # noqa: C419
62-
63-
64- def _is_changelog_excluded (path ) -> bool :
65- excluded_paths = ["*/scriv.ini" ]
66- return any ([fnmatch (path , exclude ) for exclude in excluded_paths ]) # noqa: C419
67-
68-
6960@changelog .command ()
7061@option (
7162 "-b" ,
@@ -89,58 +80,30 @@ def check(ctx: Context, project: Project, base: str, target: str):
8980
9081 is_error = False
9182
92- for app_abs_path in list_apps ():
93- app_rel_path = app_abs_path .relative_to (project .path )
94-
95- # we count these towards a changelog being present
96- # but not against the absence of one
97- top_level_dependency_changes = [
98- change
99- for change in base_commit .diff (target_commit , paths = ["uv.lock" ])
100- if not _is_source_excluded (change .a_path )
101- and not _is_source_excluded (change .b_path )
102- ]
103- has_top_level_dependency_changes = len (top_level_dependency_changes ) > 0
104-
105- source_changes = [
106- change
107- for change in base_commit .diff (target_commit , paths = [app_rel_path ])
108- if not _is_source_excluded (change .a_path )
109- and not _is_source_excluded (change .b_path )
110- ]
111- has_source_changes = len (source_changes ) > 0
112-
113- changelogd_changes = [
114- change
115- for change in base_commit .diff (
116- target_commit , paths = [app_rel_path / "changelog.d" ]
117- )
118- if not _is_changelog_excluded (change .a_path )
119- and not _is_changelog_excluded (change .b_path )
120- ]
121- has_changelogd_changes = len (changelogd_changes ) > 0
122-
123- if has_source_changes and not has_changelogd_changes :
124- echo (f"Changelog(s) are missing in { app_rel_path } for these changes:" )
125- for change in source_changes :
83+ for app in list_apps (project ):
84+ changes = app .get_changes (base_commit = base_commit , target_commit = target_commit )
85+
86+ if changes .has_source_changes and not changes .has_changelogd_changes :
87+ echo (f"Changelog(s) are missing in { app .relative_path } for these changes:" )
88+ for change in changes .source_changes :
12689 _echo_change (change )
12790 is_error = True
12891 echo ("" )
12992 elif (
130- not has_source_changes
131- and not has_top_level_dependency_changes
132- and has_changelogd_changes
93+ not changes . has_source_changes
94+ and not changes . has_top_level_dependency_changes
95+ and changes . has_changelogd_changes
13396 ):
13497 echo (
135- f"Changelog(s) are present in { app_rel_path } but there are no source changes:" # noqa: E501
98+ f"Changelog(s) are present in { app . relative_path } but there are no source changes:" # noqa: E501
13699 )
137- for change in changelogd_changes :
100+ for change in changes . changelogd_changes :
138101 _echo_change (change )
139102 is_error = True
140103 echo ("" )
141104
142105 # verify the fragments aren't empty
143- with chdir (app_abs_path ):
106+ with chdir (app . absolute_path ):
144107 scriv = Scriv ()
145108 fragments = scriv .fragments_to_combine ()
146109 for fragment in fragments :
@@ -149,7 +112,9 @@ def check(ctx: Context, project: Project, base: str, target: str):
149112 empty_fragments = list (filter (lambda frag : not frag .content .strip (), fragments ))
150113
151114 if empty_fragments :
152- echo (f"Changelog(s) are present in { app_rel_path } but have no content:" )
115+ echo (
116+ f"Changelog(s) are present in { app .relative_path } but have no content:"
117+ )
153118 for fragment in empty_fragments :
154119 echo (f"\t { fragment .path } " )
155120 is_error = True
@@ -159,5 +124,34 @@ def check(ctx: Context, project: Project, base: str, target: str):
159124 ctx .exit (1 )
160125
161126
127+ @changelog .command ("create-renovate" )
128+ @option (
129+ "-m" ,
130+ "--message" ,
131+ help = "The message for the changelog line" ,
132+ required = True ,
133+ )
134+ @pass_project
135+ def create_renovate (project : Project , message : str ):
136+ """Create a changelog for renovate"""
137+ for changed in project .repo .head .commit .diff (None ):
138+ if not changed .a_path .endswith ("pyproject.toml" ):
139+ continue
140+
141+ echo (f"Adding changelog for: { changed .a_path } " )
142+
143+ with chdir (Path (changed .a_path ).parent ):
144+ scriv = Scriv ()
145+ frag = scriv .new_fragment ()
146+
147+ frag .content = dedent (
148+ f"""
149+ ### Changed
150+
151+ - { message } """
152+ )
153+ frag .write ()
154+
155+
162156if __name__ == "__main__" :
163157 changelog ()
0 commit comments