Skip to content

Commit d0d99ff

Browse files
committed
[tooling] Add centralized exercise_utils
1 parent f9d416a commit d0d99ff

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

exercise_utils/__init__.py

Whitespace-only changes.

exercise_utils/cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import subprocess
2+
from sys import exit
3+
from typing import List, Optional
4+
5+
6+
def run_command(command: List[str], verbose: bool) -> Optional[str]:
7+
try:
8+
result = subprocess.run(
9+
command,
10+
capture_output=True,
11+
text=True,
12+
check=True,
13+
)
14+
if verbose:
15+
print(result.stdout)
16+
return result.stdout
17+
except subprocess.CalledProcessError as e:
18+
if verbose:
19+
print(e.stderr)
20+
exit(1)

hands_on/add_files.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
import os
2-
import subprocess
3-
from sys import exit
4-
from typing import List, Optional
2+
from exercise_utils import cli
53

64
__requires_git__ = True
75
__requires_github__ = False
86

97

10-
def run_command(command: List[str], verbose: bool) -> Optional[str]:
11-
try:
12-
result = subprocess.run(
13-
command,
14-
capture_output=True,
15-
text=True,
16-
check=True,
17-
)
18-
if verbose:
19-
print(result.stdout)
20-
return result.stdout
21-
except subprocess.CalledProcessError as e:
22-
if verbose:
23-
print(e.stderr)
24-
exit(1)
25-
26-
278
def download(verbose: bool):
289
os.makedirs("things")
2910
os.chdir("things")
30-
run_command(["git", "init", "--initial-branch=main"], verbose)
11+
cli.run_command(["git", "init", "--initial-branch=main"], verbose)

0 commit comments

Comments
 (0)