From: Bruno Haible Date: Fri, 12 Apr 2024 22:24:52 +0000 (+0200) Subject: gnulib-tool.py: Refactor. X-Git-Tag: v1.0~108 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=48f615b71b7299e7416ca46db076b7e61820a2f2;p=gnulib.git gnulib-tool.py: Refactor. * pygnulib/GLConfig.py (GLConfig.update, GLConfig.update_key): Improve variable names and comments. * pygnulib/GLImport.py (GLImport.__init__): Improve comments. --- diff --git a/ChangeLog b/ChangeLog index 212a78b305..4d5725f843 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-04-12 Bruno Haible + + 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 gnulib-tool.py: Optimize. diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index 515047d3f0..ab1cb218be 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -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)) diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index b6c9bbeea3..c931536ea9 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -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.