]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Remove dead code.
authorBruno Haible <bruno@clisp.org>
Thu, 5 Dec 2024 08:14:49 +0000 (09:14 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 5 Dec 2024 08:40:53 +0000 (09:40 +0100)
* pygnulib/GLModuleSystem.py (GLModule.getDependents): Remove top_level
parameter. Use the cached value if present.
* pygnulib/main.py: Update accordingly.

ChangeLog
pygnulib/GLModuleSystem.py
pygnulib/main.py

index c783488d2159e611540c1d0c9dca8e7601f3a61d..771c225c5eb1312206e0eb141578bc62bffd5794 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-12-05  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool.py: Remove dead code.
+       * pygnulib/GLModuleSystem.py (GLModule.getDependents): Remove top_level
+       parameter. Use the cached value if present.
+       * pygnulib/main.py: Update accordingly.
+
 2024-12-04  Collin Funk  <collin.funk1@gmail.com>
 
        gnulib-tool.py: Make --extract-dependents quick again.
index dda1cc36936f10575d1662aeb97637ad7fc5c50d..5182d9ac993bb610a22584c410b5a31f64896da1 100644 (file)
@@ -576,7 +576,7 @@ class GLModule:
         return modules
 
     def _getDependents(self, modules: list[GLModule] | None = None) -> list[GLModule]:
-        '''Internal function for getDependents and getDependentsRecursively
+        '''Internal function for getDependentsRecursively
         accepting an optional argument modules.'''
         if 'dependents' not in self.cache:
             result = []
@@ -588,56 +588,56 @@ class GLModule:
             self.cache['dependents'] = result
         return self.cache['dependents']
 
-    def getDependents(self, top_level: bool | None = True) -> list[GLModule]:
+    def getDependents(self) -> list[GLModule]:
         '''Return list of dependents (a.k.a. "reverse dependencies"),
         as a list of GLModule objects.
-        GLConfig: localpath. Arguments are:
-        - top_level: Optional argument, to use an optimized version from main().'''
-        # Only use optimized version, below if called from the main().
-        if not top_level:
-            return self._getDependents()
-        localpath = self.config['localpath']
-        # Find a set of module candidates quickly.
-        # Convert the module name to a POSIX basic regex.
-        # Needs to handle . [ \ * ^ $.
-        regex = self.name.replace('\\', '\\\\').replace('[', '\\[').replace('^', '\\^')
-        regex = re.compile(r'([.*$])').sub(r'[\1]', regex)
-        line_regex = '^' + regex
-        # We can't add a '$' to line_regex, because that would fail to match
-        # lines that denote conditional dependencies. We could invoke grep
-        # twice, once to search for  line_regex + '$'  and once to search
-        # for   line_regex + [ <TAB>]  but that would be twice as slow.
-        # Read module candidates from gnulib root directory.
-        command = "find modules -type f -print | xargs -n 100 grep -l %s /dev/null | sed -e 's,^modules/,,'" % shlex.quote(line_regex)
-        result = sp.run(command, shell=True, cwd=DIRS['root'], capture_output=True).stdout.decode('utf-8')
-        if localpath != None and len(localpath) > 0:
-            command = "find modules -type f -print | xargs -n 100 grep -l %s /dev/null | sed -e 's,^modules/,,' -e 's,\\.diff$,,'" % shlex.quote(line_regex)
-            for localdir in localpath:
-                result += sp.run(command, shell=True, cwd=localdir, capture_output=True).stdout.decode('utf-8')
-        listing = [ line
-                    for line in result.split('\n')
-                    if line.strip() ]
-        # Remove modules/ prefix from each file name.
-        pattern = re.compile(r'^modules/')
-        listing = [ pattern.sub('', line)
-                    for line in listing ]
-        # Filter out undesired file names.
-        listing = [ line
-                    for line in listing
-                    if self.modulesystem.file_is_module(line) ]
-        # ${module}-tests implicitly depends on ${module}, if both exist.
-        if self.isNonTests():
-            implicit_dependent = self.name+'-tests'
-            if self.modulesystem.exists(implicit_dependent):
-                listing.append(implicit_dependent)
-        candidates = sorted(set(listing))
-        result = []
-        for name in candidates:
-            module = self.modulesystem.find(name)
-            if module:  # Ignore module candidates that don't actually exist.
-                if self in module.getDependenciesWithoutConditions():
-                    result.append(module)
-        self.cache['dependents'] = result
+        This implementation is optimized for the case of a single invocation
+        of getDependents.  If you need multiple invocations, better use _getDependents.
+        GLConfig: localpath.'''
+        if 'dependents' not in self.cache:
+            localpath = self.config['localpath']
+            # Find a set of module candidates quickly.
+            # Convert the module name to a POSIX basic regex.
+            # Needs to handle . [ \ * ^ $.
+            regex = self.name.replace('\\', '\\\\').replace('[', '\\[').replace('^', '\\^')
+            regex = re.compile(r'([.*$])').sub(r'[\1]', regex)
+            line_regex = '^' + regex
+            # We can't add a '$' to line_regex, because that would fail to match
+            # lines that denote conditional dependencies. We could invoke grep
+            # twice, once to search for  line_regex + '$'  and once to search
+            # for   line_regex + [ <TAB>]  but that would be twice as slow.
+            # Read module candidates from gnulib root directory.
+            command = "find modules -type f -print | xargs -n 100 grep -l %s /dev/null | sed -e 's,^modules/,,'" % shlex.quote(line_regex)
+            result = sp.run(command, shell=True, cwd=DIRS['root'], capture_output=True).stdout.decode('utf-8')
+            # Read module candidates from local directories.
+            if localpath != None and len(localpath) > 0:
+                command = "find modules -type f -print | xargs -n 100 grep -l %s /dev/null | sed -e 's,^modules/,,' -e 's,\\.diff$,,'" % shlex.quote(line_regex)
+                for localdir in localpath:
+                    result += sp.run(command, shell=True, cwd=localdir, capture_output=True).stdout.decode('utf-8')
+            listing = [ line
+                        for line in result.split('\n')
+                        if line.strip() ]
+            # Remove modules/ prefix from each file name.
+            pattern = re.compile(r'^modules/')
+            listing = [ pattern.sub('', line)
+                        for line in listing ]
+            # Filter out undesired file names.
+            listing = [ line
+                        for line in listing
+                        if self.modulesystem.file_is_module(line) ]
+            # ${module}-tests implicitly depends on ${module}, if both exist.
+            if self.isNonTests():
+                implicit_dependent = self.name+'-tests'
+                if self.modulesystem.exists(implicit_dependent):
+                    listing.append(implicit_dependent)
+            candidates = sorted(set(listing))
+            result = []
+            for name in candidates:
+                module = self.modulesystem.find(name)
+                if module:  # Ignore module candidates that don't actually exist.
+                    if self in module.getDependenciesWithoutConditions():
+                        result.append(module)
+            self.cache['dependents'] = result
         return self.cache['dependents']
 
 
index d70b566269765efa876e8c717b46ffef1d467255..f6aa9d47eaa7ff79119f7159a27e97e9ef26a287 100644 (file)
@@ -1289,7 +1289,7 @@ def main(temp_directory: str) -> None:
         for name in modules:
             module = modulesystem.find(name)
             if module:
-                dependents = module.getDependents(top_level=True)
+                dependents = module.getDependents()
                 dependents_names = sorted([ m.name
                                             for m in dependents ])
                 sys.stdout.write(lines_to_multiline(dependents_names))