+2024-04-04 Collin Funk <collin.funk1@gmail.com>
+
+ gnulib-tool.py: Fix pylint 'raise-missing-from' warnings.
+ * pygnulib/*.py: Use explicit exception chaining so that stack trace
+ messages do not seem like bugs. See examples in:
+ <https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00056.html>
+
2024-04-04 Bruno Haible <bruno@clisp.org>
Add serial numbers to *.m4 files that did not have them.
for module in modules:
try: # Try to add each module
self.addModule(module)
- except TypeError:
+ except TypeError as exc:
self.table['modules'] = old_modules
- raise TypeError('each module must be a string')
+ raise TypeError('each module must be a string') from exc
except GLError:
self.table['modules'] = old_modules
raise
for module in modules:
try: # Try to add each module
self.addAvoid(module)
- except TypeError:
+ except TypeError as exc:
self.table['avoids'] = old_avoids
- raise TypeError('each module must be a string')
+ raise TypeError('each module must be a string') from exc
except GLError:
self.table['avoids'] = old_avoids
raise
for file in files:
try: # Try to add each file
self.addFile(file)
- except TypeError:
+ except TypeError as exc:
self.table['files'] = old_files
- raise TypeError('each file must be a string')
+ raise TypeError('each file must be a string') from exc
except GLError:
self.table['files'] = old_files
raise
for category in categories:
try: # Try to enable each category
self.enableInclTestCategory(category)
- except TypeError:
+ except TypeError as exc:
self.table['incl_test_categories'] = old_categories
- raise TypeError('each category must be one of TESTS integers')
+ raise TypeError('each category must be one of TESTS integers') from exc
else: # if type of categories is not list or tuple
raise TypeError('categories must be a list or a tuple, not %s'
% type(categories).__name__)
for category in categories:
try: # Try to enable each category
self.enableExclTestCategory(category)
- except TypeError:
+ except TypeError as exc:
self.table['excl_test_categories'] = old_categories
- raise TypeError('each category must be one of TESTS integers')
+ raise TypeError('each category must be one of TESTS integers') from exc
else: # if type of categories is not list or tuple
raise TypeError('categories must be a list or a tuple, not %s'
% type(categories).__name__)
command = 'patch -s "%s" < "%s" >&2' % (tempFile, diff_in_localdir)
try: # Try to apply patch
sp.check_call(command, shell=True)
- except sp.CalledProcessError:
- raise GLError(2, name)
+ except sp.CalledProcessError as exc:
+ raise GLError(2, name) from exc
result = (tempFile, True)
else:
result = (lookedupFile, False)
else: # Move instead of linking.
try: # Try to move file
movefile(tmpfile, joinpath(destdir, rewritten))
- except Exception:
- raise GLError(17, original)
+ except Exception as exc:
+ raise GLError(17, original) from exc
else: # if self.config['dryrun']
print('Copy file %s' % rewritten)
os.remove(backuppath)
try: # Try to replace the given file
movefile(basepath, backuppath)
- except Exception:
- raise GLError(17, original)
+ except Exception as exc:
+ raise GLError(17, original) from exc
if self.filesystem.shouldLink(original, lookedup) == CopyAction.Symlink \
and not tmpflag and filecmp.cmp(lookedup, tmpfile):
link_if_changed(lookedup, basepath)
if os.path.exists(basepath):
os.remove(basepath)
copyfile(tmpfile, joinpath(destdir, rewritten))
- except Exception:
- raise GLError(17, original)
+ except Exception as exc:
+ raise GLError(17, original) from exc
else: # if self.config['dryrun']
if already_present:
print('Update file %s (backup in %s)' % (rewritten, backupname))
try: # Try to copy lookedup file to tmpfile
copyfile(lookedup, tmpfile)
ensure_writable(tmpfile)
- except Exception:
- raise GLError(15, lookedup)
+ except Exception as exc:
+ raise GLError(15, lookedup) from exc
# Don't process binary files with sed.
if not (original.endswith(".class") or original.endswith(".mo")):
transformer = None
if not self.config['dryrun']:
try: # Try to create directory
os.makedirs(directory)
- except Exception:
- raise GLError(13, directory)
+ except Exception as exc:
+ raise GLError(13, directory) from exc
else: # if self.config['dryrun']
print('Create directory %s' % directory)
if os.path.exists(backup):
os.remove(backup)
movefile(path, '%s~' % path)
- except Exception:
- raise GLError(14, file)
+ except Exception as exc:
+ raise GLError(14, file) from exc
else: # if self.config['dryrun']
print('Remove file %s (backup in %s~)' % (path, path))
filetable['removed'] += [file]
command = f'patch {test_driver} < {diff}'
try:
result = sp.call(command, shell=True, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
- except OSError:
+ except OSError as exc:
if isfile(f'{test_driver}.orig'):
os.remove(f'{test_driver}.orig')
if isfile(f'{test_driver}.rej'):
os.remove(f'{test_driver}.rej')
- raise GLError(20, None)
+ raise GLError(20, None) from exc
if result == 0:
patched = True
break
if not os.path.exists(self.testdir):
try: # Try to create directory
os.mkdir(self.testdir)
- except Exception:
- raise GLError(19, self.testdir)
+ except Exception as exc:
+ raise GLError(19, self.testdir) from exc
self.emitter = GLEmiter(self.config)
self.filesystem = GLFileSystem(self.config)
self.modulesystem = GLModuleSystem(self.config)
if not os.path.exists(self.megatestdir):
try: # Try to create directory
os.mkdir(self.megatestdir)
- except Exception:
- raise GLError(19, self.megatestdir)
+ except Exception as exc:
+ raise GLError(19, self.megatestdir) from exc
self.emitter = GLEmiter(self.config)
self.filesystem = GLFileSystem(self.config)
self.modulesystem = GLModuleSystem(self.config)