11import ast
2+ import json
23import os
34import re
45import subprocess
5- import json
66
77
88def get_package_name_from_setup ():
@@ -22,19 +22,19 @@ def get_package_type_from_setup():
2222 """Detects package type based on config files present in the project."""
2323 if os .path .exists ("setup.py" ):
2424 return "python"
25-
25+
2626 if os .path .exists ("package.json" ):
2727 return "npm"
28-
28+
2929 if os .path .exists ("docker-compose.yml" ):
3030 return "docker"
31-
31+
3232 if os .path .exists (".ansible-lint" ):
3333 return "ansible"
34-
34+
3535 if os .path .exists (".luacheckrc" ):
3636 return "openwrt-agents"
37-
37+
3838 return None
3939
4040
@@ -91,7 +91,9 @@ def load_config():
9191 if version_match :
9292 config ["version_path" ] = init_py_path
9393 try :
94- version_tuple = ast .literal_eval (f"({ version_match .group (1 )} )" )
94+ version_tuple = ast .literal_eval (
95+ f"({ version_match .group (1 )} )"
96+ )
9597 config ["CURRENT_VERSION" ] = list (version_tuple )
9698 except (ValueError , SyntaxError ):
9799 config ["CURRENT_VERSION" ] = None
@@ -109,45 +111,67 @@ def load_config():
109111 version_tuple , version_type = version_str .split ("_" , 1 )
110112 else :
111113 version_tuple , version_type = version_str , "final"
112-
114+
113115 parts = version_tuple .split ("." )
114116 if len (parts ) < 3 :
115- raise ValueError (f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)" )
116-
117+ raise ValueError (
118+ f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)"
119+ )
120+
117121 config ["CURRENT_VERSION" ] = [
118122 int (parts [0 ]),
119123 int (parts [1 ]),
120124 int (parts [2 ]),
121- version_type
125+ version_type ,
122126 ]
123- except (ValueError , SyntaxError ):
127+ except (ValueError , SyntaxError ):
124128 config ["CURRENT_VERSION" ] = None
125129 elif config ["package_type" ] == "docker" :
126130 if os .path .exists ("Makefile" ):
127131 with open ("Makefile" , "r" ) as f :
128132 content = f .read ()
129- version_match = re .search (r"^OPENWISP_VERSION\s*=\s*([^\s]+)" , content , re .MULTILINE )
133+ version_match = re .search (
134+ r"^OPENWISP_VERSION\s*=\s*([^\s]+)" , content , re .MULTILINE
135+ )
130136 if version_match :
131137 config ["version_path" ] = "Makefile"
132138 version_str = version_match .group (1 )
133139 parts = version_str .split ("." )
134140 if len (parts ) < 3 :
135- raise ValueError (f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)" )
136- config ["CURRENT_VERSION" ] = [int (parts [0 ]), int (parts [1 ]), int (parts [2 ]), "final" ]
141+ raise ValueError (
142+ f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)"
143+ )
144+ config ["CURRENT_VERSION" ] = [
145+ int (parts [0 ]),
146+ int (parts [1 ]),
147+ int (parts [2 ]),
148+ "final" ,
149+ ]
137150 elif config ["package_type" ] == "ansible" :
138151 version_py_path = os .path .join ("templates" , "openwisp2" , "version.py" )
139152 if os .path .exists (version_py_path ):
140153 with open (version_py_path , "r" ) as f :
141154 content = f .read ()
142- version_match = re .search (r"^__openwisp_version__\s*=\s*['\"]([^'\"]+)['\"]" , content , re .MULTILINE )
155+ version_match = re .search (
156+ r"^__openwisp_version__\s*=\s*['\"]([^'\"]+)['\"]" ,
157+ content ,
158+ re .MULTILINE ,
159+ )
143160 if version_match :
144161 config ["version_path" ] = version_py_path
145162 try :
146163 version_str = version_match .group (1 )
147164 parts = version_str .split ("." )
148165 if len (parts ) < 3 :
149- raise ValueError (f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)" )
150- config ["CURRENT_VERSION" ] = [int (parts [0 ]), int (parts [1 ]), int (parts [2 ]), "final" ]
166+ raise ValueError (
167+ f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)"
168+ )
169+ config ["CURRENT_VERSION" ] = [
170+ int (parts [0 ]),
171+ int (parts [1 ]),
172+ int (parts [2 ]),
173+ "final" ,
174+ ]
151175 except (ValueError , SyntaxError ):
152176 config ["CURRENT_VERSION" ] = None
153177 elif config ["package_type" ] == "openwrt-agents" :
@@ -158,8 +182,15 @@ def load_config():
158182 config ["version_path" ] = "VERSION"
159183 parts = version_str .split ("." )
160184 if len (parts ) < 3 :
161- raise ValueError (f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)" )
162- config ["CURRENT_VERSION" ] = [int (parts [0 ]), int (parts [1 ]), int (parts [2 ]), "final" ]
185+ raise ValueError (
186+ f"Version '{ version_str } ' does not have expected 3 parts (X.Y.Z)"
187+ )
188+ config ["CURRENT_VERSION" ] = [
189+ int (parts [0 ]),
190+ int (parts [1 ]),
191+ int (parts [2 ]),
192+ "final" ,
193+ ]
163194
164195 possible_changelog_names = [
165196 "CHANGES.rst" ,
0 commit comments