From c27339b33c2f87bd560008ec03efb31998fea1c1 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 29 Sep 2017 19:59:42 +0300 Subject: [PATCH] pygnulib: deprecate legacy formatting --- pygnulib/config.py | 8 ++++---- pygnulib/filesystem.py | 4 ++-- pygnulib/generator.py | 35 ++++++++++++++++++----------------- pygnulib/module.py | 14 +++++++------- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/pygnulib/config.py b/pygnulib/config.py index 27d277dbec..eba75a805d 100644 --- a/pygnulib/config.py +++ b/pygnulib/config.py @@ -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 diff --git a/pygnulib/filesystem.py b/pygnulib/filesystem.py index 36d01ee045..4ce446315f 100644 --- a/pygnulib/filesystem.py +++ b/pygnulib/filesystem.py @@ -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): diff --git a/pygnulib/generator.py b/pygnulib/generator.py index 045065ec08..baa1403270 100644 --- a/pygnulib/generator.py +++ b/pygnulib/generator.py @@ -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" diff --git a/pygnulib/module.py b/pygnulib/module.py index f966e7483f..609b6a401b 100644 --- a/pygnulib/module.py +++ b/pygnulib/module.py @@ -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 -- 2.39.5