Skip to content

Commit 70d6198

Browse files
yaswantjames-bruten-moPierre-siddallt00sa
authored
Linter CI part 1 (#52)
* Linter CI part 1 * fix codeowners * fix indent * fix indent again * block some unwanted checks * falsify fail-fast strategy * fix Perl lexical warnings * fix Perl warning * update README * add percriticrc * add codeql badge * add codeql badge * cancel in progress runs with PR updates * Update .github/linters/.ruff.toml * Update .github/linters/.ruff.toml * Update .github/linters/.ruff.toml * Update .github/linters/.ruff.toml * turn off python ruff * apply black/isort, populate black/isort conf files * run isort * missed file * update black config * partial fix shellcheck issues * tidy * black check config try * opaque black * black default * refactor run kgo script with POSIX compliance * response to @james-bruten-mo comments * revert changes to meto_run_kgi_script * revert printf changes and add shellcheck ignore * lint checker fixes * error in bash * black and isort with black profile * another isort attempt * remove isort linting * remove isort * Update suite_report.py Co-authored-by: Pierre Siddall <[email protected]> * Update suite_report.py Co-authored-by: Pierre Siddall <[email protected]> * run black * forgot to run black... * remove .github dir to split up ticket * Update lfric_macros/apply_macros.py Co-authored-by: Sam Clarke-Green <[email protected]> * Update lfric_macros/release_lfric.py Co-authored-by: Sam Clarke-Green <[email protected]> --------- Co-authored-by: James Bruten <[email protected]> Co-authored-by: James Bruten <[email protected]> Co-authored-by: Pierre Siddall <[email protected]> Co-authored-by: Sam Clarke-Green <[email protected]>
1 parent 3ac0433 commit 70d6198

21 files changed

+2131
-993
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
*.sublime-workspace
12
*.code-workspace
3+
.vscode
4+
__pycache__/
25
*.pyc
3-
*.sublime-workspace
6+
*~
47
*.swp
58
.conda
69
.idea
7-
.vscode
8-
__pycache__

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# SimSys Scripts
1+
# Simulation Systems Scripts
22

3-
This repository contains support scripts that are common across the many simulation and modelling codes owned by the Met Office.
4-
Particularily those owned and maintained by the SSD team.
3+
[![Checks](https://github.com/MetOffice/SimSys_Scripts/actions/workflows/lint.yml/badge.svg)](https://github.com/MetOffice/SimSys_Scripts/actions/workflows/lint.yml)
4+
[![CodeQL](https://github.com/MetOffice/SimSys_Scripts/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/MetOffice/SimSys_Scripts/actions/workflows/github-code-scanning/codeql)
55

6-
Also contains a copy of script_updater.sh which is intended to live in the fcm repositories to pull from
7-
this repo.
6+
This repository contains support scripts that are common across the many
7+
simulation and modelling codes owned by the Met Office. Particularly those
8+
owned and maintained by the Simulation Systems and Deployment (SSD) team.
9+
10+
Also contains a copy of `script_updater.sh` which is intended to live in the
11+
fcm repositories to pull from this repository.

fcm_bdiff.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
run tests on based on the branch-difference (to allow checking of only files
1010
which a developer has actually modified on their branch)
1111
"""
12-
import re
12+
1313
import os
14+
import re
1415
import subprocess
1516
import time
1617

@@ -20,10 +21,11 @@ class FCMError(Exception):
2021
"""
2122
Exception class for FCM commands
2223
"""
24+
2325
def __str__(self):
24-
return ("\nFCM command: \"{0:s}\""
25-
"\nFailed with error: \"{1:s}\""
26-
.format(" ".join(self.args[0]), self.args[1].strip()))
26+
return '\nFCM command: "{0:s}"\nFailed with error: "{1:s}"'.format(
27+
" ".join(self.args[0]), self.args[1].strip()
28+
)
2729

2830

2931
# ------------------------------------------------------------------------------
@@ -32,16 +34,20 @@ def is_trunk(url):
3234
Given an FCM url, returns True if it appears to be pointing to the
3335
UM main trunk
3436
"""
35-
search = re.search(r"""
37+
search = re.search(
38+
r"""
3639
(svn://fcm\d+/\w+_svn/\w+/trunk|
3740
.*/svn/[\w\.]+/\w+/trunk|
3841
..*_svn/\w+/trunk)
39-
""", url, flags=re.VERBOSE)
42+
""",
43+
url,
44+
flags=re.VERBOSE,
45+
)
4046
return search is not None
4147

4248

4349
# ------------------------------------------------------------------------------
44-
def text_decoder(bytes_type_string, codecs=['utf8', 'cp1252']):
50+
def text_decoder(bytes_type_string, codecs=["utf8", "cp1252"]):
4551
"""
4652
Given a bytes type string variable, attempt to decode it using the codecs
4753
listed.
@@ -127,18 +133,20 @@ def get_branch_diff_filenames(branch=".", path_override=None):
127133
# Strip whitespace, and remove blank lines while turning the output into
128134
# a list of strings.
129135
bdiff_files = [x.strip() for x in bdiff.split("\n") if x.strip()]
130-
bdiff_files = [bfile.split()[1] for bfile in bdiff_files
131-
if bfile.split()[0].strip() == "M" or
132-
bfile.split()[0].strip() == "A"]
136+
bdiff_files = [
137+
bfile.split()[1]
138+
for bfile in bdiff_files
139+
if bfile.split()[0].strip() == "M" or bfile.split()[0].strip() == "A"
140+
]
133141

134142
# Convert the file paths to be relative to the current URL; to do this
135143
# construct the base path of the trunk URL and compare it to the results
136144
# of the bdiff command above
137145
repos_root = get_repository_root(info)
138-
relative_paths = [os.path.relpath(bfile,
139-
os.path.join(repos_root,
140-
"main", "trunk"))
141-
for bfile in bdiff_files]
146+
relative_paths = [
147+
os.path.relpath(bfile, os.path.join(repos_root, "main", "trunk"))
148+
for bfile in bdiff_files
149+
]
142150

143151
# These relative paths can be joined to an appropriate base to complete
144152
# the filenames to return
@@ -169,9 +177,9 @@ def run_fcm_command(command, max_retries, snooze):
169177
"""
170178
retries = 0
171179
while True:
172-
output = subprocess.Popen(command,
173-
stdout=subprocess.PIPE,
174-
stderr=subprocess.PIPE)
180+
output = subprocess.Popen(
181+
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE
182+
)
175183
_ = output.wait()
176184
if output.returncode == 0:
177185
return text_decoder(output.stdout.read())
@@ -198,8 +206,7 @@ def use_mirror(branch):
198206
if mirror_key in os.environ:
199207
branch = os.environ[mirror_key]
200208
retries = 2
201-
print("[INFO] Switching branch used for fcm command to : {0:}".format(
202-
branch))
209+
print(f"[INFO] Switching branch used for fcm command to: {branch}")
203210
else:
204211
retries = 0
205212
return branch, retries
@@ -211,8 +218,9 @@ def get_repository_root(branch_info):
211218
Given the raw output from an fcm binfo command - which can be retrieved by
212219
calling get_branch_info() - returns the Repository Root field
213220
"""
214-
repos_root = re.search(r"^Repository Root:\s*(?P<url>.*)\s*$",
215-
branch_info, flags=re.MULTILINE)
221+
repos_root = re.search(
222+
r"^Repository Root:\s*(?P<url>.*)\s*$", branch_info, flags=re.MULTILINE
223+
)
216224
if repos_root:
217225
repos_root = repos_root.group("url")
218226
else:
@@ -226,8 +234,9 @@ def get_branch_parent(branch_info):
226234
Given the raw output from an fcm binfo command - which can be retrieved by
227235
calling get_branch_info() - returns the Branch Parent Field
228236
"""
229-
parent = re.search(r"^Branch Parent:\s*(?P<parent>.*)$", branch_info,
230-
flags=re.MULTILINE)
237+
parent = re.search(
238+
r"^Branch Parent:\s*(?P<parent>.*)$", branch_info, flags=re.MULTILINE
239+
)
231240
if parent:
232241
parent = parent.group("parent")
233242
else:

0 commit comments

Comments
 (0)