A few functions in constants.py check for drive prefixes where other code does not. Lets just use os.path.isabs() and let it deal with platform related stuff. I suppose path.startswith('/') would probably work too but it is less clear and would make Windows (without Cygwin) support harder in the future.
* pygnulib/GLImport.py (GLImport.relative_to_destdir) (GLImport.relative_to_currdir): Use os.path.isabs() instead of checking for a slash. * pygnulib/constants.py (symlink_relative, as_link_value_at_dest) (hardlink): Use os.path.isabs() instead of checking for a slash or drive prefix. --- ChangeLog | 10 ++++++++++ pygnulib/GLImport.py | 8 ++++---- pygnulib/constants.py | 11 +++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8e67f0a816..3d34109399 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-06-09 Collin Funk <collin.fu...@gmail.com> + + gnulib-tool.py: Handle absolute path checks consistently. + * pygnulib/GLImport.py (GLImport.relative_to_destdir) + (GLImport.relative_to_currdir): Use os.path.isabs() instead of checking + for a slash. + * pygnulib/constants.py (symlink_relative, as_link_value_at_dest) + (hardlink): Use os.path.isabs() instead of checking for a slash or drive + prefix. + 2024-06-09 Bruno Haible <br...@clisp.org> c32width tests: Avoid a test failure on Solaris 11 OpenIndiana, OmniOS. diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index df541a8b77..5f090d4ea1 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -418,10 +418,10 @@ def relative_to_destdir(self, dir: str) -> str: directory, to a filename relative to destdir. GLConfig: destdir.''' destdir = self.config['destdir'] - if dir.startswith('/'): + if os.path.isabs(dir): return dir else: - if destdir.startswith('/'): + if os.path.isabs(destdir): # XXX This doesn't look right. return dir else: @@ -433,10 +433,10 @@ def relative_to_currdir(self, dir: str) -> str: to a filename relative to the current directory. GLConfig: destdir.''' destdir = self.config['destdir'] - if dir.startswith('/'): + if os.path.isabs(dir): return dir else: - if destdir.startswith('/'): + if os.path.isabs(destdir): # XXX This doesn't look right. return joinpath(destdir, dir) else: diff --git a/pygnulib/constants.py b/pygnulib/constants.py index 4890e2129f..71811576da 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -362,7 +362,7 @@ def symlink_relative(src: str, dest: str) -> None: os.symlink(src, dest) except PermissionError: sys.stderr.write('%s: ln -s failed; falling back on cp -p\n' % APP['name']) - if src.startswith('/') or (len(src) >= 2 and src[1] == ':'): + if os.path.isabs(src): # src is absolute. cp_src = src else: @@ -384,12 +384,11 @@ def as_link_value_at_dest(src: str, dest: str) -> str: raise TypeError('src must be a string, not %s' % (type(src).__name__)) if type(dest) is not str: raise TypeError('dest must be a string, not %s' % (type(dest).__name__)) - if src.startswith('/') or (len(src) >= 2 and src[1] == ':'): + if os.path.isabs(src): return src else: # if src is not absolute - if dest.startswith('/') or (len(dest) >= 2 and dest[1] == ':'): - cwd = os.getcwd() - return joinpath(cwd, src) + if os.path.isabs(dest): + return joinpath(os.getcwd(), src) else: # if dest is not absolute destdir = os.path.dirname(dest) if not destdir: @@ -427,7 +426,7 @@ def hardlink(src: str, dest: str) -> None: os.link(src, dest) except PermissionError: sys.stderr.write('%s: ln failed; falling back on cp -p\n' % APP['name']) - if src.startswith('/') or (len(src) >= 2 and src[1] == ':'): + if os.path.isabs(src): # src is absolute. cp_src = src else: -- 2.45.2