Replace clojure version regex

clj-bb-rewrite
bom 8 months ago
parent bcccfd8b9c
commit 617d909438

@ -52,7 +52,7 @@ class BuildFile(Validateable):
case BuildFileType.PYTHON: case BuildFileType.PYTHON:
return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?(-dev)?[0-9]*" return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?(-dev)?[0-9]*"
case BuildFileType.JAVA_CLOJURE: case BuildFileType.JAVA_CLOJURE:
return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?" return r'(?P<project>\(defproject\s(\S)*\s)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
case _: case _:
return "" return ""
@ -80,13 +80,7 @@ class BuildFile(Validateable):
) )
version_str = version_string.group() version_str = version_string.group()
case BuildFileType.JAVA_CLOJURE: case BuildFileType.JAVA_CLOJURE:
# TODO: unsure about the trailing '\n' ! version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
version_line = re.search("\\(defproject .*\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()
except: except:
raise RuntimeError(f"Version not found in file {self.file_path}") raise RuntimeError(f"Version not found in file {self.file_path}")
@ -96,7 +90,6 @@ class BuildFile(Validateable):
return result return result
def set_version(self, new_version: Version): def set_version(self, new_version: Version):
# TODO: How can we create regex-pattern constants to use them at both places?
if new_version.is_snapshot(): if new_version.is_snapshot():
new_version.snapshot_suffix = self.get_default_suffix() new_version.snapshot_suffix = self.get_default_suffix()
@ -125,8 +118,8 @@ class BuildFile(Validateable):
case BuildFileType.JAVA_CLOJURE: case BuildFileType.JAVA_CLOJURE:
# TODO: we should stick here on defproject instead of first line! # TODO: we should stick here on defproject instead of first line!
substitute = re.sub( substitute = re.sub(
f'"{self.__get_file_type_regex_str(build_file_type)}"', self.__get_file_type_regex_str(build_file_type),
f'"{new_version.to_string()}"', fr'\g<project>"{new_version.to_string()}"',
self.content, self.content,
1, 1,
) )

Loading…
Cancel
Save