usgs / groundmotion-processing

Parsing and processing ground motion data
Other
54 stars 41 forks source link

Always print absolute project paths #1025

Closed emthompson-usgs closed 1 year ago

emthompson-usgs commented 1 year ago

I think this undoes a mistake I made in #1022.

emthompson-usgs commented 1 year ago

For context, the reason things are a bit complicated is in response to this issue. And since I don't understand how/where the absolute paths are creating problems, I thought we should just use relative paths as much as possible to avoid the problem. But when paths are printed to the terminal or log files, I like to have absolute paths because then it is easy to copy/paste them without having to go through the process of figuring out where they are relative to every time.

baagaard-usgs commented 1 year ago

I don't understand why do we need the check that the platform is not Windows when we use resolve()? Doesn't resolve() work on Windows too?

I would also add the following fix so that relative paths are not used when storing the projects configuration in "~/.gmprocess`:

diff --git a/src/gmprocess/subcommands/projects.py b/src/gmprocess/subcommands/projects.py
index 85b6f039..6bd0d258 100644
--- a/src/gmprocess/subcommands/projects.py
+++ b/src/gmprocess/subcommands/projects.py
@@ -372,7 +372,7 @@ def create(config, use_cwd=False):

     # Apparently, relpath doesn't work for Windows, at least with the Azure
     # CI builds
-    if platform.system() != "Windows":
+    if platform.system() != "Windows" and use_cwd:
         rel_path_loc = Path(config.filename).parents[1]
         conf_relpath = str(".." / conf_path.relative_to(rel_path_loc))
         data_relpath = str(".." / data_path.relative_to(rel_path_loc))
emthompson-usgs commented 1 year ago

It is just that we don't need to do it on Windows because we aren't using relative paths on Windows. This is because we got errors that we couldn't fix when we do use relative paths on Windows systems, and the request for relative paths is a cluster/linux specific issue.

baagaard-usgs commented 1 year ago

I would just remove the if condition for Windows because resolve() works for absolute and relative paths. I think eliminating unnecessary ifs makes the code cleaner.

Here is the fix for eliminating the double prompt when creating system levels projects when no current projects configuration exists:

diff --git a/src/gmprocess/apps/gmrecords.py b/src/gmprocess/apps/gmrecords.py
index 42715cc3..5d720ae4 100644
--- a/src/gmprocess/apps/gmrecords.py
+++ b/src/gmprocess/apps/gmrecords.py
@@ -151,7 +151,7 @@ class GMrecordsApp(object):
         return (self.projects_path / self.current_project["data_path"]).resolve()

     def _initialize(self):
-        require_config = self.args.subcommand != "projects"
+        require_config = not self.args.subcommand in ["projects", "proj"]
         self._load_config(require_config)

         log_file = self.args.log or None
emthompson-usgs commented 1 year ago

Okay, sounds good. I'll apply these changes to this branch.