Skip to content

Commit 1bbaf85

Browse files
add type hinting
1 parent 9d4aad8 commit 1bbaf85

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

github_extraction/get_git_sources.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@
99

1010
import re
1111
import subprocess
12+
from typing import Optional
13+
from pathlib import Path
1214

1315

14-
def run_command(command, shell=False, rval=False):
16+
def run_command(
17+
command: str, rval: bool = False
18+
) -> Optional[subprocess.CompletedProcess]:
1519
"""
1620
Run a subprocess command and return the result object
1721
Inputs:
1822
- command, str with command to run
1923
Outputs:
2024
- result object from subprocess.run
2125
"""
22-
if not shell:
23-
command = command.split()
26+
command = command.split()
2427
result = subprocess.run(
2528
command,
2629
capture_output=True,
2730
text=True,
2831
timeout=300,
29-
shell=shell,
32+
shell=True,
3033
check=False,
3134
)
3235
if result.returncode:
@@ -38,7 +41,9 @@ def run_command(command, shell=False, rval=False):
3841
return result
3942

4043

41-
def clone_repo_mirror(source, repo_ref, parent, mirror_loc, loc):
44+
def clone_repo_mirror(
45+
source: str, repo_ref: str, parent: str, mirror_loc: Path, loc: Path
46+
) -> None:
4247
"""
4348
Clone a repo source using a local git mirror.
4449
Assume the mirror is set up as per the Met Office
@@ -71,7 +76,7 @@ def clone_repo_mirror(source, repo_ref, parent, mirror_loc, loc):
7176
run_command(command)
7277

7378

74-
def clone_repo(repo_source, repo_ref, loc):
79+
def clone_repo(repo_source: str, repo_ref: str, loc: Path) -> None:
7580
"""
7681
Clone the repo and checkout the provided ref
7782
Only if a remote source
@@ -84,7 +89,7 @@ def clone_repo(repo_source, repo_ref, loc):
8489
run_command(command)
8590

8691

87-
def sync_repo(repo_source, repo_ref, loc):
92+
def sync_repo(repo_source: str, repo_ref: str, loc: Path) -> None:
8893
"""
8994
Rsync a local git clone and checkout the provided ref
9095
"""

github_extraction/rose_stem_extract_source.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
# *****************************COPYRIGHT*******************************
77
"""
88
Clone sources for a rose-stem run for use with git bdiff module in scripts
9+
Only intended for use with rose-stem suites that have provided appropriate environment
10+
variables
911
"""
1012

1113
import os
1214
from datetime import datetime
1315
from pathlib import Path
1416
from ast import literal_eval
15-
from get_git_sources import clone_repo, clone_repo_mirror, sync_repo, run_command
17+
from get_git_sources import clone_repo, clone_repo_mirror, sync_repo
18+
from typing import Dict
1619

1720

18-
def main():
21+
def main() -> None:
1922

2023
clone_loc = Path(os.environ["SOURCE_DIRECTORY"])
24+
clone_loc.mkdir(parents=True)
2125

22-
run_command(f"mkdir -p {clone_loc}")
23-
24-
dependencies = literal_eval(os.environ["DEPENDENCIES"])
26+
dependencies: Dict = literal_eval(os.environ["DEPENDENCIES"])
2527

2628
for dependency, values in dependencies.items():
2729

0 commit comments

Comments
 (0)