-
Notifications
You must be signed in to change notification settings - Fork 15
Refactor #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Refactor #200
Changes from all commits
b88c916
2ba52be
5cc918f
87513ad
eac6492
73107e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,20 @@ | ||
| *.sublime-workspace | ||
| *.code-workspace | ||
| .vscode | ||
| __pycache__/ | ||
| *.pyc | ||
| *~ | ||
| *.swp | ||
| .conda | ||
| .DS_Store | ||
| .env.* | ||
| .idea | ||
| .vscode | ||
| *.bak | ||
| *.code-workspace | ||
| *.egg | ||
| *.egg-info | ||
| *.egg-info/ | ||
| *.log | ||
| *.pyc | ||
| *.sublime-workspace | ||
| *.swp | ||
| *.tmp | ||
| *.venv | ||
| *~ | ||
| uv.lock | ||
| venv/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| BSD 3-Clause License | ||
| BSD 3-Clause Licence | ||
|
|
||
| Copyright (c) 2023, Met Office | ||
| All rights reserved. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ | |
| import yaml | ||
| from collections import defaultdict | ||
| from pathlib import Path | ||
| from typing import Dict, List, Optional, Set, Union | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above (although I think Dict and List changes are an earlier python, so maybe they can stay)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| from git_bdiff import GitBDiff, GitInfo | ||
| from get_git_sources import clone_repo, sync_repo | ||
|
|
||
|
|
@@ -43,7 +42,7 @@ def __init__(self) -> None: | |
| self.task_states = {} | ||
| self.temp_directory = None | ||
|
|
||
| def get_um_failed_configs(self) -> Set[str]: | ||
| def get_um_failed_configs(self) -> set[str]: | ||
| """ | ||
| Read through failed UM rose_ana tasks | ||
| """ | ||
|
|
@@ -76,7 +75,7 @@ def read_um_section(self, change: str) -> str: | |
| section = "Unknown" | ||
| return section | ||
|
|
||
| def get_changed_um_section(self) -> Set[str]: | ||
| def get_changed_um_section(self) -> set[str]: | ||
| """ | ||
| Read through bdiff of UM source and find code owner section for each changed | ||
| file | ||
|
|
@@ -113,7 +112,7 @@ def get_changed_um_section(self) -> Set[str]: | |
|
|
||
| return changed_sections | ||
|
|
||
| def get_um_owners(self, filename: str) -> Dict: | ||
| def get_um_owners(self, filename: str) -> dict: | ||
| """ | ||
| Read UM Code Owners file and write to a dictionary | ||
| """ | ||
|
|
@@ -151,7 +150,7 @@ def get_um_owners(self, filename: str) -> Dict: | |
|
|
||
| return owners | ||
|
|
||
| def parse_tasks(self) -> Dict[str, List[str]]: | ||
| def parse_tasks(self) -> dict[str, list[str]]: | ||
| """ | ||
| Read through the tasks run, sorting by state | ||
| """ | ||
|
|
@@ -233,7 +232,7 @@ def determine_primary_source(self) -> str: | |
|
|
||
| return "unknown" | ||
|
|
||
| def read_rose_conf(self) -> Dict[str, str]: | ||
| def read_rose_conf(self) -> dict[str, str]: | ||
| """ | ||
| Read the suite rose-suite.conf file into a dictionary | ||
| """ | ||
|
|
@@ -281,19 +280,19 @@ def find_unknown_dependency(self, dependency: str) -> str: | |
|
|
||
| pattern = re.compile(rf"{dependency.upper()} SOURCE CLONE=(\S+)") | ||
| log_file = self.suite_path / "log" / "scheduler" / "log" | ||
| with open(log_file, "r") as f: | ||
| with open(log_file) as f: | ||
| for line in f: | ||
| if match := pattern.search(line): | ||
| return match.group(1).rstrip("/") | ||
| raise RuntimeError(f"Unable to find source for dependency {dependency}") | ||
|
|
||
| def read_dependencies(self) -> Dict[str, Dict]: | ||
| def read_dependencies(self) -> dict[str, dict]: | ||
| """ | ||
| Read the suite dependencies from the dependencies.yaml file - this is assumed to | ||
| have been copied to the suite_path directory | ||
| """ | ||
|
|
||
| with open(self.suite_path / "dependencies.yaml", "r") as stream: | ||
| with open(self.suite_path / "dependencies.yaml") as stream: | ||
| dependencies = yaml.safe_load(stream) | ||
| for dependency, data in dependencies.items(): | ||
| if data["source"] is None: | ||
|
|
@@ -307,7 +306,7 @@ def get_workflow_id(self) -> str: | |
| Read cylc install log for workflow id | ||
| """ | ||
|
|
||
| with open(self.suite_path / "log" / "scheduler" / "log", "r") as f: | ||
| with open(self.suite_path / "log" / "scheduler" / "log") as f: | ||
| for line in f: | ||
| match = re.search(r"INFO - Workflow: (\S+\/\w+)", line) | ||
| try: | ||
|
|
@@ -344,7 +343,7 @@ def get_suite_starttime(self) -> str: | |
| starttime = row[0] | ||
| return starttime.split("+")[0] | ||
|
|
||
| def read_groups_run(self) -> List[str]: | ||
| def read_groups_run(self) -> list[str]: | ||
| """ | ||
| Read in groups run as part of suite from the cylc database file | ||
| """ | ||
|
|
@@ -360,7 +359,7 @@ def read_groups_run(self) -> List[str]: | |
| groups = ["suite_default"] | ||
| return groups | ||
|
|
||
| def get_task_states(self) -> Dict[str, str]: | ||
| def get_task_states(self) -> dict[str, str]: | ||
| """ | ||
| Query the database and return a dictionary of states. This is assumed to be in | ||
| suite_path/log/db | ||
|
|
@@ -374,8 +373,8 @@ def get_task_states(self) -> Dict[str, str]: | |
| return data | ||
|
|
||
| def query_suite_database( | ||
| self, database: Path, selections: List[str], source: str | ||
| ) -> List[tuple]: | ||
| self, database: Path, selections: list[str], source: str | ||
| ) -> list[tuple]: | ||
| """ | ||
| Create an sql statement and query provided database. Return the result | ||
| """ | ||
|
|
@@ -392,8 +391,8 @@ def query_suite_database( | |
| return data | ||
|
|
||
| def run_command( | ||
| self, command: Union[str, List[str]], shell: bool = False, rval: bool = False | ||
| ) -> Optional[subprocess.CompletedProcess]: | ||
| self, command: str | list[str], shell: bool = False, rval: bool = False | ||
| ) -> subprocess.CompletedProcess | None: | ||
| """ | ||
| Run a subprocess command and return the result object | ||
| Inputs: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave this as using the old Optional and Union statements for the time being. We've already seen python compatibility issues for this in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see that
os46-3stack is still using Python 3.7.To make future tidying easier, would it work if we add the annotation import from future, rather than keeping the legacy imports?
Its probably only useful to fix type annotations, not runtime logic.