Bruno Haible wrote: >> I never really looked at the joinpath() function so I just realized it >> essentially does os.path.normpath(os.path.join(...)) unlike what it's >> doc string says. > > "unlike what the doc string says"? What do you mean by that? The doc string > said "This function also replaces SUBDIR/../ with empty", which is something > that os.path.normpath does but os.path.join doesn't.
Now that I re-read the doc string it appears correct. But I am still confused about what the point of 'newtail' is: def joinpath(head: str, *tail: str) -> str: '''Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. This function also replaces SUBDIR/../ with empty; therefore it is not suitable when some of the pathname components use Makefile variables such as '$(srcdir)'.''' newtail = [] for item in tail: newtail.append(item) result = os.path.normpath(os.path.join(head, *tail)) return result >> The os.path.normpath() isn't really necessary. > > Here I disagree. There are comparisons such as > > lookedup == joinpath(localdir, original) > > which may have evaluated to True, whereas > > lookedup == os.path.join(localdir, original) > > might evaluate to False, due to incomplete normalization. > >> For example, A/./B not being simplified to A/B >> which shouldn't cause any issues building. > > Here I disagree as well. Previously the code could assume everywhere > — including in comparisons and in stdout output — that file names are > normalized. Now this is no longer the case, with consequences: > - Maybe the patch introduced bugs (not caught by the test suite). > - Surely it will make maintenance harder, because everywhere we deal > with a file name, we will have to ask ourselves "is it normalized > or not?" That was already kind-of a problem hence os.path.join() instead of joinpath() in some places. To preserve ./configure.ac vs. configure.ac in comments to match gnulib-tool.sh for example. Maybe it is best to just use normalized paths everywhere since it is easy in Python compared to shell? Either through Pathlib which should do it automatically or os.path.normpath(os.path.join(...)). There are a few places that must be an exception to preserve $(top_srcdir) for example though. Collin