]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Refactor.
authorBruno Haible <bruno@clisp.org>
Fri, 12 Apr 2024 22:24:52 +0000 (00:24 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 12 Apr 2024 22:24:52 +0000 (00:24 +0200)
* pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Improve
variable names and comments.
* pygnulib/GLImport.py (GLImport.__init__): Improve comments.

ChangeLog
pygnulib/GLConfig.py
pygnulib/GLImport.py

index 212a78b3052c2a10690eb1b07d7bb6c62ca8b9d7..4d5725f843d94424d58b44bf677ae7eafb26e923 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-04-12  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool.py: Refactor.
+       * pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Improve
+       variable names and comments.
+       * pygnulib/GLImport.py (GLImport.__init__): Improve comments.
+
 2024-04-12  Bruno Haible  <bruno@clisp.org>
 
        gnulib-tool.py: Optimize.
index 515047d3f08f1329fc4c9064c37116b1c351204a..ab1cb218bea4f87fdb60212c1a835e2651f318b5 100644 (file)
@@ -270,12 +270,12 @@ class GLConfig:
         table = copy.deepcopy(self)
         return table
 
-    def update(self, dictionary: GLConfig) -> None:
-        '''Specify the dictionary whose keys will be used to update config.'''
-        if type(dictionary) is not GLConfig:
-            raise TypeError('dictionary must be a GLConfig, not %s'
-                            % type(dictionary).__name__)
-        dictionary = dictionary.table
+    def update(self, other_config: GLConfig) -> None:
+        '''Merges all non-default values from other_config into this config.'''
+        if type(other_config) is not GLConfig:
+            raise TypeError('other_config must be a GLConfig, not %s'
+                            % type(other_config).__name__)
+        dictionary = other_config.table
         result = dict()
         for key in dictionary:
             src = self.table[key]
@@ -297,13 +297,13 @@ class GLConfig:
             result[key] = value
         self.table = result
 
-    def update_key(self, dictionary: GLConfig, key: str) -> None:
-        '''Update the given key using value from the given dictionary.'''
+    def update_key(self, other_config: GLConfig, key: str) -> None:
+        '''Copies the value for key from other_config into this config.'''
         if key in self.table:
-            if type(dictionary) is not GLConfig:
-                raise TypeError('dictionary must be a GLConfig, not %s'
-                                % type(dictionary).__name__)
-            dictionary = dictionary.table
+            if type(other_config) is not GLConfig:
+                raise TypeError('other_config must be a GLConfig, not %s'
+                                % type(other_config).__name__)
+            dictionary = other_config.table
             self.table[key] = dictionary[key]
         else:  # if key not in self.table
             raise KeyError('GLConfig does not contain key: %s' % repr(key))
index b6c9bbeea39e41dd4ca66ee3815b92cbdc5a77ca..c931536ea97bd59831f1776a716407d80ae84a88 100644 (file)
@@ -84,24 +84,36 @@ class GLImport:
             raise TypeError('mode must be 0 <= mode <= 3, not %s'
                             % repr(mode))
 
-        # Initialize some values.
-        self.cache = GLConfig()
+        # config contains the configuration, as specified through command-line
+        # parameters.
+
+        # self.config records the configuration that we are building/deducing.
+        # Initialize it with the properties from config.
         self.config = config.copy()
+
+        # self.cache is the configuration extracted from some files on the
+        # file system: configure.{ac,in}, gnulib-cache.m4, gnulib-comp.m4.
+        self.cache = GLConfig()
         os.rmdir(self.cache['tempdir'])
 
-        # Get cached auxdir and libtool from configure.ac/in.
-        self.cache.setAuxDir('.')
+        # Read configure.{ac,in}.
         with codecs.open(self.config.getAutoconfFile(), 'rb', 'UTF-8') as file:
             data = file.read()
+
+        # Get cached auxdir and libtool from configure.{ac,in}.
+        self.cache.setAuxDir('.')
         pattern = re.compile(r'^AC_CONFIG_AUX_DIR\([\[ ]*([^]"$`\\)]+).*?$', re.MULTILINE)
         match = pattern.search(data)
         if match:
             self.cache.setAuxDir(match.group(1))
-        pattern = re.compile(r'A[CM]_PROG_LIBTOOL', re.M)
-        guessed_libtool = bool(pattern.findall(data))
         if self.config['auxdir'] == '':
             self.config.setAuxDir(self.cache['auxdir'])
 
+        # Get libtool guess from configure.{ac,in}.
+        # XXX This is not actually used.
+        pattern = re.compile(r'A[CM]_PROG_LIBTOOL', re.M)
+        guessed_libtool = bool(pattern.findall(data))
+
         # Guess autoconf version.
         pattern = re.compile(r'.*AC_PREREQ\((.*)\)', re.M)
         versions = cleaner(pattern.findall(data))
@@ -244,12 +256,16 @@ class GLImport:
             elif self.mode == MODES['update']:
                 modules = self.cache.getModules()
 
-            # Update configuration dictionary.
+            # Merge the configuration found on disk.
             self.config.update(self.cache)
+
+            # Merge with the configuration from the command-line parameters;
+            # they override the configuration found on disk.
             for key in config.keys():
                 value = config[key]
                 if not config.isdefault(key, value):
                     self.config.update_key(config, key)
+
             self.config.setModules(modules)
 
         # Determine whether --automake-subdir/--automake-subdir-tests are supported.