From 4da99aabaa6993d6538b84a4e2cbc91216cf6159 Mon Sep 17 00:00:00 2001 From: Ross Beyer <rbeyer@rossbeyer.net> Date: Wed, 10 Feb 2021 06:42:22 -0800 Subject: [PATCH] Convert input relative paths to absolute in isisVarInit.py (#4275) * isisVarInit.py(fix): relative paths given to the command line arguments will now be correctly resolved to their aboslute paths on input, ensuring they will be written into the activation scripts that way. * Added note to Changelog. --- CHANGELOG.md | 1 + isis/scripts/isisVarInit.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db9b0f42ea..11fef38ac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ update the Unreleased link so that it compares against the latest release tag. - Fixed not being able to enable USECOORDLIST argument in mappt. [#4150](https://github.com/USGS-Astrogeology/ISIS3/issues/4150) - Fixed history entry not being added to a cube when running spiceinit with web=true. [4040](https://github.com/USGS-Astrogeology/ISIS3/issues/4040) - Updated wavelength and bandbin values in translation files for the TGO CaSSIS BandBin group. [4147](https://github.com/USGS-Astrogeology/ISIS3/issues/4147) +- Fixed relative paths not being properly converted to absolute paths in isisVarInit.py [4274](https://github.com/USGS-Astrogeology/ISIS3/issues/4274) ## [4.3.0] - 2020-10-02 diff --git a/isis/scripts/isisVarInit.py b/isis/scripts/isisVarInit.py index bdaf84fb87..a36022a2ab 100755 --- a/isis/scripts/isisVarInit.py +++ b/isis/scripts/isisVarInit.py @@ -21,6 +21,26 @@ from pathlib import Path # SPDX-License-Identifier: CC0-1.0 +class ResolveAction(argparse.Action): + """A custom action that returns the absolute version of the provided + pathlib.Path argument. + """ + + def __init__(self, option_strings, dest, type=None, **kwargs): + if issubclass(Path, type): + super(ResolveAction, self).__init__( + option_strings, dest, type=type, **kwargs + ) + else: + raise TypeError( + f"The type= parameter of argument {dest} must be a " + f"class or subclass of pathlib.Path." + ) + + def __call__(self, parser, namespace, values, option_string=None): + setattr(namespace, self.dest, values.resolve()) + + def mkdir(p: Path) -> str: """Returns a string with a message about the creation or existance of the path, *p*.""" @@ -64,23 +84,26 @@ parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( "-d", "--data-dir", - default=os.environ["CONDA_PREFIX"] + "/data", + default=Path(os.environ["CONDA_PREFIX"] + "/data"), type=Path, + action=ResolveAction, help="ISIS Data Directory, default: %(default)s", ) parser.add_argument( "-t", "--test-dir", - default=os.environ["CONDA_PREFIX"] + "/testData", + default=Path(os.environ["CONDA_PREFIX"] + "/testData"), type=Path, + action=ResolveAction, help="ISIS Test Data Directory, default: %(default)s", ) parser.add_argument( "-a", "--ale-dir", - default=os.environ["CONDA_PREFIX"] + "/aleData", + default=Path(os.environ["CONDA_PREFIX"] + "/aleData"), type=Path, + action=ResolveAction, help="ISIS Ale Data Directory, default: %(default)s", ) args = parser.parse_args() -- GitLab