diff --git a/pymake/pymake.py b/pymake/pymake.py index ecb50b4..00ce0fb 100644 --- a/pymake/pymake.py +++ b/pymake/pymake.py @@ -236,7 +236,7 @@ def compress_targets(self): # set appdir based on first target, assumes that the path # for all of the targets are the same if appdir is None: - appdir = os.path.dirname(target) + appdir = str(Path(target).parent) # determine files in appdir if no applications build at this # time (--keep command line argument) else: @@ -529,6 +529,8 @@ def set_build_target_bool(self, target=None): target = self.target if self.appdir is not None: + # os.path.dirname rather than Path.parent, because a target + # with no directory has to compare unequal to an appdir of "." if os.path.dirname(self.target) != self.appdir: target = str(Path(self.appdir) / Path(target).name) @@ -646,7 +648,7 @@ def _set_extrafiles(self): # evaluate extrafiles type if extrafiles: - srcdir = os.path.abspath(self.srcdir) + srcdir = Path(self.srcdir).absolute() if isinstance(extrafiles, list): for idx, value in enumerate(extrafiles): fpth = str(Path(srcdir) / value) @@ -820,6 +822,8 @@ def update_build_targets(self): ------- """ + # os.path.abspath rather than Path.absolute, because it removes the + # ".." segments and so two spellings of a target count as one if os.path.abspath(self.target) not in self.build_targets: if self.verbose: print(f"adding {self.target} to build_targets list") diff --git a/pymake/pymake_base.py b/pymake/pymake_base.py index 832d53e..53711b1 100644 --- a/pymake/pymake_base.py +++ b/pymake/pymake_base.py @@ -1060,7 +1060,9 @@ def _write_makedefaults( line += "endif\n\n" f.write(line) - # get path to executable + # get path to executable. os.path.dirname rather than + # Path.parent, because a target with no directory has to give + # the empty string here rather than "." dpth = os.path.dirname(target) if len(dpth) > 0: dpth = os.path.relpath(dpth, make_dir) diff --git a/pymake/pymake_build_apps.py b/pymake/pymake_build_apps.py index 2803a5c..ecee088 100644 --- a/pymake/pymake_build_apps.py +++ b/pymake/pymake_build_apps.py @@ -26,7 +26,6 @@ """ -import os import shutil import sys from datetime import datetime @@ -118,7 +117,7 @@ def build_apps( if appdir is None: base_pth = "." else: - base_pth = os.path.dirname(appdir) + base_pth = str(Path(appdir).parent) # set the meson directory if a pymake object was not passed in if pymake_object is None: diff --git a/pymake/utils/_meson_build.py b/pymake/utils/_meson_build.py index 6fe21dd..69c2d6f 100644 --- a/pymake/utils/_meson_build.py +++ b/pymake/utils/_meson_build.py @@ -229,6 +229,8 @@ def meson_setup( else: command_list.append("--prefix=$(pwd)") + # os.path, because the install directory is relative to the build + # file and Path.relative_to cannot walk up before python 3.12 libdir = os.path.relpath(os.path.abspath(appdir), os.path.abspath(mesondir)) command_list.append(f"--libdir={libdir}") command_list.append(f"--bindir={libdir}") diff --git a/pymake/utils/_usgs_src_update.py b/pymake/utils/_usgs_src_update.py index 3c75fea..3316df6 100644 --- a/pymake/utils/_usgs_src_update.py +++ b/pymake/utils/_usgs_src_update.py @@ -596,12 +596,10 @@ def _update_vs2dt_files(srcdir, **kwargs): """ # move the main source into the source directory - f1 = Path(srcdir) / ".." / "vs2dt3_3.f" - f1 = os.path.abspath(f1) + f1 = (Path(srcdir).parent / "vs2dt3_3.f").absolute() if not Path(f1).is_file(): raise OSError(f"{f1} does not exist") - f2 = Path(srcdir) / "vs2dt3_3.f" - f2 = os.path.abspath(f2) + f2 = (Path(srcdir) / "vs2dt3_3.f").absolute() shutil.move(f1, f2) if not Path(f2).is_file(): raise OSError(f"{f2} does not exist") diff --git a/pymake/utils/usgsprograms.py b/pymake/utils/usgsprograms.py index b98af6d..4f67008 100644 --- a/pymake/utils/usgsprograms.py +++ b/pymake/utils/usgsprograms.py @@ -103,7 +103,6 @@ def _build_usgs_database(self): ------- """ - # pth = os.path.dirname(os.path.abspath(pymake.__file__)) fpth = Path(__file__).parent / PROGRAM_DATA_FILE with open(fpth, "rb") as f: programs = tomllib.load(f)["program"]