Fix CI: Update type declaration and value assignments
This commit is contained in:
parent
10e7deb74b
commit
420030fa0a
1 changed files with 38 additions and 20 deletions
|
@ -2,11 +2,15 @@ import json
|
|||
import re
|
||||
import subprocess as sub
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional, Union
|
||||
from pathlib import Path
|
||||
from os import environ
|
||||
|
||||
# TODO: jem, zam - 2023_04_18: Discuss if we can move more functionality to domain?
|
||||
class FileHandler(ABC):
|
||||
def __init__(self) -> None:
|
||||
self.config_file_path: Optional[Path | None] = None
|
||||
self.config_file_type: Optional[Path | None] = None
|
||||
|
||||
@classmethod
|
||||
def from_file_path(cls, file_path):
|
||||
|
@ -40,6 +44,8 @@ class FileHandler(ABC):
|
|||
class JsonFileHandler(FileHandler):
|
||||
|
||||
def parse(self) -> tuple[list[int], bool]:
|
||||
if self.config_file_path is None:
|
||||
raise ValueError("No file name given.")
|
||||
with open(self.config_file_path, 'r') as json_file:
|
||||
json_version = json.load(json_file)['version']
|
||||
is_snapshot = False
|
||||
|
@ -61,6 +67,8 @@ class JsonFileHandler(FileHandler):
|
|||
class GradleFileHandler(FileHandler):
|
||||
|
||||
def parse(self) -> tuple[list[int], bool]:
|
||||
if self.config_file_path is None:
|
||||
raise ValueError("No file name given.")
|
||||
with open(self.config_file_path, 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
version_line = re.search("\nversion = .*", contents)
|
||||
|
@ -68,19 +76,19 @@ class GradleFileHandler(FileHandler):
|
|||
if version_line is None:
|
||||
raise exception
|
||||
|
||||
version_line = version_line.group()
|
||||
version_line_group = version_line.group()
|
||||
version_string = re.search(
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line)
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line_group)
|
||||
if version_string is None:
|
||||
raise exception
|
||||
|
||||
version_string = version_string.group()
|
||||
version_string_group = version_string.group()
|
||||
is_snapshot = False
|
||||
if '-SNAPSHOT' in version_string:
|
||||
if '-SNAPSHOT' in version_string_group:
|
||||
is_snapshot = True
|
||||
version_string = version_string.replace('-SNAPSHOT', '')
|
||||
version_string_group = version_string_group.replace('-SNAPSHOT', '')
|
||||
|
||||
version = [int(x) for x in version_string.split('.')]
|
||||
version = [int(x) for x in version_string_group.split('.')]
|
||||
|
||||
return version, is_snapshot
|
||||
|
||||
|
@ -97,6 +105,8 @@ class GradleFileHandler(FileHandler):
|
|||
class PythonFileHandler(FileHandler):
|
||||
|
||||
def parse(self) -> tuple[list[int], bool]:
|
||||
if self.config_file_path is None:
|
||||
raise ValueError("No file name given.")
|
||||
with open(self.config_file_path, 'r') as python_file:
|
||||
contents = python_file.read()
|
||||
version_line = re.search("\nversion = .*\n", contents)
|
||||
|
@ -104,19 +114,19 @@ class PythonFileHandler(FileHandler):
|
|||
if version_line is None:
|
||||
raise exception
|
||||
|
||||
version_line = version_line.group()
|
||||
version_line_group = version_line.group()
|
||||
version_string = re.search(
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line)
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line_group)
|
||||
if version_string is None:
|
||||
raise exception
|
||||
|
||||
version_string = version_string.group()
|
||||
version_string_group = version_string.group()
|
||||
is_snapshot = False
|
||||
if '-SNAPSHOT' in version_string:
|
||||
if '-SNAPSHOT' in version_string_group:
|
||||
is_snapshot = True
|
||||
version_string = version_string.replace('-SNAPSHOT', '')
|
||||
version_string_group = version_string_group.replace('-SNAPSHOT', '')
|
||||
|
||||
version = [int(x) for x in version_string.split('.')]
|
||||
version = [int(x) for x in version_string_group.split('.')]
|
||||
|
||||
return version, is_snapshot
|
||||
|
||||
|
@ -133,6 +143,8 @@ class PythonFileHandler(FileHandler):
|
|||
class ClojureFileHandler(FileHandler):
|
||||
|
||||
def parse(self) -> tuple[list[int], bool]:
|
||||
if self.config_file_path is None:
|
||||
raise ValueError("No file name given.")
|
||||
with open(self.config_file_path, 'r') as clj_file:
|
||||
contents = clj_file.read()
|
||||
version_line = re.search("^\\(defproject .*\n", contents)
|
||||
|
@ -140,19 +152,19 @@ class ClojureFileHandler(FileHandler):
|
|||
if version_line is None:
|
||||
raise exception
|
||||
|
||||
version_line = version_line.group()
|
||||
version_line_group = version_line.group()
|
||||
version_string = re.search(
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line)
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line_group)
|
||||
if version_string is None:
|
||||
raise exception
|
||||
|
||||
version_string = version_string.group()
|
||||
version_string_group = version_string.group()
|
||||
is_snapshot = False
|
||||
if '-SNAPSHOT' in version_string:
|
||||
if '-SNAPSHOT' in version_string_group:
|
||||
is_snapshot = True
|
||||
version_string = version_string.replace('-SNAPSHOT', '')
|
||||
version_string_group = version_string_group.replace('-SNAPSHOT', '')
|
||||
|
||||
version = [int(x) for x in version_string.split('.')]
|
||||
version = [int(x) for x in version_string_group.split('.')]
|
||||
|
||||
return version, is_snapshot
|
||||
|
||||
|
@ -185,8 +197,14 @@ class SystemApi():
|
|||
stderr=sub.PIPE,
|
||||
text=True,
|
||||
encoding="UTF-8")
|
||||
self.stdout = stream.stdout.readlines()
|
||||
self.stderr = stream.stderr.readlines()
|
||||
if stream.stdout is not None:
|
||||
self.stdout = stream.stdout.readlines()
|
||||
else:
|
||||
self.stdout = None
|
||||
if stream.stderr is not None:
|
||||
self.stderr = stream.stderr.readlines()
|
||||
else:
|
||||
self.stderr = None
|
||||
|
||||
def run_checked(self, *args):
|
||||
self.run(args)
|
||||
|
|
Loading…
Reference in a new issue