Resolve pylint errors in infrastructure_api.py

This commit is contained in:
bom 2023-04-28 15:01:03 +02:00 committed by Michael Jerger
parent e0b30adf9f
commit 70b5607d8e

View file

@ -46,7 +46,7 @@ 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:
with open(self.config_file_path, 'r', encoding='utf-8') as json_file:
json_version = json.load(json_file)['version']
is_snapshot = False
if '-SNAPSHOT' in json_version:
@ -56,7 +56,7 @@ class JsonFileHandler(FileHandler):
return version, is_snapshot
def write(self, version_string):
with open(self.config_file_path, 'r+') as json_file:
with open(self.config_file_path, 'r+', encoding='utf-8') as json_file:
json_data = json.load(json_file)
json_data['version'] = version_string
json_file.seek(0)
@ -69,7 +69,7 @@ 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:
with open(self.config_file_path, 'r', encoding='utf-8') as gradle_file:
contents = gradle_file.read()
version_line = re.search("\nversion = .*", contents)
exception = Exception("Version not found in gradle file")
@ -93,7 +93,7 @@ class GradleFileHandler(FileHandler):
return version, is_snapshot
def write(self, version_string):
with open(self.config_file_path, 'r+') as gradle_file:
with open(self.config_file_path, 'r+', encoding='utf-8') as gradle_file:
contents = gradle_file.read()
version_substitute = re.sub(
'\nversion = "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?"', f'\nversion = "{version_string}"', contents)
@ -107,7 +107,7 @@ 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:
with open(self.config_file_path, 'r', encoding='utf-8') as python_file:
contents = python_file.read()
version_line = re.search("\nversion = .*\n", contents)
exception = Exception("Version not found in gradle file")
@ -131,7 +131,7 @@ class PythonFileHandler(FileHandler):
return version, is_snapshot
def write(self, version_string):
with open(self.config_file_path, 'r+') as python_file:
with open(self.config_file_path, 'r+', encoding='utf-8') as python_file:
contents = python_file.read()
version_substitute = re.sub(
'\nversion = "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?"', f'\nversion = "{version_string}"', contents)
@ -145,7 +145,7 @@ 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:
with open(self.config_file_path, 'r', encoding='utf-8') as clj_file:
contents = clj_file.read()
version_line = re.search("^\\(defproject .*\n", contents)
exception = Exception("Version not found in clj file")
@ -169,7 +169,7 @@ class ClojureFileHandler(FileHandler):
return version, is_snapshot
def write(self, version_string):
with open(self.config_file_path, 'r+') as clj_file:
with open(self.config_file_path, 'r+', encoding='utf-8') as clj_file:
clj_first = clj_file.readline()
clj_rest = clj_file.read()
version_substitute = re.sub(
@ -185,6 +185,7 @@ class GitApi():
def __init__(self):
self.execution_api = ExecutionApi()
# pylint: disable=invalid-name
def get_latest_n_commits(self, n: int):
return self.execution_api.execute(
f'git log --oneline --format="%s %b" -n {n}')
@ -203,11 +204,10 @@ class GitApi():
return self.execution_api.execute('git describe --tags --abbrev=0')
def get_current_branch(self):
self.execution_api.execute('git branch --show-current')
return ''.join(self.execution_api.stdout).rstrip()
return ''.join(self.execution_api.execute('git branch --show-current')).rstrip()
def init(self, default_branch: str = "main"):
self.execution_api.execute(f'git init')
self.execution_api.execute('git init')
self.execution_api.execute(f'git checkout -b {default_branch}')
def set_user_config(self, email: str, name: str):