]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
gnulib-tool.py: Fix pylint 'raise-missing-from' warnings.
authorCollin Funk <collin.funk1@gmail.com>
Thu, 4 Apr 2024 21:56:12 +0000 (14:56 -0700)
committerBruno Haible <bruno@clisp.org>
Fri, 5 Apr 2024 00:57:44 +0000 (02:57 +0200)
* 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>

ChangeLog
pygnulib/GLConfig.py
pygnulib/GLFileSystem.py
pygnulib/GLImport.py
pygnulib/GLTestDir.py

index 536c69737ef8567b1d10997f6ab18e4fd9dc2720..3cceb4c60a7856ac3656368f83396414c00f7534 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
index 8136d9b08cf29d4641c0907ba76d6f707bc05c6a..121edf541e920d82538c406d273aea8a42307387 100644 (file)
@@ -539,9 +539,9 @@ class GLConfig:
             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
@@ -585,9 +585,9 @@ class GLConfig:
             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
@@ -630,9 +630,9 @@ class GLConfig:
             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
@@ -688,9 +688,9 @@ class GLConfig:
             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__)
@@ -736,9 +736,9 @@ class GLConfig:
             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__)
index a0cddd8903cbce1277e05c4f3965adf8e2305163..e157578e54131214e9e3595e255794a4cc000c28 100644 (file)
@@ -120,8 +120,8 @@ class GLFileSystem:
                     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)
@@ -260,8 +260,8 @@ class GLFileAssistant:
                 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)
 
@@ -299,8 +299,8 @@ class GLFileAssistant:
                     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)
@@ -313,8 +313,8 @@ class GLFileAssistant:
                             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))
@@ -343,8 +343,8 @@ class GLFileAssistant:
         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
index 5cd39f66a34b8ee2fe8cad2f4c9f21b4b5d69d48..c6d1a758a4c5feeec27237999382314aef1fb6b5 100644 (file)
@@ -1018,8 +1018,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                 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)
 
@@ -1043,8 +1043,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                         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]
index 51c6ee31934e96fdb2003d9200253b3380442dab..829e26fb3f7b3587d37b5f9f5b915671a7bc9060 100644 (file)
@@ -75,12 +75,12 @@ def _patch_test_driver() -> None:
         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
@@ -112,8 +112,8 @@ class GLTestDir:
         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)
@@ -900,8 +900,8 @@ class GLMegaTestDir:
         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)