]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
pygnulib: deprecate legacy formatting
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 29 Sep 2017 16:59:42 +0000 (19:59 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 29 Sep 2017 18:12:41 +0000 (21:12 +0300)
pygnulib/config.py
pygnulib/filesystem.py
pygnulib/generator.py
pygnulib/module.py

index 27d277dbec51895ab1b242eb7bacb7866553298e..eba75a805d96b18f8c8ed1e299073015ef791f79 100644 (file)
@@ -91,7 +91,7 @@ class Base:
     def __repr__(self):
         module = self.__class__.__module__
         name = self.__class__.__name__
-        return "{0}.{1}{2}".format(module, name, repr(self.__table))
+        return "{}.{}{}".format(module, name, repr(self.__table))
 
 
     def __iter__(self):
@@ -416,14 +416,14 @@ class Base:
         """include guard prefix"""
         prefix = self["macro_prefix"].upper()
         default = Base._TABLE_["macro_prefix"]
-        return "GL_%s" % prefix if prefix == default else "GL"
+        return "GL_{0}".format(prefix) if prefix == default else "GL"
 
 
     def __getitem__(self, key):
         if key not in Base._TABLE_:
             key = key.replace("-", "_")
             if key not in Base._TABLE_:
-                raise KeyError("unsupported option: %r" % key)
+                raise KeyError("unsupported option: {0}".format(key))
         if key == "all_tests":
             return self.all_tests
         return self.__table[key]
@@ -433,7 +433,7 @@ class Base:
         if key not in Base._TABLE_:
             key = key.replace("_", "-")
             if key not in Base._TABLE_:
-                raise KeyError("unsupported option: %r" % key)
+                raise KeyError("unsupported option: {0}".format(key))
         key = key.replace("-", "_")
         if key == "all_tests":
             self.all_tests = value
index 36d01ee04587bdd2de49682b7f8fb95d721783e4..4ce446315f37911bb15ce6c78420a39e5d6cfcc2 100644 (file)
@@ -44,7 +44,7 @@ class Directory:
     def __repr__(self):
         module = self.__class__.__module__
         name = self.__class__.__name__
-        return "%s.%s{%r}" % (module, name, self.name)
+        return "{}.{}{}".format(module, name, repr(self.__name))
 
 
     def __getitem__(self, name):
@@ -108,7 +108,7 @@ class GnulibGit(Directory):
         config = _BaseConfig_(root=path)
         super().__init__(name, config)
         if not _os_.path.isdir(_os_.path.join(self.path, ".git")):
-            raise TypeError("%r is not a gnulib repository")
+            raise TypeError("{} is not a gnulib repository".format(self.path))
 
 
     def __enter__(self):
index 045065ec08cac012d42bb43d265e7e20ef5bb8a1..baa140327070921e7e6a1dc2bf5e4a0059ece5e2 100644 (file)
@@ -42,7 +42,7 @@ class Generator:
     def __repr__(self):
         module = self.__class__.__module__
         name = self.__class__.__name__
-        return "%s.%s" % (module, name)
+        return "{0}.{1}".format(module, name)
 
     def __str__(self):
         return "\n".join([_ for _ in self])
@@ -117,8 +117,8 @@ class POMakefile(Generator):
     def __repr__(self):
         module = self.__class__.__module__
         name = self.__class__.__name__
-        fmt = "%s.%s{po_base=%r, po_domain=%r}"
-        return fmt % (module, name, self.po_base, self.po_domain)
+        fmt = "{}.{}{po_base={}, po_domain={}}"
+        return fmt.format(module, name, repr(self.__config.po_base), repr(self.__config.po_domain))
 
 
     def __iter__(self):
@@ -126,11 +126,11 @@ class POMakefile(Generator):
             yield line
         yield "# Usually the message domain is the same as the package name."
         yield "# But here it has a '-gnulib' suffix."
-        yield "DOMAIN = %s-gnulib" % self.po_domain
+        yield "DOMAIN = {}-gnulib".format(self.po_domain)
         yield ""
         yield "# These two variables depend on the location of this directory."
-        yield "subdir = %s" % self.po_domain
-        yield "top_subdir = %s" % "/".join([".." for _ in self.po_base.split(_os_.path.sep)])
+        yield "subdir = {}".format(self.po_domain)
+        yield "top_subdir = {}".format("/".join(".." for _ in self.po_base.split(_os_.path.sep)))
         for line in POMakefile._TEMPLATE_:
             yield line
 
@@ -154,8 +154,8 @@ class POTFILES(Generator):
     def __repr__(self):
         module = self.__class__.__module__
         name = self.__class__.__name__
-        fmt = "%s.%s{files=%r}"
-        return fmt % (module, name, self.files)
+        fmt = "{}.{}{files={}}"
+        return fmt.format(module, name, repr(self.__files))
 
 
     def __iter__(self):
@@ -220,8 +220,8 @@ class AutoconfSnippet(Generator):
             flags += ["gettext"]
         include_guard_prefix = self.__config.include_guard_prefix
         flags = "|".join(flags)
-        fmt = "%s.%s{include_guard_prefix=%r, flags=%s}"
-        return fmt % (module, name, include_guard_prefix, flags)
+        fmt = "{}.{}{include_guard_prefix={}, flags={}}"
+        return fmt.format(module, name, repr(include_guard_prefix), flags)
 
 
     def __iter__(self):
@@ -280,8 +280,8 @@ class InitMacro(Generator):
     def __repr__(self):
         module = self.__class__.__module__
         name = self.__class__.__name__
-        fmt = "%s.%s{macro_prefix=%r}"
-        return fmt % (module, name, self.macro_prefix)
+        fmt = "{}.{}{macro_prefix={}}"
+        return fmt.format(module, name, repr(self.__macro_prefix))
 
 
 
@@ -296,6 +296,7 @@ class InitMacroHeader(InitMacro):
 
 
     def __iter__(self):
+        macro_prefix = self.__macro_prefix
         # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
         # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead
         # of LIBOBJS. The purpose is to allow several gnulib instantiations under
@@ -305,8 +306,8 @@ class InitMacroHeader(InitMacro):
         # that uses pieces of gnulib also uses $(LIBOBJ):
         #   automatically discovered file `error.c' should not be explicitly
         #   mentioned.
-        yield "  m4_pushdef([AC_LIBOBJ], m4_defn([%s_LIBOBJ]))" % self.macro_prefix
-        yield "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([%s_REPLACE_FUNCS]))" % self.macro_prefix
+        yield "  m4_pushdef([AC_LIBOBJ], m4_defn([{}_LIBOBJ]))".format(macro_prefix)
+        yield "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([{}_REPLACE_FUNCS]))".format(self.macro_prefix)
 
         # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
         # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
@@ -314,7 +315,7 @@ class InitMacroHeader(InitMacro):
         #   mentioned
         # We let automake know about the files to be distributed through the
         # EXTRA_lib_SOURCES variable.
-        yield "  m4_pushdef([AC_LIBSOURCES], m4_defn([%s_LIBSOURCES]))" % self.macro_prefix
+        yield "  m4_pushdef([AC_LIBSOURCES], m4_defn([{}_LIBSOURCES]))".format(macro_prefix)
 
         # Create data variables for checking the presence of files that are
         # mentioned as AC_LIBSOURCES arguments. These are m4 variables, not shell
@@ -322,8 +323,8 @@ class InitMacroHeader(InitMacro):
         # created, not when it is run. ${macro_prefix_arg}_LIBSOURCES_LIST is the
         # list of files to check for. ${macro_prefix_arg}_LIBSOURCES_DIR is the
         # subdirectory in which to expect them.
-        yield "  m4_pushdef([%s_LIBSOURCES_LIST], [])" % self.macro_prefix
-        yield "  m4_pushdef([%s_LIBSOURCES_DIR], [])" % self.macro_prefix
+        yield "  m4_pushdef([{}_LIBSOURCES_LIST], [])".format(macro_prefix)
+        yield "  m4_pushdef([{}_LIBSOURCES_DIR], [])".format(macro_prefix)
         yield "  gl_COMMON"
 
 
index f966e7483f68e6ba9de020363f01e33d527aeb49..609b6a401b63875c022abafa18877e7f4f4f6ee1 100644 (file)
@@ -284,7 +284,7 @@ class Base:
         if len(module) != len(module.encode()):
             module = (module + "\n").encode("UTF-8")
             module = _hashlib_.md5(module).hexdigest()
-        return "%s_gnulib_enabled_%s" % (macro_prefix, module)
+        return "{}_gnulib_enabled_{}".format(macro_prefix, module)
 
 
     def shell_function(self, macro_prefix="gl"):
@@ -293,7 +293,7 @@ class Base:
         if len(module) != len(module.encode()):
             module = (module + "\n").encode("UTF-8")
             module = _hashlib_.md5(module).hexdigest()
-        return "func_%s_gnulib_m4code_%s" % (macro_prefix, module)
+        return "func_{}_gnulib_m4code_{}".format(macro_prefix, module)
 
 
     def conditional_name(self, macro_prefix="gl"):
@@ -302,7 +302,7 @@ class Base:
         if len(module) != len(module.encode()):
             module = (module + "\n").encode("UTF-8")
             module = _hashlib_.md5(module).hexdigest()
-        return "%s_GNULIB_ENABLED_%s" % (macro_prefix, module)
+        return "{}_GNULIB_ENABLED_{}".format(macro_prefix, module)
 
 
     def __hash__(self):
@@ -312,7 +312,7 @@ class Base:
     def __repr__(self):
         module = self.__class__.__module__
         name = self.__class__.__name__
-        return "%s.%s{%r}" % (module, name, self.name)
+        return "{}.{}{}".format(module, name, repr(self.__table["name"]))
 
 
     def __str__(self):
@@ -391,7 +391,7 @@ class File(Base):
     for (_key_, (_, _typeid_, _value_)) in Base._TABLE_.items():
         _TABLE_[_value_] = (_typeid_, _key_)
     _FIELDS_ = [field for (_, _, field) in Base._TABLE_.values()]
-    _PATTERN_ = _re_.compile("(%s):" % "|".join(_FIELDS_))
+    _PATTERN_ = _re_.compile("({}):".format("|".join(_FIELDS_)))
 
 
     def __init__(self, path, mode="r", name=None, **kwargs):
@@ -399,7 +399,7 @@ class File(Base):
         if name is None:
             name = _os_.path.basename(path)
         if mode not in ("r", "w", "rw"):
-            raise ValueError("illegal mode: %r" % mode)
+            raise ValueError("illegal mode: {}".format(mode))
         if mode == "r":
             with _codecs_.open(path, "rb", "UTF-8") as stream:
                 match = File._PATTERN_.split(stream.read())[1:]
@@ -426,7 +426,7 @@ class File(Base):
             self.__init__(path, "r")
             self.__stream = _codecs_.open(path, "w+", "UTF-8")
         else:
-            raise ValueError("invalid mode: %r" % mode)
+            raise ValueError("illegal mode: {}".format(mode))
 
         for (key, value) in kwargs.items():
             table[key] = value