@@ -26,39 +26,20 @@ class ChangelogFile:
2626
2727 def __init__ (
2828 self ,
29- project : base_interface . IProject ,
29+ check : "AChangelogCheck" ,
3030 changelog : base_interface .IChangelog ) -> None :
31- self .project = project
31+ self .check = check
32+ self .project = check .project
3233 self .changelog = changelog
3334
34- @cached_property
35- def invalid_reflink_re (self ) -> Pattern [str ]:
36- return re .compile (INVALID_REFLINK )
37-
38- @cached_property
39- def link_ticks_re (self ) -> Pattern [str ]:
40- return re .compile (LINK_TICKS_REGEX )
41-
42- @cached_property
43- def punctuation_re (self ) -> Pattern [str ]:
44- return re .compile (REF_WITH_PUNCTUATION_REGEX )
45-
46- @cached_property
47- def ref_ticks_re (self ) -> Pattern [str ]:
48- return re .compile (REF_TICKS_REGEX )
49-
50- @cached_property
51- def single_tick_re (self ) -> Pattern [str ]:
52- return re .compile (SINGLE_TICK_REGEX )
53-
5435 def check_punctuation (self , section , entry ) -> List [str ]:
5536 change = entry ["change" ]
5637 if change .strip ().endswith ("." ):
5738 return []
5839 # Ends with punctuated link
5940 ends_with_punctuated_link = (
6041 change .strip ().endswith ('`' )
61- and self .punctuation_re .match (change .strip ()))
42+ and self .check . punctuation_re .match (change .strip ()))
6243 if ends_with_punctuated_link :
6344 return []
6445 # Ends with a list
@@ -74,58 +55,86 @@ def check_reflinks(self, section, entry) -> List[str]:
7455 [f"{ self .changelog .version } : Found text "
7556 f"\" ref:\" ({ section } /{ entry ['area' ]} ) "
7657 f"This should probably be \" :ref:\" \n { entry ['change' ]} " ]
77- if self .invalid_reflink_re .findall (entry ["change" ])
58+ if self .check . invalid_reflink_re .findall (entry ["change" ])
7859 else [])
7960
80- def check_change (self , section , entry ) -> List [str ]:
81- return [
61+ def check_change (self , section , entry ) -> Tuple [str , ... ]:
62+ return tuple (
8263 * self .check_reflinks (section , entry ),
8364 * self .check_ticks (section , entry ),
84- * self .check_punctuation (section , entry )]
65+ * self .check_punctuation (section , entry ))
8566
8667 def check_ticks (self , section , entry ) -> List [str ]:
8768 _change = entry ["change" ]
88- for reflink in self .ref_ticks_re .findall (_change ):
69+ for reflink in self .check . ref_ticks_re .findall (_change ):
8970 _change = _change .replace (reflink , "" )
90- for extlink in self .link_ticks_re .findall (_change ):
71+ for extlink in self .check . link_ticks_re .findall (_change ):
9172 _change = _change .replace (extlink , "" )
92- single_ticks = self .single_tick_re .findall (_change )
73+ single_ticks = self .check . single_tick_re .findall (_change )
9374 return (
9475 [f"{ self .changelog .version } : Single backticks found "
9576 f"({ section } /{ entry ['area' ]} ) "
9677 f"{ ', ' .join (single_ticks )} \n { _change } " ]
9778 if single_ticks
9879 else [])
9980
100- def run_checks (self ) -> List [str ]:
81+ @property
82+ def is_current (self ):
83+ return self .project .is_current (self .changelog .version )
84+
85+ def run_checks (self ) -> Tuple [str , ...]:
10186 errors = []
102- for section , entries in self .changelog .data .items ():
87+ duplicate_current = (
88+ self .is_current
89+ and (self .project .changelogs .current_path
90+ != self .changelog .path ))
91+ if duplicate_current :
92+ errors .append (
93+ f"Duplicate current version file: { self .changelog .path } " )
94+
95+ for section , data in self .changelog .data .items ():
10396 if section == "date" :
97+ missing_pending = (
98+ self .is_current
99+ and self .project .is_dev
100+ and data != "Pending" )
101+ if missing_pending :
102+ errors .append (
103+ f"{ self .changelog_version } "
104+ f"should be set to `Pending`" )
105+ incorrect_pending = (
106+ (not self .is_current
107+ or not self .project .is_dev )
108+ and data == "Pending" )
109+ if incorrect_pending :
110+ errors .append (
111+ f"{ self .changelog_version } "
112+ f"should be not set to `Pending`" )
113+ # TODO: add date format check
104114 continue
105115 if section not in self .project .changelogs .sections :
106116 errors .append (
107117 f"{ self .changelog .version } Unrecognized changelog "
108118 f"section: { section } " )
109119 if section == "changes" :
110120 no_changes_version = (
111- version . Version ( self .changelog .version )
121+ self .changelog .version
112122 > version .Version ("1.16" ))
113123 if no_changes_version :
114124 errors .append (
115125 "Removed `changes` section found: "
116126 f"{ self .changelog .version } " )
117- if not entries :
127+ if not data :
118128 continue
119- for entry in entries :
129+ for entry in data :
120130 errors .extend (self .check_change (section , entry ))
121- return errors
131+ return tuple ( errors )
122132
123133
124- class AChangelogCheck (
134+ class AProjectCheck (
125135 abstract .ACodeCheck ,
126136 metaclass = abstracts .Abstraction ):
127137 """Extensions check."""
128- changelog_file_class = ChangelogFile
129138
130139 def __init__ (
131140 self ,
@@ -135,10 +144,18 @@ def __init__(
135144 self .project = project
136145 super ().__init__ (* args , ** kwargs )
137146
147+
148+ class AChangelogCheck (
149+ AProjectCheck ,
150+ metaclass = abstracts .Abstraction ):
151+ """Extensions check."""
152+ changelog_file_class = ChangelogFile
153+
138154 @property
139- def current_changelog_path (self ) -> pathlib .Path :
140- return self .project .changelogs .current_path .relative_to (
141- self .project .path )
155+ def dev_not_pending (self ) -> bool :
156+ return (
157+ self .project .is_dev
158+ and not self .project .changelogs .is_pending )
142159
143160 @property
144161 def extra_pending (self ) -> List [str ]:
@@ -147,17 +164,13 @@ def extra_pending(self) -> List[str]:
147164 in self .pending_changelogs
148165 if x != self .project .version .base_version ]
149166
150- @property
151- def pending_not_dev (self ) -> bool :
152- return (
153- not self .project .is_dev
154- and self .project .changelogs .is_pending )
167+ @cached_property
168+ def invalid_reflink_re (self ) -> Pattern [str ]:
169+ return re .compile (INVALID_REFLINK )
155170
156- @property
157- def dev_not_pending (self ) -> bool :
158- return (
159- self .project .is_dev
160- and not self .project .changelogs .is_pending )
171+ @cached_property
172+ def link_ticks_re (self ) -> Pattern [str ]:
173+ return re .compile (LINK_TICKS_REGEX )
161174
162175 @cached_property
163176 def pending_changelogs (self ) -> List [str ]:
@@ -166,13 +179,33 @@ def pending_changelogs(self) -> List[str]:
166179 for k , v in self .project .changelogs .items ()
167180 if v .release_date == "Pending" ]
168181
182+ @property
183+ def pending_not_dev (self ) -> bool :
184+ return (
185+ not self .project .is_dev
186+ and self .project .changelogs .is_pending )
187+
188+ @cached_property
189+ def punctuation_re (self ) -> Pattern [str ]:
190+ return re .compile (REF_WITH_PUNCTUATION_REGEX )
191+
192+ @cached_property
193+ def ref_ticks_re (self ) -> Pattern [str ]:
194+ return re .compile (REF_TICKS_REGEX )
195+
196+ @cached_property
197+ def single_tick_re (self ) -> Pattern [str ]:
198+ return re .compile (SINGLE_TICK_REGEX )
199+
169200 def check_changelog (
170201 self ,
171- changelog : base_interface .IChangelog ) -> List [str ]:
172- return self .changelog_file_class (
173- self .project , changelog ).run_checks ()
202+ changelog : base_interface .IChangelog ) -> Tuple [str , ...]:
203+ return self .changelog_file_class (self , changelog ).run_checks ()
174204
175205 def check_changes (
176- self ) -> Iterator [Tuple [base_interface .IChangelog , List ]]:
206+ self ) -> Iterator [
207+ Tuple [
208+ base_interface .IChangelog ,
209+ Tuple [str , ...]]]:
177210 for changelog in self .project .changelogs .values ():
178211 yield changelog , self .check_changelog (changelog )
0 commit comments