@@ -27,19 +27,16 @@ def get_package_type_from_setup():
2727 ".ansible-lint" : "ansible" ,
2828 ".luacheckrc" : "openwrt-agents" ,
2929 }
30-
3130 for filename , package_type in package_type_files .items ():
3231 if os .path .exists (filename ):
3332 return package_type
34-
3533 return None
3634
3735
3836def detect_changelog_style (changelog_path ):
3937 # Detects if the changelog uses the 'Version ' prefix for its entries
4038 if not os .path .exists (changelog_path ):
4139 return True
42-
4340 with open (changelog_path , "r" , encoding = "utf-8" ) as f :
4441 content = f .read ()
4542 # Look for a line that starts with 'Version X.Y.Z'
@@ -57,12 +54,10 @@ def _handle_python_version(config):
5754 project_name = get_package_name_from_setup ()
5855 if not project_name :
5956 return
60-
6157 package_directory = project_name .replace ("-" , "_" )
6258 init_py_path = os .path .join (package_directory , "__init__.py" )
6359 if not os .path .exists (init_py_path ):
6460 return
65-
6661 with open (init_py_path , "r" ) as f :
6762 content = f .read ()
6863 version_match = re .search (r"^VERSION\s*=\s*\((.*)\)" , content , re .M )
@@ -79,13 +74,11 @@ def _handle_npm_version(config):
7974 """Handles version detection for NPM packages."""
8075 if not os .path .exists ("package.json" ):
8176 return
82-
8377 with open ("package.json" , "r" ) as f :
8478 content = json .load (f )
8579 version_str = content .get ("version" )
8680 if not version_str :
8781 return
88-
8982 config ["version_path" ] = "package.json"
9083 try :
9184 if "-" in version_str :
@@ -94,13 +87,11 @@ def _handle_npm_version(config):
9487 version_tuple , version_type = version_str .split ("_" , 1 )
9588 else :
9689 version_tuple , version_type = version_str , "final"
97-
9890 parts = version_tuple .split ("." )
9991 if len (parts ) < 3 :
10092 raise ValueError (
10193 f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)"
10294 )
103-
10495 config ["CURRENT_VERSION" ] = [
10596 int (parts [0 ]),
10697 int (parts [1 ]),
@@ -115,23 +106,20 @@ def _handle_docker_version(config):
115106 """Handles version detection for Docker packages."""
116107 if not os .path .exists ("Makefile" ):
117108 return
118-
119109 with open ("Makefile" , "r" ) as f :
120110 content = f .read ()
121111 version_match = re .search (
122112 r"^OPENWISP_VERSION\s*=\s*([^\s]+)" , content , re .MULTILINE
123113 )
124114 if not version_match :
125115 return
126-
127116 config ["version_path" ] = "Makefile"
128117 version_str = version_match .group (1 )
129118 parts = version_str .split ("." )
130119 if len (parts ) < 3 :
131120 raise ValueError (
132121 f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)"
133122 )
134-
135123 config ["CURRENT_VERSION" ] = [
136124 int (parts [0 ]),
137125 int (parts [1 ]),
@@ -145,7 +133,6 @@ def _handle_ansible_version(config):
145133 version_py_path = os .path .join ("templates" , "openwisp2" , "version.py" )
146134 if not os .path .exists (version_py_path ):
147135 return
148-
149136 with open (version_py_path , "r" ) as f :
150137 content = f .read ()
151138 version_match = re .search (
@@ -155,7 +142,6 @@ def _handle_ansible_version(config):
155142 )
156143 if not version_match :
157144 return
158-
159145 config ["version_path" ] = version_py_path
160146 try :
161147 version_str = version_match .group (1 )
@@ -164,7 +150,6 @@ def _handle_ansible_version(config):
164150 raise ValueError (
165151 f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)"
166152 )
167-
168153 config ["CURRENT_VERSION" ] = [
169154 int (parts [0 ]),
170155 int (parts [1 ]),
@@ -179,19 +164,16 @@ def _handle_openwrt_agents_version(config):
179164 """Handles version detection for OpenWRT agents packages."""
180165 if not os .path .exists ("VERSION" ):
181166 return
182-
183167 with open ("VERSION" , "r" ) as f :
184168 version_str = f .read ().strip ()
185169 if not version_str :
186170 return
187-
188171 config ["version_path" ] = "VERSION"
189172 parts = version_str .split ("." )
190173 if len (parts ) < 3 :
191174 raise ValueError (
192175 f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)"
193176 )
194-
195177 config ["CURRENT_VERSION" ] = [
196178 int (parts [0 ]),
197179 int (parts [1 ]),
@@ -229,11 +211,9 @@ def load_config():
229211 config ["repo" ] = "/" .join (repo_path .split ("/" )[- 2 :])
230212 except (subprocess .CalledProcessError , FileNotFoundError ):
231213 config ["repo" ] = None
232-
233214 config ["version_path" ] = None
234215 config ["CURRENT_VERSION" ] = None
235216 config ["package_type" ] = get_package_type_from_setup ()
236-
237217 # Use handler function if available for the detected package type
238218 handler = PACKAGE_VERSION_HANDLERS .get (config ["package_type" ])
239219 if handler :
0 commit comments