From: Collin Funk Date: Sat, 15 Jun 2024 12:42:18 +0000 (-0700) Subject: gnulib-tool.py: Revert previous change. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=7a99ec181aca5cf5839b62e632f7ec4c82b9a845;p=gnulib.git gnulib-tool.py: Revert previous change. * pygnulib/constants.py (joinpath): Restore function and remove unused local variable. (relativize, symlink_relative, as_link_value_at_dest, hardlink): Use it. * pygnulib/GLConfig.py (resetAutoconfFile): Likewise. * pygnulib/GLEmiter.py (lib_Makefile_am, tests_Makefile_am): Likewise. * pygnulib/GLFileSystem.py (lookup, shouldLink, tmpfilename, add) (update, add_or_update, super_update): Likewise. * pygnulib/GLImport.py (__init__, relative_to_currdir) (_done_dir_, _update_ignorelist_, prepare, execute): Likewise. * pygnulib/GLInfo.py (version): Likewise. * pygnulib/GLMakefileTable.py (parent): Likewise. * pygnulib/GLModuleSystem.py (exists, find, getFiles) (getAutomakeSnippet_Unconditional): Likewise. * pygnulib/GLTestDir.py (_patch_test_driver, execute): Likewise. * pygnulib/main.py (main): Likewise. --- diff --git a/ChangeLog b/ChangeLog index 93266c7e23..e98f9c2c26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2024-06-15 Collin Funk + + gnulib-tool.py: Revert previous change. + * pygnulib/constants.py (joinpath): Restore function and remove unused + local variable. + (relativize, symlink_relative, as_link_value_at_dest, hardlink): Use it. + * pygnulib/GLConfig.py (resetAutoconfFile): Likewise. + * pygnulib/GLEmiter.py (lib_Makefile_am, tests_Makefile_am): Likewise. + * pygnulib/GLFileSystem.py (lookup, shouldLink, tmpfilename, add) + (update, add_or_update, super_update): Likewise. + * pygnulib/GLImport.py (__init__, relative_to_currdir) + (_done_dir_, _update_ignorelist_, prepare, execute): Likewise. + * pygnulib/GLInfo.py (version): Likewise. + * pygnulib/GLMakefileTable.py (parent): Likewise. + * pygnulib/GLModuleSystem.py (exists, find, getFiles) + (getAutomakeSnippet_Unconditional): Likewise. + * pygnulib/GLTestDir.py (_patch_test_driver, execute): Likewise. + * pygnulib/main.py (main): Likewise. + 2024-06-14 Paul Eggert timespec-add,timespec-sub: tune diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index 110bdf3b1d..b8a7fc5b0b 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -24,6 +24,7 @@ from typing import Any from .constants import ( MODES, TESTS, + joinpath, remove_trailing_slashes, ) from .GLError import GLError @@ -1047,10 +1048,10 @@ class GLConfig: def resetAutoconfFile(self) -> None: '''Reset path of autoconf file relative to destdir.''' configure_ac = '' - if os.path.isfile(os.path.join(self.table['destdir'], 'configure.ac')): - configure_ac = os.path.join(self.table['destdir'], 'configure.ac') - elif os.path.isfile(os.path.join(self.table['destdir'], 'configure.in')): - configure_ac = os.path.join(self.table['destdir'], 'configure.in') + if os.path.isfile(joinpath(self.table['destdir'], 'configure.ac')): + configure_ac = joinpath(self.table['destdir'], 'configure.ac') + elif os.path.isfile(joinpath(self.table['destdir'], 'configure.in')): + configure_ac = joinpath(self.table['destdir'], 'configure.in') self.table['configure_ac'] = configure_ac # Define ac_version methods. diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index e03074eb61..cb6106e941 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -24,6 +24,7 @@ import subprocess as sp from collections.abc import Callable from .constants import ( UTILS, + joinpath, lines_to_multiline, combine_lines_matching, substart, @@ -824,7 +825,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ if gnu_make: emit += '# Start of GNU Make output.\n' result = sp.run([UTILS['autoconf'], '-t', 'AC_SUBST:$1 = @$1@', - os.path.join(self.config['destdir'], 'configure.ac')], + joinpath(self.config['destdir'], 'configure.ac')], capture_output=True) if result.returncode == 0: # sort -u @@ -842,7 +843,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ for current_edit in range(0, makefiletable.count()): dictionary = makefiletable[current_edit] if 'var' in dictionary: - if destfile == os.path.join(dictionary['dir'], 'Makefile.am'): + if destfile == joinpath(dictionary['dir'], 'Makefile.am'): val = dictionary['val'] if dictionary['var'] == 'SUBDIRS' and dictionary['dotfirst']: # The added subdirectory ${val} needs to be mentioned after '.'. @@ -881,7 +882,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ else: # Then test if $sourcebase/Makefile.am (if it exists) specifies it. if makefile_name: - path = os.path.join(sourcebase, 'Makefile.am') + path = joinpath(sourcebase, 'Makefile.am') if os.path.isfile(path): with open(path, mode='r', newline='\n', encoding='utf-8') as file: data = file.read() @@ -1139,7 +1140,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ for current_edit in range(0, makefiletable.count()): dictionary = makefiletable[current_edit] if 'var' in dictionary: - if destfile == os.path.join(dictionary['dir'], 'Makefile.am'): + if destfile == joinpath(dictionary['dir'], 'Makefile.am'): val = dictionary['val'] if dictionary['var'] == 'SUBDIRS' and dictionary['dotfirst']: # The added subdirectory ${val} needs to be mentioned after '.'. diff --git a/pygnulib/GLFileSystem.py b/pygnulib/GLFileSystem.py index 4666fcdffb..f2a98a0a28 100644 --- a/pygnulib/GLFileSystem.py +++ b/pygnulib/GLFileSystem.py @@ -28,6 +28,7 @@ from .constants import ( DIRS, ensure_writable, hardlink, + joinpath, link_if_changed, movefile, copyfile, @@ -79,23 +80,23 @@ class GLFileSystem: lookedupFile = None lookedupPatches = [] for localdir in localpath: - file_in_localdir = os.path.join(localdir, name) + file_in_localdir = joinpath(localdir, name) if os.path.isfile(file_in_localdir): lookedupFile = file_in_localdir break - diff_in_localdir = os.path.join(localdir, '%s.diff' % name) + diff_in_localdir = joinpath(localdir, '%s.diff' % name) if os.path.isfile(diff_in_localdir): lookedupPatches.append(diff_in_localdir) # Treat the gnulib dir like a lowest-priority --local-dir, except that # here we don't look for .diff files. if lookedupFile == None: - file_in_localdir = os.path.join(DIRS['root'], name) + file_in_localdir = joinpath(DIRS['root'], name) if os.path.isfile(file_in_localdir): lookedupFile = file_in_localdir if lookedupFile != None: if len(lookedupPatches) > 0: # Apply the patches, from lowest-priority to highest-priority. - tempFile = os.path.join(self.config['tempdir'], name) + tempFile = joinpath(self.config['tempdir'], name) try: # Try to create directories os.makedirs(os.path.dirname(tempFile)) except OSError: @@ -131,7 +132,7 @@ class GLFileSystem: # action anyways. if copymode != lcopymode: for localdir in localpath: - if lookedup == os.path.join(localdir, original): + if lookedup == joinpath(localdir, original): return lcopymode return copymode @@ -192,7 +193,7 @@ class GLFileAssistant: if not self.config['dryrun']: # Put the new contents of $file in a file in the same directory (needed # to guarantee that an 'mv' to "$destdir/$file" works). - result = os.path.join(self.config['destdir'], '%s.tmp' % path) + result = joinpath(self.config['destdir'], '%s.tmp' % path) dirname = os.path.dirname(result) if dirname and not os.path.isdir(dirname): os.makedirs(dirname) @@ -200,7 +201,7 @@ class GLFileAssistant: # Put the new contents of $file in a file in a temporary directory # (because the directory of "$file" might not exist). tempdir = self.config['tempdir'] - result = os.path.join(tempdir, '%s.tmp' % os.path.basename(path)) + result = joinpath(tempdir, '%s.tmp' % os.path.basename(path)) dirname = os.path.dirname(result) if not os.path.isdir(dirname): os.makedirs(dirname) @@ -244,14 +245,14 @@ class GLFileAssistant: print('Copying file %s' % rewritten) if self.filesystem.shouldLink(original, lookedup) == CopyAction.Symlink \ and not tmpflag and filecmp.cmp(lookedup, tmpfile): - link_if_changed(lookedup, os.path.join(destdir, rewritten)) + link_if_changed(lookedup, joinpath(destdir, rewritten)) else: # if any of these conditions is not met if self.filesystem.shouldLink(original, lookedup) == CopyAction.Hardlink \ and not tmpflag and filecmp.cmp(lookedup, tmpfile): - hardlink(lookedup, os.path.join(destdir, rewritten)) + hardlink(lookedup, joinpath(destdir, rewritten)) else: # Move instead of linking. try: # Try to move file - movefile(tmpfile, os.path.join(destdir, rewritten)) + movefile(tmpfile, joinpath(destdir, rewritten)) except Exception as exc: raise GLError(17, original) from exc else: # if self.config['dryrun'] @@ -276,8 +277,8 @@ class GLFileAssistant: % type(already_present).__name__) basename = rewritten backupname = '%s~' % basename - basepath = os.path.join(destdir, basename) - backuppath = os.path.join(destdir, backupname) + basepath = joinpath(destdir, basename) + backuppath = joinpath(destdir, backupname) if not filecmp.cmp(basepath, tmpfile): if not self.config['dryrun']: if already_present: @@ -304,7 +305,7 @@ class GLFileAssistant: try: # Try to move file if os.path.exists(basepath): os.remove(basepath) - copyfile(tmpfile, os.path.join(destdir, rewritten)) + copyfile(tmpfile, joinpath(destdir, rewritten)) except Exception as exc: raise GLError(17, original) from exc else: # if self.config['dryrun'] @@ -356,7 +357,7 @@ class GLFileAssistant: # Write the transformed data to the temporary file. with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file: file.write(re.sub(transformer[0], transformer[1], src_data)) - path = os.path.join(self.config['destdir'], rewritten) + path = joinpath(self.config['destdir'], rewritten) if os.path.isfile(path): # The file already exists. self.update(lookedup, tmpflag, tmpfile, already_present) @@ -376,8 +377,8 @@ class GLFileAssistant: 1: tmpfile was used to update destfile; 2: destfile was created, because it didn't exist.''' backupname = '%s~' % basename - basepath = os.path.join(self.config['destdir'], basename) - backuppath = os.path.join(self.config['destdir'], backupname) + basepath = joinpath(self.config['destdir'], basename) + backuppath = joinpath(self.config['destdir'], backupname) if os.path.isfile(basepath): if filecmp.cmp(basepath, tmpfile): result_flag = 0 diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index db8836d4c9..5f090d4ea1 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -27,6 +27,7 @@ from .constants import ( MODES, TESTS, cleaner, + joinpath, lines_to_multiline, movefile, copyfile, @@ -127,7 +128,7 @@ class GLImport: raise GLError(4, version) # Get other cached variables. - path = os.path.join(self.config['m4base'], 'gnulib-cache.m4') + path = joinpath(self.config['m4base'], 'gnulib-cache.m4') if os.path.isfile(path): with open(path, mode='r', newline='\n', encoding='utf-8') as file: data = file.read() @@ -221,7 +222,7 @@ class GLImport: # Get cached filelist from gnulib-comp.m4. destdir, m4base = self.config.getDestDir(), self.config.getM4Base() - path = os.path.join(destdir, m4base, 'gnulib-comp.m4') + path = joinpath(destdir, m4base, 'gnulib-comp.m4') if os.path.isfile(path): with open(path, mode='r', newline='\n', encoding='utf-8') as file: data = file.read() @@ -290,8 +291,8 @@ class GLImport: base = self.config['destdir'] else: base = '.' - if os.path.isfile(os.path.join(base, 'Makefile.am')): - with open(os.path.join(base, 'Makefile.am'), mode='r', newline='\n', encoding='utf-8') as file: + if os.path.isfile(joinpath(base, 'Makefile.am')): + with open(joinpath(base, 'Makefile.am'), mode='r', newline='\n', encoding='utf-8') as file: data = file.read() pattern = re.compile(r'^AUTOMAKE_OPTIONS[\t ]*=(.*)$', re.MULTILINE) automake_options = pattern.findall(data) @@ -437,7 +438,7 @@ class GLImport: else: if os.path.isabs(destdir): # XXX This doesn't look right. - return os.path.join(destdir, dir) + return joinpath(destdir, dir) else: return relconcat(destdir, dir) @@ -675,14 +676,14 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix '''This method is used to determine ignore argument for _update_ignorelist_ method and then call it.''' destdir = self.config['destdir'] - if (os.path.isdir(os.path.join(destdir, 'CVS')) - or os.path.isdir(os.path.join(destdir, directory, 'CVS')) - or os.path.isfile(os.path.join(destdir, directory, '.cvsignore'))): + if (os.path.isdir(joinpath(destdir, 'CVS')) + or os.path.isdir(joinpath(destdir, directory, 'CVS')) + or os.path.isfile(joinpath(destdir, directory, '.cvsignore'))): self._update_ignorelist_(directory, '.cvsignore', files_added, files_removed) - if (os.path.isdir(os.path.join(destdir, '.git')) - or os.path.isfile(os.path.join(destdir, '.gitignore')) - or os.path.isfile(os.path.join(destdir, directory, '.gitignore'))): + if (os.path.isdir(joinpath(destdir, '.git')) + or os.path.isfile(joinpath(destdir, '.gitignore')) + or os.path.isfile(joinpath(destdir, directory, '.gitignore'))): self._update_ignorelist_(directory, '.gitignore', files_added, files_removed) @@ -696,11 +697,11 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix anchor = '/' else: anchor = '' - srcpath = os.path.join(directory, ignore) + srcpath = joinpath(directory, ignore) backupname = '%s~' % srcpath - if os.path.isfile(os.path.join(destdir, srcpath)): + if os.path.isfile(joinpath(destdir, srcpath)): if files_added or files_removed: - with open(os.path.join(destdir, srcpath), mode='r', newline='\n', encoding='utf-8') as file: + with open(joinpath(destdir, srcpath), mode='r', newline='\n', encoding='utf-8') as file: original_lines = file.readlines() # Clean the newlines but not trailing whitespace. original_lines = [ line.rstrip('\n') @@ -713,7 +714,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix if filenames_to_add or filenames_to_remove: if not self.config['dryrun']: print('Updating %s (backup in %s)' % (srcpath, backupname)) - copyfile2(os.path.join(destdir, srcpath), os.path.join(destdir, backupname)) + copyfile2(joinpath(destdir, srcpath), joinpath(destdir, backupname)) new_lines = original_lines + [ f'{anchor}{filename}' for filename in sorted(filenames_to_add) ] if anchor != '': @@ -724,11 +725,11 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix new_lines = [ line for line in new_lines if line not in lines_to_remove ] - with open(os.path.join(destdir, srcpath), mode='w', newline='\n', encoding='utf-8') as file: + with open(joinpath(destdir, srcpath), mode='w', newline='\n', encoding='utf-8') as file: file.write(lines_to_multiline(new_lines)) else: # if self.config['dryrun'] print('Update %s (backup in %s)' % (srcpath, backupname)) - else: # if not os.path.isfile(os.path.join(destdir, srcpath)) + else: # if not os.path.isfile(joinpath(destdir, srcpath)) if files_added: if not self.config['dryrun']: print('Creating %s' % srcpath) @@ -738,7 +739,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix if ignore == '.cvsignore': # Automake generates Makefile rules that create .dirstamp files. files_added = ['.deps', '.dirstamp'] + files_added - with open(os.path.join(destdir, srcpath), mode='w', newline='\n', encoding='utf-8') as file: + with open(joinpath(destdir, srcpath), mode='w', newline='\n', encoding='utf-8') as file: file.write(lines_to_multiline(files_added)) else: # if self.config['dryrun'] print('Create %s' % srcpath) @@ -876,9 +877,9 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Add m4/gnulib-tool.m4 to the file list. It is not part of any module. new_files = filelist + ['m4/gnulib-tool.m4'] old_files = list(self.cache['files']) - path = os.path.join(destdir, m4base, 'gnulib-tool.m4') + path = joinpath(destdir, m4base, 'gnulib-tool.m4') if os.path.isfile(path): - old_files.append(os.path.join('m4', 'gnulib-tool.m4')) + old_files.append(joinpath('m4', 'gnulib-tool.m4')) # old_files is the list of files according to the last gnulib-tool invocation. # new_files is the list of files after this gnulib-tool invocation. @@ -981,7 +982,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix pairs = sorted(set(pairs), key=lambda pair: pair[0]) files = sorted(set(pair[0] for pair in pairs)) for file in files: - path = os.path.normpath(os.path.join(destdir, file)) + path = joinpath(destdir, file) if os.path.isfile(path) or os.path.islink(path): if not self.config['dryrun']: backup = '%s~' % path @@ -1066,11 +1067,11 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix if pobase: # Create po makefile and auxiliary files. for file in ['Makefile.in.in', 'remove-potcdate.sin']: - tmpfile = assistant.tmpfilename(os.path.join(pobase, file)) - path = os.path.join('build-aux', 'po', file) + tmpfile = assistant.tmpfilename(joinpath(pobase, file)) + path = joinpath('build-aux', 'po', file) lookedup, flag = filesystem.lookup(path) copyfile(lookedup, tmpfile) - basename = os.path.join(pobase, file) + basename = joinpath(pobase, file) filename, backup, flag = assistant.super_update(basename, tmpfile) if flag == 1: if not self.config['dryrun']: @@ -1087,7 +1088,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix os.remove(tmpfile) # Create po makefile parameterization, part 1. - basename = os.path.join(pobase, 'Makevars') + basename = joinpath(pobase, 'Makevars') tmpfile = assistant.tmpfilename(basename) emit = self.emitter.po_Makevars() with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file: @@ -1108,11 +1109,11 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix os.remove(tmpfile) # Create po makefile parameterization, part 2. - basename = os.path.join(pobase, 'POTFILES.in') + basename = joinpath(pobase, 'POTFILES.in') tmpfile = assistant.tmpfilename(basename) with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file: file.write(self.emitter.po_POTFILES_in(filetable.all_files)) - basename = os.path.join(pobase, 'POTFILES.in') + basename = joinpath(pobase, 'POTFILES.in') filename, backup, flag = assistant.super_update(basename, tmpfile) if flag == 1: if not self.config['dryrun']: @@ -1134,17 +1135,17 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix print('Fetching gnulib PO files from %s' % TP_URL) args = ['wget', '--no-verbose', '--mirror', '--level=1', '-nd', '-A.po', '-P', '.', '%sgnulib/' % TP_URL] - sp.call(args, cwd=os.path.join(destdir, pobase)) + sp.call(args, cwd=joinpath(destdir, pobase)) else: # if self.config['dryrun'] print('Fetch gnulib PO files from %s' % TP_URL) # Create po/LINGUAS. - basename = os.path.join(pobase, 'LINGUAS') + basename = joinpath(pobase, 'LINGUAS') if not self.config['dryrun']: tmpfile = assistant.tmpfilename(basename) data = '# Set of available languages.\n' files = sorted([ subend('.po', '', file) - for file in os.listdir(os.path.join(destdir, pobase)) + for file in os.listdir(joinpath(destdir, pobase)) if file.endswith('.po') ]) data += lines_to_multiline(files) with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file: @@ -1159,13 +1160,13 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix os.remove(tmpfile) else: # if not self.config['dryrun'] backupname = '%s~' % basename - if os.path.isfile(os.path.join(destdir, basename)): + if os.path.isfile(joinpath(destdir, basename)): print('Update %s (backup in %s)' % (basename, backupname)) - else: # if not os.path.isfile(os.path.join(destdir, basename)) + else: # if not os.path.isfile(joinpath(destdir, basename)) print('Create %s' % basename) # Create m4/gnulib-cache.m4. - basename = os.path.join(m4base, 'gnulib-cache.m4') + basename = joinpath(m4base, 'gnulib-cache.m4') tmpfile = assistant.tmpfilename(basename) emit = self.gnulib_cache() with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file: @@ -1190,7 +1191,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix os.remove(tmpfile) # Create m4/gnulib-comp.m4. - basename = os.path.join(m4base, 'gnulib-comp.m4') + basename = joinpath(m4base, 'gnulib-comp.m4') tmpfile = assistant.tmpfilename(basename) emit = self.gnulib_comp(filetable, gentests) with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file: @@ -1228,13 +1229,13 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Create library makefile. # Do this after creating gnulib-comp.m4, because func_emit_lib_Makefile_am # can run 'autoconf -t', which reads gnulib-comp.m4. - basename = os.path.join(sourcebase, source_makefile_am) + basename = joinpath(sourcebase, source_makefile_am) tmpfile = assistant.tmpfilename(basename) emit = self.emitter.lib_Makefile_am(basename, self.moduletable.getMainModules(), self.moduletable, self.makefiletable, actioncmd, for_test) if automake_subdir: - emit = sp.run([os.path.join(DIRS['root'], 'build-aux/prefix-gnulib-mk'), '--from-gnulib-tool', + emit = sp.run([joinpath(DIRS['root'], 'build-aux/prefix-gnulib-mk'), '--from-gnulib-tool', f'--lib-name={libname}', f'--prefix={sourcebase}/'], input=emit, text=True, capture_output=True).stdout with open(tmpfile, mode='w', newline='\n', encoding='utf-8') as file: @@ -1256,7 +1257,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Create tests Makefile. if gentests: - basename = os.path.join(testsbase, tests_makefile_am) + basename = joinpath(testsbase, tests_makefile_am) tmpfile = assistant.tmpfilename(basename) emit = self.emitter.tests_Makefile_am(basename, self.moduletable.getTestsModules(), self.moduletable, self.makefiletable, @@ -1282,7 +1283,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Update the .cvsignore and .gitignore files. ignorelist = [] # Treat gnulib-comp.m4 like an added file, even if it already existed. - filetable.added_files.append(os.path.join(m4base, 'gnulib-comp.m4')) + filetable.added_files.append(joinpath(m4base, 'gnulib-comp.m4')) filetable.added_files = sorted(set(filetable.added_files)) filetable.removed_files = sorted(set(filetable.removed_files)) for file in filetable.added_files: @@ -1381,12 +1382,12 @@ in _a_LDFLAGS or _la_LDFLAGS when linking a library.''') if 'var' in dictionary: if dictionary['var'] == 'ACLOCAL_AMFLAGS': print(' - mention "-I %s" in %s in %s' - % (dictionary['val'], dictionary['var'], os.path.join(dictionary['dir'], 'Makefile.am'))) + % (dictionary['val'], dictionary['var'], joinpath(dictionary['dir'], 'Makefile.am'))) print(' or add an AC_CONFIG_MACRO_DIRS([%s]) invocation in %s,' % (dictionary['val'], configure_ac)) else: print(' - mention "%s" in %s in %s,' - % (dictionary['val'], dictionary['var'], os.path.join(dictionary['dir'], 'Makefile.am'))) + % (dictionary['val'], dictionary['var'], joinpath(dictionary['dir'], 'Makefile.am'))) # Detect position_early_after. with open(configure_ac, mode='r', newline='\n', encoding='utf-8') as file: diff --git a/pygnulib/GLInfo.py b/pygnulib/GLInfo.py index 19bea7ecb3..eac4c65071 100644 --- a/pygnulib/GLInfo.py +++ b/pygnulib/GLInfo.py @@ -22,7 +22,7 @@ import os import re import subprocess as sp from pygnulib import __author__, __copyright__ -from .constants import DIRS +from .constants import DIRS, joinpath #=============================================================================== @@ -321,7 +321,7 @@ Report bugs to .''' except: have_git = False if have_git: - version_gen = os.path.join(DIRS['build-aux'], 'git-version-gen') + version_gen = joinpath(DIRS['build-aux'], 'git-version-gen') args = [version_gen, '/dev/null'] result = sp.check_output(args, cwd=DIRS['root']).decode('UTF-8') result = result.strip() diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py index d0151d9b04..efd276d20c 100644 --- a/pygnulib/GLMakefileTable.py +++ b/pygnulib/GLMakefileTable.py @@ -19,6 +19,7 @@ from __future__ import annotations # Define global imports #=============================================================================== import os +from .constants import joinpath from .GLConfig import GLConfig #=============================================================================== @@ -90,12 +91,12 @@ class GLMakefileTable: dir1 = '%s%s' % (m4base, os.path.sep) dir2 = '' while (dir1 - and not (os.path.isfile(os.path.join(self.config['destdir'], dir1, 'Makefile.am')) - or os.path.join(dir1, 'Makefile.am') == os.path.join(sourcebase, source_makefile_am) - or (gentests and os.path.join(dir1, 'Makefile.am') == os.path.join(testsbase, tests_makefile_am)))): - dir2 = os.path.join(os.path.basename(dir1), dir2) + and not (os.path.isfile(joinpath(self.config['destdir'], dir1, 'Makefile.am')) + or joinpath(dir1, 'Makefile.am') == joinpath(sourcebase, source_makefile_am) + or (gentests and joinpath(dir1, 'Makefile.am') == joinpath(testsbase, tests_makefile_am)))): + dir2 = joinpath(os.path.basename(dir1), dir2) dir1 = os.path.dirname(dir1) - self.editor(dir1, 'EXTRA_DIST', os.path.join(dir2, 'gnulib-cache.m4')) + self.editor(dir1, 'EXTRA_DIST', joinpath(dir2, 'gnulib-cache.m4')) def count(self) -> int: '''Count number of edits which are stored, including the removed ones.''' diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 4b1eed8394..02dacfcf9f 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -31,6 +31,7 @@ from .constants import ( TESTS, combine_lines, filter_filelist, + joinpath, lines_to_multiline, subend, ) @@ -90,11 +91,11 @@ class GLModuleSystem: badnames = ['ChangeLog', 'COPYING', 'README', 'TEMPLATE', 'TEMPLATE-EXTENDED', 'TEMPLATE-TESTS'] if module_name not in badnames: - result = os.path.isfile(os.path.join(DIRS['modules'], module_name)) + result = os.path.isfile(joinpath(DIRS['modules'], module_name)) if not result: for localdir in localpath: - if (os.path.isdir(os.path.join(localdir, 'modules')) - and os.path.isfile(os.path.join(localdir, 'modules', module_name))): + if (os.path.isdir(joinpath(localdir, 'modules')) + and os.path.isfile(joinpath(localdir, 'modules', module_name))): result = True break return result @@ -107,7 +108,7 @@ class GLModuleSystem: raise TypeError('module_name must be a string, not %s' % type(module_name).__name__) if self.exists(module_name): - path, istemp = self.filesystem.lookup(os.path.join('modules', module_name)) + path, istemp = self.filesystem.lookup(joinpath('modules', module_name)) result = GLModule(self.config, module_name, path, istemp) return result else: # if not self.exists(module) @@ -469,9 +470,9 @@ class GLModule: result = [ line.strip() for line in snippet.split('\n') if line.strip() ] - result.append(os.path.join('m4', '00gnulib.m4')) - result.append(os.path.join('m4', 'zzgnulib.m4')) - result.append(os.path.join('m4', 'gnulib-common.m4')) + result.append(joinpath('m4', '00gnulib.m4')) + result.append(joinpath('m4', 'zzgnulib.m4')) + result.append(joinpath('m4', 'gnulib-common.m4')) self.cache['files'] = result return self.cache['files'] @@ -620,8 +621,7 @@ class GLModule: buildaux_files = filter_filelist('\n', all_files, 'build-aux/', '', 'build-aux/', '') if buildaux_files != '': - # Don't let os.path.normpath() remove $(top_srcdir) when auxdir starts with '..'. - buildaux_files = [ os.path.join('$(top_srcdir)', os.path.normpath(os.path.join(auxdir, filename))) + buildaux_files = [ os.path.join('$(top_srcdir)', joinpath(auxdir, filename)) for filename in buildaux_files.split('\n') ] result += 'EXTRA_DIST += %s' % ' '.join(buildaux_files) result += '\n\n' diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index 72150afbc5..ad4549f734 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -33,6 +33,7 @@ from .constants import ( ensure_writable, force_output, hardlink, + joinpath, link_relative, lines_to_multiline, movefile, @@ -55,11 +56,11 @@ from .GLFileTable import GLFileTable def _patch_test_driver() -> None: '''Patch the test-driver script in testdirs.''' - test_driver = os.path.join('build-aux', 'test-driver') + test_driver = joinpath('build-aux', 'test-driver') print('patching file %s' % test_driver) - diffs = [ os.path.join(DIRS['root'], name) - for name in [os.path.join('build-aux', 'test-driver.diff'), - os.path.join('build-aux', 'test-driver-1.16.3.diff')] ] + diffs = [ joinpath(DIRS['root'], name) + for name in [joinpath('build-aux', 'test-driver.diff'), + joinpath('build-aux', 'test-driver-1.16.3.diff')] ] patched = False for diff in diffs: command = f'patch {shlex.quote(test_driver)} < {shlex.quote(diff)}' @@ -320,7 +321,7 @@ class GLTestDir: filetable.new_files = sorted(new_table, key=lambda pair: pair[0]) # Create directories. - directories = sorted({ os.path.join(self.testdir, os.path.dirname(pair[0])) + directories = sorted({ joinpath(self.testdir, os.path.dirname(pair[0])) for pair in filetable.new_files }) for directory in directories: if not os.path.isdir(directory): @@ -328,7 +329,7 @@ class GLTestDir: # Copy files or make symbolic links or hard links. for (dest, src) in filetable.new_files: - destpath = os.path.join(self.testdir, dest) + destpath = joinpath(self.testdir, dest) if src.startswith('tests=lib/'): src = substart('tests=lib/', 'lib/', src) lookedup, flag = self.filesystem.lookup(src) @@ -348,10 +349,10 @@ class GLTestDir: # Create $sourcebase/Makefile.am. for_test = True - directory = os.path.join(self.testdir, sourcebase) + directory = joinpath(self.testdir, sourcebase) if not os.path.isdir(directory): os.mkdir(directory) - destfile = os.path.join(directory, 'Makefile.am') + destfile = joinpath(directory, 'Makefile.am') if single_configure: emit = self.emitter.lib_Makefile_am(destfile, main_modules, moduletable, self.makefiletable, '', for_test) @@ -362,10 +363,10 @@ class GLTestDir: file.write(emit) # Create $m4base/Makefile.am. - directory = os.path.join(self.testdir, m4base) + directory = joinpath(self.testdir, m4base) if not os.path.isdir(directory): os.mkdir(directory) - destfile = os.path.join(directory, 'Makefile.am') + destfile = joinpath(directory, 'Makefile.am') emit = '## Process this file with automake to produce Makefile.in.\n\n' emit += 'EXTRA_DIST =\n' for file in filetable.all_files: @@ -380,12 +381,12 @@ class GLTestDir: inctests = self.config.checkInclTestCategory(TESTS['tests']) if inctests: - directory = os.path.join(self.testdir, testsbase) + directory = joinpath(self.testdir, testsbase) if not os.path.isdir(directory): os.mkdir(directory) if single_configure: # Create $testsbase/Makefile.am. - destfile = os.path.join(directory, 'Makefile.am') + destfile = joinpath(directory, 'Makefile.am') witness_macro = '%stests_WITNESS' % macro_prefix emit = self.emitter.tests_Makefile_am(destfile, tests_modules, moduletable, self.makefiletable, witness_macro, for_test) @@ -393,7 +394,7 @@ class GLTestDir: file.write(emit) else: # if not single_configure # Create $testsbase/Makefile.am. - destfile = os.path.join(directory, 'Makefile.am') + destfile = joinpath(directory, 'Makefile.am') libtests = False self.config.setLibtests(False) emit = self.emitter.tests_Makefile_am(destfile, modules, moduletable, @@ -403,7 +404,7 @@ class GLTestDir: # Viewed from the $testsbase subdirectory, $auxdir is different. emit = '' saved_auxdir = auxdir - auxdir = os.path.normpath(os.path.join(relinverse(testsbase), auxdir)) + auxdir = os.path.normpath(joinpath(relinverse(testsbase), auxdir)) self.config.setAuxDir(auxdir) # Create $testsbase/configure.ac. emit += '# Process this file with autoconf ' @@ -489,7 +490,7 @@ class GLTestDir: emit += 'AH_TOP([#include \"../config.h\"])\n\n' emit += 'AC_CONFIG_FILES([Makefile])\n' emit += 'AC_OUTPUT\n' - path = os.path.join(self.testdir, testsbase, 'configure.ac') + path = joinpath(self.testdir, testsbase, 'configure.ac') with open(path, mode='w', newline='\n', encoding='utf-8') as file: file.write(emit) @@ -505,7 +506,7 @@ class GLTestDir: emit += 'AUTOMAKE_OPTIONS = 1.14 foreign\n\n' emit += 'SUBDIRS = %s\n\n' % ' '.join(subdirs) emit += 'ACLOCAL_AMFLAGS = -I %s\n' % m4base - path = os.path.join(self.testdir, 'Makefile.am') + path = joinpath(self.testdir, 'Makefile.am') with open(path, mode='w', newline='\n', encoding='utf-8') as file: file.write(emit) @@ -625,12 +626,12 @@ class GLTestDir: for directory in subdirs: # For subdirs that have a configure.ac by their own, it's the subdir's # configure.ac which creates the subdir's Makefile.am, not this one. - makefiles.append(os.path.join(directory, 'Makefile')) + makefiles.append(joinpath(directory, 'Makefile')) if not single_configure: makefiles = makefiles[:-1] emit += 'AC_CONFIG_FILES([%s])\n' % ' '.join(makefiles) emit += 'AC_OUTPUT\n' - path = os.path.join(self.testdir, 'configure.ac') + path = joinpath(self.testdir, 'configure.ac') with open(path, mode='w', newline='\n', encoding='utf-8') as file: file.write(emit) @@ -640,11 +641,11 @@ class GLTestDir: force_output() os.chdir(self.testdir) # gettext - if os.path.isfile(os.path.join(m4base, 'gettext.m4')): + if os.path.isfile(joinpath(m4base, 'gettext.m4')): args = [UTILS['autopoint'], '--force'] execute(args, verbose) for src in os.listdir(m4base): - src = os.path.join(m4base, src) + src = joinpath(m4base, src) if src.endswith('.m4~'): dest = src[:-1] if os.path.isfile(dest): @@ -677,22 +678,22 @@ class GLTestDir: if inctests and not single_configure: # Do not use "${AUTORECONF} --force --install", because it may invoke # autopoint, which brings in older versions of some of our .m4 files. - os.chdir(os.path.join(self.testdir, testsbase)) + os.chdir(joinpath(self.testdir, testsbase)) # gettext - if os.path.isfile(os.path.join(m4base, 'gettext.m4')): + if os.path.isfile(joinpath(m4base, 'gettext.m4')): args = [UTILS['autopoint'], '--force'] execute(args, verbose) for src in os.listdir(m4base): - src = os.path.join(m4base, src) + src = joinpath(m4base, src) if src.endswith('.m4~'): dest = src[:-1] if os.path.isfile(dest): os.remove(dest) movefile(src, dest) # aclocal - args = [UTILS['aclocal'], '-I', os.path.join('..', m4base)] + args = [UTILS['aclocal'], '-I', joinpath('..', m4base)] execute(args, verbose) - if not os.path.isdir(os.path.join('../build-aux')): + if not os.path.isdir(joinpath('../build-aux')): print('executing mkdir ../build-aux') os.mkdir('../build-aux') # autoconf @@ -712,7 +713,7 @@ class GLTestDir: # Need to run configure and make once, to create built files that are to be # distributed (such as parse-datetime.c). - path = os.path.join(self.testdir, sourcebase, 'Makefile.am') + path = joinpath(self.testdir, sourcebase, 'Makefile.am') with open(path, mode='r', newline='\n', encoding='utf-8') as file: snippet = file.read() snippet = combine_lines(snippet) @@ -757,7 +758,7 @@ class GLTestDir: tests_distributed_built_sources = [] if inctests: # Likewise for built files in the $testsbase directory. - path = os.path.join(self.testdir, testsbase, 'Makefile.am') + path = joinpath(self.testdir, testsbase, 'Makefile.am') with open(path, mode='r', newline='\n', encoding='utf-8') as file: snippet = file.read() snippet = combine_lines(snippet) @@ -839,7 +840,7 @@ class GLTestDir: 'LIBTOOLIZE=%s' % UTILS['libtoolize'], 'distclean'] sp.call(args) - if os.path.isfile(os.path.join('build-aux', 'test-driver')): + if os.path.isfile(joinpath('build-aux', 'test-driver')): _patch_test_driver() os.chdir(DIRS['cwd']) @@ -898,7 +899,7 @@ class GLMegaTestDir: # First, all modules one by one. for module in modules: self.config.setModules([module.name]) - GLTestDir(self.config, os.path.join(self.megatestdir, module.name)).execute() + GLTestDir(self.config, joinpath(self.megatestdir, module.name)).execute() megasubdirs.append(module.name) # Then, all modules all together. @@ -908,7 +909,7 @@ class GLMegaTestDir: if module.name != 'config-h' ] self.config.setModules([ module.name for module in modules ]) - GLTestDir(self.config, os.path.join(self.megatestdir, 'ALL')).execute() + GLTestDir(self.config, joinpath(self.megatestdir, 'ALL')).execute() megasubdirs.append('ALL') # Create autobuild. @@ -926,10 +927,10 @@ class GLMegaTestDir: repdict['Oct'] = repdict['October'] = '10' repdict['Nov'] = repdict['November'] = '11' repdict['Dec'] = repdict['December'] = '12' - vc_witness = os.path.join(DIRS['root'], '.git', 'refs', 'heads', 'master') + vc_witness = joinpath(DIRS['root'], '.git', 'refs', 'heads', 'master') if not os.path.isfile(vc_witness): - vc_witness = os.path.join(DIRS['root'], 'ChangeLog') - mdate_sh = os.path.join(DIRS['root'], 'build-aux', 'mdate-sh') + vc_witness = joinpath(DIRS['root'], 'ChangeLog') + mdate_sh = joinpath(DIRS['root'], 'build-aux', 'mdate-sh') args = ['sh', mdate_sh, vc_witness] cvsdate = sp.check_output(args).decode('UTF-8').strip() for key in repdict: @@ -961,7 +962,7 @@ class GLMegaTestDir: emit += ' ) 2>&1 | { if test -n "$AUTOBUILD_SUBST"; then ' emit += 'sed -e "$AUTOBUILD_SUBST"; else cat; fi; } > logs/$safemodule\n' emit += 'done\n' - path = os.path.join(self.megatestdir, 'do-autobuild') + path = joinpath(self.megatestdir, 'do-autobuild') with open(path, mode='w', newline='\n', encoding='utf-8') as file: file.write(emit) @@ -970,7 +971,7 @@ class GLMegaTestDir: emit += 'AUTOMAKE_OPTIONS = 1.14 foreign\n\n' emit += 'SUBDIRS = %s\n\n' % ' '.join(megasubdirs) emit += 'EXTRA_DIST = do-autobuild\n' - path = os.path.join(self.megatestdir, 'Makefile.am') + path = joinpath(self.megatestdir, 'Makefile.am') with open(path, mode='w', newline='\n', encoding='utf-8') as file: file.write(emit) @@ -984,7 +985,7 @@ class GLMegaTestDir: emit += 'AC_CONFIG_SUBDIRS([%s])\n' % ' '.join(megasubdirs) emit += 'AC_CONFIG_FILES([Makefile])\n' emit += 'AC_OUTPUT\n' - path = os.path.join(self.megatestdir, 'configure.ac') + path = joinpath(self.megatestdir, 'configure.ac') with open(path, mode='w', newline='\n', encoding='utf-8') as file: file.write(emit) @@ -1004,6 +1005,6 @@ class GLMegaTestDir: args = [UTILS['automake'], '--add-missing', '--copy'] execute(args, verbose) rmtree('autom4te.cache') - if os.path.isfile(os.path.join('build-aux', 'test-driver')): + if os.path.isfile(joinpath('build-aux', 'test-driver')): _patch_test_driver() os.chdir(DIRS['cwd']) diff --git a/pygnulib/constants.py b/pygnulib/constants.py index 29952f4f46..8c4671116b 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -252,6 +252,16 @@ def cleaner(sequence: str | list[str]) -> str | list[str | bool]: return sequence +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)'.''' + return os.path.normpath(os.path.join(head, *tail)) + + def relativize(dir1: str, dir2: str) -> str: '''Compute a relative pathname reldir such that dir1/reldir = dir2. dir1 and dir2 must be relative pathnames.''' @@ -262,7 +272,7 @@ def relativize(dir1: str, dir2: str) -> str: first = dir1[:dir1.find(os.path.sep)] if first != '.': if first == '..': - dir2 = os.path.join(os.path.basename(dir0), dir2) + dir2 = joinpath(os.path.basename(dir0), dir2) dir0 = os.path.dirname(dir0) else: # if first != '..' # Get first component of dir2 @@ -270,8 +280,8 @@ def relativize(dir1: str, dir2: str) -> str: if first == first2: dir2 = dir2[dir2.find(os.path.sep) + 1:] else: # if first != first2 - dir2 = os.path.join('..', dir2) - dir0 = os.path.join(dir0, first) + dir2 = joinpath('..', dir2) + dir0 = joinpath(dir0, first) dir1 = dir1[dir1.find(os.path.sep) + 1:] result = os.path.normpath(dir2) return result @@ -355,7 +365,7 @@ def symlink_relative(src: str, dest: str) -> None: # src is relative to the directory of dest. last_slash = dest.rfind('/') if last_slash >= 0: - cp_src = os.path.join(dest[0:last_slash-1], src) + cp_src = joinpath(dest[0:last_slash-1], src) else: cp_src = src copyfile2(cp_src, dest) @@ -374,7 +384,7 @@ def as_link_value_at_dest(src: str, dest: str) -> str: return src else: # if src is not absolute if os.path.isabs(dest): - return os.path.join(os.getcwd(), src) + return joinpath(os.getcwd(), src) else: # if dest is not absolute destdir = os.path.dirname(dest) if not destdir: @@ -419,7 +429,7 @@ def hardlink(src: str, dest: str) -> None: # src is relative to the directory of dest. last_slash = dest.rfind('/') if last_slash >= 0: - cp_src = os.path.join(dest[0: last_slash - 1], src) + cp_src = joinpath(dest[0: last_slash - 1], src) else: cp_src = src copyfile2(cp_src, dest) diff --git a/pygnulib/main.py b/pygnulib/main.py index aa678afd25..c1c2cd2c1e 100644 --- a/pygnulib/main.py +++ b/pygnulib/main.py @@ -92,6 +92,7 @@ from pygnulib.constants import ( UTILS, MODES, ENCS, + joinpath, lines_to_multiline, ensure_writable, copyfile, @@ -858,9 +859,9 @@ def main(temp_directory: str) -> None: elif mode == 'find': modulesystem = GLModuleSystem(config) for filename in files: - if (os.path.isfile(os.path.join(DIRS['root'], filename)) + if (os.path.isfile(joinpath(DIRS['root'], filename)) or (localpath != None - and any([ os.path.isfile(os.path.join(localdir, filename)) + and any([ os.path.isfile(joinpath(localdir, filename)) for localdir in localpath ]))): # Convert the file name to a POSIX basic regex. # Needs to handle . [ \ * ^ $. @@ -955,7 +956,7 @@ def main(temp_directory: str) -> None: if m4base: # Apply func_import to a particular gnulib directory. # Any number of additional modules can be given. - if not os.path.isfile(os.path.join(destdir, m4base, 'gnulib-cache.m4')): + if not os.path.isfile(joinpath(destdir, m4base, 'gnulib-cache.m4')): # First use of gnulib in the given m4base. if not sourcebase: sourcebase = 'lib' @@ -982,7 +983,7 @@ def main(temp_directory: str) -> None: # too expensive.) m4dirs = [] dirisnext = False - filepath = os.path.join(destdir, 'Makefile.am') + filepath = joinpath(destdir, 'Makefile.am') if os.path.isfile(filepath): with open(filepath, mode='r', newline='\n', encoding='utf-8') as file: data = file.read() @@ -996,7 +997,7 @@ def main(temp_directory: str) -> None: if dirisnext: # Ignore absolute directory pathnames, like /usr/local/share/aclocal. if not os.path.isabs(aclocal_amflag): - if os.path.isfile(os.path.join(destdir, aclocal_amflag, 'gnulib-cache.m4')): + if os.path.isfile(joinpath(destdir, aclocal_amflag, 'gnulib-cache.m4')): m4dirs.append(aclocal_amflag) dirisnext = False else: # if not dirisnext @@ -1007,11 +1008,11 @@ def main(temp_directory: str) -> None: for arg in guessed_m4dirs: # Ignore absolute directory pathnames, like /usr/local/share/aclocal. if not os.path.isabs(arg): - if os.path.isfile(os.path.join(destdir, arg, 'gnulib-cache.m4')): + if os.path.isfile(joinpath(destdir, arg, 'gnulib-cache.m4')): m4dirs.append(arg) else: # if not os.path.isfile(filepath) # No Makefile.am! Oh well. Look at the last generated aclocal.m4. - filepath = os.path.join(destdir, 'aclocal.m4') + filepath = joinpath(destdir, 'aclocal.m4') if os.path.isfile(filepath): pattern = re.compile(r'm4_include\(\[(.*?)]\)') with open(filepath, mode='r', newline='\n', encoding='utf-8') as file: @@ -1020,7 +1021,7 @@ def main(temp_directory: str) -> None: for m4dir in m4dirs ] m4dirs = [ m4dir for m4dir in m4dirs - if os.path.isfile(os.path.join(destdir, m4dir, 'gnulib-cache.m4')) ] + if os.path.isfile(joinpath(destdir, m4dir, 'gnulib-cache.m4')) ] m4dirs = sorted(set(m4dirs)) if len(m4dirs) == 0: # First use of gnulib in a package. @@ -1319,7 +1320,7 @@ def main(temp_directory: str) -> None: destdir = os.path.dirname(dest) destpath = os.path.basename(dest) # Create the directory for destfile. - dirname = os.path.dirname(os.path.join(destdir, destpath)) + dirname = os.path.dirname(joinpath(destdir, destpath)) if not config['dryrun']: if dirname and not os.path.isdir(dirname): try: # Try to create directories @@ -1334,10 +1335,10 @@ def main(temp_directory: str) -> None: ensure_writable(tmpfile) assistant.setOriginal(srcpath) assistant.setRewritten(destpath) - if os.path.isfile(os.path.join(destdir, destpath)): + if os.path.isfile(joinpath(destdir, destpath)): # The file already exists. assistant.update(lookedup, flag, tmpfile, True) - else: # if not os.path.isfile(os.path.join(destdir, destpath)) + else: # if not os.path.isfile(joinpath(destdir, destpath)) # Install the file. # Don't protest if the file should be there but isn't: it happens # frequently that developers don't put autogenerated files under @@ -1358,7 +1359,7 @@ def main(temp_directory: str) -> None: # This disturbs the result of the next "gitk" invocation. # Workaround: Let git scan the files. This can be done through # "git update-index --refresh" or "git status" or "git diff". - if os.path.isdir(os.path.join(DIRS['root'], '.git')): + if os.path.isdir(joinpath(DIRS['root'], '.git')): try: sp.run(['git', 'update-index', '--refresh'], cwd=DIRS['root'], stdout=sp.DEVNULL)