Skip to content

Commit

Permalink
gnulib-tool.py: Revert previous change.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
collinfunk committed Jun 15, 2024
1 parent fe33f94 commit 7a99ec1
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 135 deletions.
19 changes: 19 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
2024-06-15 Collin Funk <[email protected]>

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 <[email protected]>

timespec-add,timespec-sub: tune
Expand Down
9 changes: 5 additions & 4 deletions pygnulib/GLConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .constants import (
MODES,
TESTS,
joinpath,
remove_trailing_slashes,
)
from .GLError import GLError
Expand Down Expand Up @@ -1047,10 +1048,10 @@ def setAutoconfFile(self, configure_ac: str) -> None:
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.
Expand Down
9 changes: 5 additions & 4 deletions pygnulib/GLEmiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from collections.abc import Callable
from .constants import (
UTILS,
joinpath,
lines_to_multiline,
combine_lines_matching,
substart,
Expand Down Expand Up @@ -824,7 +825,7 @@ def lib_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: G
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
Expand All @@ -842,7 +843,7 @@ def lib_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: G
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 '.'.
Expand Down Expand Up @@ -881,7 +882,7 @@ def lib_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: G
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()
Expand Down Expand Up @@ -1139,7 +1140,7 @@ def tests_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable:
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 '.'.
Expand Down
33 changes: 17 additions & 16 deletions pygnulib/GLFileSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
DIRS,
ensure_writable,
hardlink,
joinpath,
link_if_changed,
movefile,
copyfile,
Expand Down Expand Up @@ -79,23 +80,23 @@ def lookup(self, name: str) -> tuple[str, bool]:
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:
Expand Down Expand Up @@ -131,7 +132,7 @@ def shouldLink(self, original: str, lookedup: str) -> bool:
# 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

Expand Down Expand Up @@ -192,15 +193,15 @@ def tmpfilename(self, path: str) -> str:
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)
else: # if self.config['dryrun']
# 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)
Expand Down Expand Up @@ -244,14 +245,14 @@ def add(self, lookedup: str, tmpflag: bool, tmpfile: str) -> None:
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']
Expand All @@ -276,8 +277,8 @@ def update(self, lookedup: str, tmpflag: bool, tmpfile: str, already_present: bo
% 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:
Expand All @@ -304,7 +305,7 @@ def update(self, lookedup: str, tmpflag: bool, tmpfile: str, already_present: bo
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']
Expand Down Expand Up @@ -356,7 +357,7 @@ def add_or_update(self, already_present: bool) -> None:
# 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)
Expand All @@ -376,8 +377,8 @@ def super_update(self, basename: str, tmpfile: str) -> tuple[str, str, int]:
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
Expand Down
Loading

0 comments on commit 7a99ec1

Please sign in to comment.