changeset 39129:4893ef60114f

misc: optional configuration paths
author Dmitry Selyutin <ghostmansd@gmail.com>
date Wed, 04 Jul 2018 23:50:33 +0300
parents d3904b5d6bfd
children e9a763b44069
files pygnulib.py pygnulib/config.py pygnulib/misc.py
diffstat 3 files changed, 41 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/pygnulib.py	Wed Jul 04 10:54:18 2018 +0300
+++ b/pygnulib.py	Wed Jul 04 23:50:33 2018 +0300
@@ -268,9 +268,10 @@
     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 @@
 
     # 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 @@
     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 @@
         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"))
--- a/pygnulib/config.py	Wed Jul 04 10:54:18 2018 +0300
+++ b/pygnulib/config.py	Wed Jul 04 23:50:33 2018 +0300
@@ -13,6 +13,7 @@
 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 @@
         "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 @@
         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 @@
         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(
--- a/pygnulib/misc.py	Wed Jul 04 10:54:18 2018 +0300
+++ b/pygnulib/misc.py	Wed Jul 04 23:50:33 2018 +0300
@@ -75,6 +75,29 @@
         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"""