From 4420b71bbf644c1101d08d9d9e0ad40a93283512 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Wed, 4 Jul 2018 23:50:33 +0300 Subject: [PATCH] misc: optional configuration paths --- pygnulib.py | 19 +++++++++++++------ pygnulib/config.py | 11 +++++------ pygnulib/misc.py | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/pygnulib.py b/pygnulib.py index a890b2a71f..dc4afea2cd 100755 --- a/pygnulib.py +++ b/pygnulib.py @@ -268,9 +268,10 @@ def import_hook(script, gnulib, namespace, explicit, verbosity, options, *args, overrides = {BaseVFS(override) for override in config.overrides} for (alias, key) in SUBSTITUTION.items(): path = config[key] if key else "" - project[alias] = path - for override in overrides: - override[alias] = path + if path is not None: + project[alias] = path + for override in overrides: + override[alias] = path gnulib["tests=lib"] = "lib" # Determine all relevant file lists. @@ -438,8 +439,10 @@ def import_hook(script, gnulib, namespace, explicit, verbosity, options, *args, # Find the first parent directory of m4_base that contains or will contain a Makefile.am. (dir1, dir2) = (config.m4_base, "") - source_base_makefile = os.path.join(config.source_base, config.makefile_name) - tests_base_makefile = os.path.join(config.tests_base, config.makefile_name) + makefile_name = config.makefile_name + makefile_name = "Makefile.am" if makefile_name is None else makefile_name + source_base_makefile = os.path.join(config.source_base, makefile_name) + tests_base_makefile = os.path.join(config.tests_base, makefile_name) while dir1 != ".": path = os.path.join(dir1, "Makefile.am") if vfs_exists(project, os.path.join(config.root, dir1, "Makefile.am")) \ @@ -450,7 +453,7 @@ def import_hook(script, gnulib, namespace, explicit, verbosity, options, *args, mkedits.append((dir1, "EXTRA_DIST", os.path.join(dir2, "gnulib-cache.m4"))) # Generate the contents of library makefile. - path = os.path.join(config.source_base, config.makefile_name) + path = os.path.join(config.source_base, makefile_name) with tempfile.NamedTemporaryFile("w", encoding="UTF-8", delete=False) as tmp: arguments = { "path": path, @@ -602,6 +605,10 @@ def import_hook(script, gnulib, namespace, explicit, verbosity, options, *args, for path in removed_files: (directory, name) = os.path.split(path) items[directory].append(["-", name]) + + # Treat gnulib-comp.m4 like an added file, even if it already existed. + items["m4"].append(["+", "gnulib-comp.m4"]) + for directory in sorted(items): gitignore = os.path.isdir(os.path.join(project.root, ".git")) cvsignore = os.path.isdir(os.path.join(project.root, "CVS")) diff --git a/pygnulib/config.py b/pygnulib/config.py index 9c9a6d9ce2..9021fd2889 100644 --- a/pygnulib/config.py +++ b/pygnulib/config.py @@ -13,6 +13,7 @@ from .error import AutoconfVersionError as _AutoconfVersionError from .error import M4BaseMismatchError as _M4BaseMismatchError from .misc import Property as _Property from .misc import PathProperty as _PathProperty +from .misc import OptionalPathProperty as _OptionalPathProperty from .misc import BitwiseProperty as _BitwiseProperty from .misc import StringListProperty as _StringListProperty from .misc import PathListProperty as _PathListProperty @@ -49,12 +50,12 @@ class BaseConfig: "overrides" : tuple(), "source_base" : "lib", "m4_base" : "m4", - "po_base" : "", + "po_base" : None, "doc_base" : "doc", "tests_base" : "tests", "auxdir" : "build-aux", "libname" : "libgnu", - "makefile_name" : "Makefile.am", + "makefile_name" : None, "macro_prefix" : "gl", "po_domain" : "", "witness_c_macro" : "", @@ -218,10 +219,9 @@ class BaseConfig: fset=lambda self, path: self.__set_option("m4_base", path), doc="directory relative to ROOT where *.m4 macros are placed; defaults to 'm4'", ) - po_base = _Property( + po_base = _OptionalPathProperty( fget=lambda self: self.__get_option("po_base"), fset=lambda self, path: self.__set_option("po_base", path), - check=lambda value: isinstance(value, str), doc="directory relative to ROOT where *.po files are placed; defaults to 'po'", ) doc_base = _PathProperty( @@ -245,10 +245,9 @@ class BaseConfig: check=lambda value: isinstance(value, str) and value, doc="library name; defaults to 'libgnu'", ) - makefile_name = _Property( + makefile_name = _OptionalPathProperty( fget=lambda self: self.__get_option("makefile_name"), fset=lambda self, name: self.__set_option("makefile_name", name), - check=lambda value: isinstance(value, str) and value, doc="name of makefile in automake syntax in the source-base and tests-base directories", ) macro_prefix = _Property( diff --git a/pygnulib/misc.py b/pygnulib/misc.py index 2ac96d4c2b..018c7e12d7 100644 --- a/pygnulib/misc.py +++ b/pygnulib/misc.py @@ -75,6 +75,29 @@ class PathProperty(Property): return super().__set__(obj, val) +class OptionalPathProperty(PathProperty): + def __init__(self, fget=None, fset=None, doc=None): + """ + doc : any arbitrary string + fget : function to get the value + fset : function to set the value + + def fget(self): + return self.path + + def fset(self, path): + self.path = path + """ + super().__init__(fget=fget, fset=fset, doc=doc) + + + def __set__(self, obj, val): + if not (val is None or isinstance(val, str)): + raise TypeError("value: str or None expected") + val = _os.path.normpath(val) if val else None + return super(PathProperty, self).__set__(obj, val) + + class BitwiseProperty(Property): """bitwise flag property""" -- 2.39.5