CI-WATER / gsshapy

An SQLAlchemy ORM for GSSHA model files and a toolkit to convert gridded input into GSSHA input.
BSD 3-Clause "New" or "Revised" License
7 stars 9 forks source link

allow use of relative paths #18

Closed dharhas closed 7 years ago

dharhas commented 7 years ago

Use of relative paths would make sharing examples and model inputs across users/computers a whole lot easier. Is there something fundamental that makes this difficult or is it a case of going through the codebase and making path handling more robust.

snowman2 commented 7 years ago

The issue is that some GSSHA models use relative paths in the project file. So, to be sure the code finds the files correctly, the most robust method is to execute GSSHA/gsshapy from the directory with the model files. To remedy this, gsshapy uses os.chdir to run from the model directory instead of the script directory.

snowman2 commented 7 years ago

@sdc50 recommended calculating the absolute path of the relative path for input files as a possible solution.

dharhas commented 7 years ago

Now I'm not sure how much work this would be without looking at the codebase but we should be able to aim for the following.

1) If we create the model input with gsshapy, always use relative paths within a project folder. This makes the model run more portable.

2) Wrap usage of os.chdir within a context manager so usage of gsshapy is idempotent, i.e. you are in the same directory at the end of the script as at the beginning, even if gsshapy crashes.

3) Detect abs/relative paths and adjust as necessary to make the model happy.

snowman2 commented 7 years ago

@dharhas, I agree.

  1. This is the case.

2/3. I will work on that.

snowman2 commented 7 years ago

@dharhas, I have a working version in master now.

dharhas commented 7 years ago

Nice. Recommend adding a few tests if you haven't already.

snowman2 commented 7 years ago

I had to modify existing tests to work with the updated version, so I am pretty sure it is covered.