Update regexes for gradle and python files
This commit is contained in:
parent
36df9f486b
commit
6399a1dfeb
1 changed files with 12 additions and 23 deletions
|
@ -48,11 +48,11 @@ class BuildFile(Validateable):
|
||||||
def __get_file_type_regex_str(self, file_type: BuildFileType):
|
def __get_file_type_regex_str(self, file_type: BuildFileType):
|
||||||
match file_type:
|
match file_type:
|
||||||
case BuildFileType.JAVA_GRADLE:
|
case BuildFileType.JAVA_GRADLE:
|
||||||
return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?"
|
return r'(?P<pre_version>version\s?=\s?)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||||
case BuildFileType.PYTHON:
|
case BuildFileType.PYTHON:
|
||||||
return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?(-dev)?[0-9]*"
|
return r'(?P<pre_version>version\s?=\s?)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT|-dev\d*)?)\"'
|
||||||
case BuildFileType.JAVA_CLOJURE:
|
case BuildFileType.JAVA_CLOJURE:
|
||||||
return r'(?P<project>\(defproject\s(\S)*\s)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
return r'(?P<pre_version>\(defproject\s(\S)*\s)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||||
case _:
|
case _:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@ -63,22 +63,9 @@ class BuildFile(Validateable):
|
||||||
case BuildFileType.JS:
|
case BuildFileType.JS:
|
||||||
version_str = json.loads(self.content)["version"]
|
version_str = json.loads(self.content)["version"]
|
||||||
case BuildFileType.JAVA_GRADLE:
|
case BuildFileType.JAVA_GRADLE:
|
||||||
# TODO: '\nversion = ' will not parse all ?!
|
version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
|
||||||
version_line = re.search("\nversion = .*", self.content)
|
|
||||||
version_line_group = version_line.group()
|
|
||||||
version_string = re.search(
|
|
||||||
self.__get_file_type_regex_str(build_file_type), version_line_group
|
|
||||||
)
|
|
||||||
version_str = version_string.group()
|
|
||||||
case BuildFileType.PYTHON:
|
case BuildFileType.PYTHON:
|
||||||
# TODO: '\nversion = ' will not parse all ?!
|
version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
|
||||||
version_line = re.search("\nversion = .*\n", self.content)
|
|
||||||
version_line_group = version_line.group()
|
|
||||||
version_string = re.search(
|
|
||||||
self.__get_file_type_regex_str(build_file_type),
|
|
||||||
version_line_group,
|
|
||||||
)
|
|
||||||
version_str = version_string.group()
|
|
||||||
case BuildFileType.JAVA_CLOJURE:
|
case BuildFileType.JAVA_CLOJURE:
|
||||||
version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
|
version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
|
||||||
except:
|
except:
|
||||||
|
@ -103,22 +90,24 @@ class BuildFile(Validateable):
|
||||||
self.content = json.dumps(json_data, indent=4)
|
self.content = json.dumps(json_data, indent=4)
|
||||||
case BuildFileType.JAVA_GRADLE:
|
case BuildFileType.JAVA_GRADLE:
|
||||||
substitute = re.sub(
|
substitute = re.sub(
|
||||||
f'\nversion = "{self.__get_file_type_regex_str(build_file_type)}"',
|
self.__get_file_type_regex_str(build_file_type),
|
||||||
f'\nversion = "{new_version.to_string()}"',
|
fr'\g<pre_version>"{new_version.to_string()}"',
|
||||||
self.content,
|
self.content,
|
||||||
|
1,
|
||||||
)
|
)
|
||||||
self.content = substitute
|
self.content = substitute
|
||||||
case BuildFileType.PYTHON:
|
case BuildFileType.PYTHON:
|
||||||
substitute = re.sub(
|
substitute = re.sub(
|
||||||
f'\nversion = "{self.__get_file_type_regex_str(build_file_type)}"',
|
self.__get_file_type_regex_str(build_file_type),
|
||||||
f'\nversion = "{new_version.to_string()}"',
|
fr'\g<pre_version>"{new_version.to_string()}"',
|
||||||
self.content,
|
self.content,
|
||||||
|
1,
|
||||||
)
|
)
|
||||||
self.content = substitute
|
self.content = substitute
|
||||||
case BuildFileType.JAVA_CLOJURE:
|
case BuildFileType.JAVA_CLOJURE:
|
||||||
substitute = re.sub(
|
substitute = re.sub(
|
||||||
self.__get_file_type_regex_str(build_file_type),
|
self.__get_file_type_regex_str(build_file_type),
|
||||||
fr'\g<project>"{new_version.to_string()}"',
|
fr'\g<pre_version>"{new_version.to_string()}"',
|
||||||
self.content,
|
self.content,
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue