-
Notifications
You must be signed in to change notification settings - Fork 3
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
Refactor work_dir creation #171
Conversation
Codecov Report
@@ Coverage Diff @@
## main #171 +/- ##
==========================================
- Coverage 88.97% 88.58% -0.40%
==========================================
Files 26 26
Lines 1660 1603 -57
==========================================
- Hits 1477 1420 -57
Misses 183 183
|
a7d3f99
to
17ff1e8
Compare
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.
Looks good, I just have a question/comment on the use of chdir
benchcab/benchcab.py
Outdated
with chdir(self.root_dir): | ||
mkdir(internal.SRC_DIR, exist_ok=True, verbose=True) |
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.
We can probably remove the chdir
here? I notice you have used chdir
elsewhere in the code. Was it required to make the tests pass?
with chdir(self.root_dir): | |
mkdir(internal.SRC_DIR, exist_ok=True, verbose=True) | |
mkdir(internal.SRC_DIR, exist_ok=True, verbose=True) |
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.
In the current instantiation of the tests, without mkdir
the paths will be created where the tests are run and not in the temporary location. The paths are deleted right away in the tests so nobody will see them but it is still an undesired side effect. Especially if something goes wrong and they are not deleted.
With the redesign of the tests, since we have a fixture that changes the CWD for the whole test, it will work without chdir
.
I'm happy to wait for the tests redesign to go in first.
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.
I'm surprised the files are not being created in the temporary location since there is a run_around_tests()
autouse fixture which changes the CWD. But I'm happy for this to wait until #172 goes in.
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.
I'll double check...
Yep it is basically a constant so it could go in internal.py. We could define the relative path list in internal.py and iterate over that? |
@SeanBryan51 I think we need to discuss our strategy to create/remove directories. For the moment, we are going towards using relative paths to create the fluxsite run tree. But the clean function uses absolute paths: def clean_directory_tree(root_dir=internal.CWD):
"""Remove pre-existing directories in current working directory."""
src_dir = Path(root_dir, internal.SRC_DIR)
if src_dir.exists():
shutil.rmtree(src_dir)
run_dir = Path(root_dir, internal.RUN_DIR)
if run_dir.exists():
shutil.rmtree(run_dir) This makes it harder to remember what they do, in particular when writing tests as Since |
Yes. I think ideally we should use relative paths whenever paths are prefixed by the CWD. Maybe we can take a look at this when we fix issue #162? |
9e74fb2
to
e73d2e0
Compare
@@ -57,23 +57,27 @@ | |||
CABLE_AUX_DIR / "core" / "biogeochem" / "pftlookup_csiro_v16_17tiles.csv" | |||
) | |||
|
|||
# Fluxsite directory tree | |||
FLUXSITE_DIRS = {} |
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.
Would a list be better here? I.e.
FLUXSITE_DIRS = [
FLUXSITE_RUN_DIR,
FLUXSITE_LOG_DIR,
...
]
I don't mind either way, but it seems using a list would have less changes in the code base.
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.
I don't like having 2 places with the same constants: the constant with its name and then a list with all of them that is used only once in the code after that. Hence the idea of a dictionary so that references to these paths are always handled in the same way throughout the code.
Fixes #150
Added a
mkdir()
wrapper to use throughout the code:benchcab
to createsrc/
, hence removing thesetup_src_dir()
function.fluxsite
to create the task directories withinsetup_task()
workdir
to create the fluxsite run directory tree.Defined
FLUXSITE_DIRS
: a dictionary ininternal.py
that contains all the individual directories for the fluxsite runs.Change the creation and deletion of fluxsite directory tree and source directory to use relative paths instead of absolute paths.