forked from mdekauwe/CABLE_benchmarking
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add requested changes from code review
Split up the default build function into smaller `pre_build`, `run_build` and `post_build` functions to improve code readability. Simplify unit tests for `*_build` functions. Add `benchcab/utils/fs.py` for defining utility functions for interacting with the file system.
- Loading branch information
1 parent
5cf2f4a
commit ef75799
Showing
8 changed files
with
270 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Contains utility functions for interacting with the file system.""" | ||
|
||
import os | ||
import shutil | ||
import contextlib | ||
from pathlib import Path | ||
|
||
|
||
@contextlib.contextmanager | ||
def chdir(newdir: Path): | ||
"""Context manager `cd`.""" | ||
prevdir = Path.cwd() | ||
os.chdir(newdir.expanduser()) | ||
try: | ||
yield | ||
finally: | ||
os.chdir(prevdir) | ||
|
||
|
||
def rename(src: Path, dest: Path, verbose=False): | ||
"""A wrapper around `pathlib.Path.rename` with optional loggging.""" | ||
if verbose: | ||
print(f"mv {src} {dest}") | ||
src.rename(dest) | ||
|
||
|
||
def copy2(src: Path, dest: Path, verbose=False): | ||
"""A wrapper around `shutil.copy2` with optional logging.""" | ||
if verbose: | ||
print(f"cp -p {src} {dest}") | ||
shutil.copy2(src, dest) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.