Replace clojure version regex

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

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

Loading…
Cancel
Save