diff --git a/CHANGELOG.md b/CHANGELOG.md index db9b0f42ea7815ce8ea0ca870fcaacf052da4e6a..11fef38ac311758f78d95722e93a8941a43629d4 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 bdaf84fb870b50a16a6bbb878a6ae198d8057b7b..a36022a2abc22415b9c190371e5d6eeca5fd176d 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()