Skip to content

Commit a1c8871

Browse files
ruff
1 parent bba76d9 commit a1c8871

File tree

1 file changed

+33
-29
lines changed
  • installation_and_upgrade/ibex_install_utils/tasks

1 file changed

+33
-29
lines changed

installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import os
12
import re
23
import subprocess
34

5+
import git
6+
7+
from ibex_install_utils.exceptions import ErrorInTask
48
from ibex_install_utils.task import task
59
from ibex_install_utils.tasks import BaseTasks
610
from ibex_install_utils.tasks.common_paths import EPICS_PATH, SETTINGS_CONFIG_PATH
7-
from ibex_install_utils.exceptions import ErrorInRun, ErrorInTask
811
from ibex_install_utils.user_prompt import UserPrompt
9-
from genie_python import genie as g
10-
import re
11-
import git
12-
import os
12+
1313

1414
class GitTasks(BaseTasks):
1515
@task(f"Show Git status in {EPICS_PATH}")
@@ -92,28 +92,32 @@ def checkout_to_release_branch(self) -> None:
9292
print(f"Error checking out to new release branch and push: {e}")
9393
print("Branch may previously exist either locally or remotely - intervention required")
9494

95-
# something for the future in case creting new beranch fails - maybe one exists we want to use?
96-
# try:
97-
# subprocess.check_call(f"cd {EPICS_PATH} && git checkout %COMPUTERNAME%", shell=True)
98-
# print("Switched to existing release branch")
99-
# except subprocess.CalledProcessError as e:
100-
# print(f"Error switching to existing release branch and push: {e}")
101-
102-
#Method to check that the machine name matches a git branch
103-
def inst_name_matches_branch():
104-
repo = git.Repo(
105-
os.path.join(SETTINGS_CONFIG_PATH, BaseTasks._get_machine_name())
106-
)
95+
# something for the future in case creating new branch fails
96+
# maybe one exists we want to use?
97+
# try:
98+
# subprocess.check_call(f"cd {EPICS_PATH} && git checkout %COMPUTERNAME%",
99+
# shell=True)
100+
# print("Switched to existing release branch")
101+
# except subprocess.CalledProcessError as e:
102+
# print(f"Error switching to existing release branch and push: {e}")
103+
104+
# Method to check that the machine name matches a git branch
105+
def inst_name_matches_branch(self) -> None:
106+
repo = git.Repo(os.path.join(SETTINGS_CONFIG_PATH, BaseTasks._get_machine_name()))
107107
if repo.active_branch.name != BaseTasks._get_machine_name():
108108
print(
109-
f"Git branch, '{repo.active_branch}', is not the same as machine name ,'{BaseTasks._get_machine_name()}' "
109+
f"Git branch, '{repo.active_branch}', is not the same as machine name ,"
110+
f"'{BaseTasks._get_machine_name()}' "
110111
)
111112
raise ErrorInTask("Git branch is not the same as machine name")
112113

113-
@task(f"Attempt automatic merge of one branch into another")
114-
def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to, dir):
114+
@task("Attempt automatic merge of one branch into another")
115+
def automatic_merge_of_git_remote(
116+
self, branch_to_merge_from: str, branch_to_merge_to: str, dir: str
117+
) -> None:
115118
f"""
116-
Attempt an automatic merge of one branch {branch_to_merge_from} to another, {branch_to_merge_to} in {dir}
119+
Attempt an automatic merge of one branch
120+
{branch_to_merge_from} to another, {branch_to_merge_to} in {dir}
117121
"""
118122
manual_prompt = (
119123
f"Merge the {branch_to_merge_from} branch into the {branch_to_merge_to} branch. "
@@ -126,10 +130,10 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to
126130
" 5. Resolve any merge conflicts\n"
127131
" 6. git push\n"
128132
)
129-
133+
130134
automatic_prompt = "Attempt automatic merge?"
131135
repo = git.Repo(dir)
132-
if self.prompt.confirm_step(automatic_prompt):
136+
if self.prompt.confirm_step(automatic_prompt):
133137
try:
134138
try:
135139
subprocess.check_call(f"cd /d {dir}", shell=True)
@@ -147,25 +151,25 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to
147151
print(f" merge: {repo.git.merge(f'{branch_to_merge_from}')}")
148152
# no longer push let the instrument do that on start up if needed
149153
except git.GitCommandError as e:
150-
print(
151-
f"Error doing automatic merge, please perform the merge manually: {e}"
152-
)
154+
print(f"Error doing automatic merge, please perform the merge manually: {e}")
153155
self.prompt.prompt_and_raise_if_not_yes(manual_prompt)
154156
else:
155157
self.prompt.prompt_and_raise_if_not_yes(manual_prompt)
156158

159+
157160
if __name__ == "__main__":
158161
"""For running task standalone
159162
Must be called with pythonpath set to `<exact path on your pc>/installation_and_upgrade`
160163
as that is the root of this module and all our imports work that way.
161164
162-
This effectively means to call `set PYTHONPATH=. && python ibex_install_utils/tasks/backup_tasks.py`
165+
This effectively means to call
166+
`set PYTHONPATH=. && python ibex_install_utils/tasks/backup_tasks.py`
163167
from the installation_and_upgrade directory in terminal.
164168
"""
165169
print("")
166170

167171
#! Copying older backups to share will likely fail on developer machines
168172
prompt = UserPrompt(False, True)
169-
170-
git_instance = GitTasks(prompt,'','','','')
173+
174+
git_instance = GitTasks(prompt, "", "", "", "")
171175
git_instance.automatic_merge_of_git_remote("branch1", "branch2", "C:/test")

0 commit comments

Comments
 (0)