# HG changeset patch # User Dmitry Selyutin # Date 1504987311 -10800 # Node ID b790ffde5faa21cf67550c2a7a0c948493b60abc # Parent 3db083b5486ca6cbe62713b4d355727e67782487 private import even for standard modules diff -r 3db083b5486c -r b790ffde5faa pygnulib/config.py --- a/pygnulib/config.py Sat Sep 09 22:54:55 2017 +0300 +++ b/pygnulib/config.py Sat Sep 09 23:01:51 2017 +0300 @@ -3,12 +3,13 @@ -import argparse -import codecs -import collections -import os -import re -import sys +import argparse as _argparse_ +import codecs as _codecs_ +import collections as _collections_ +import os as _os_ +import re as _re_ +import sys as _sys_ + from .error import type_assert as _type_assert_ from .error import AutoconfVersionError as _AutoconfVersionError_ @@ -397,9 +398,9 @@ class Cache(Base): """gnulib cached configuration""" _AUTOCONF_ = { - "autoconf" : re.compile(".*AC_PREREQ\\(\\[(.*?)\\]\\)", re.S | re.M), - "auxdir" : re.compile("^AC_CONFIG_AUX_DIR\\(\\[(.*?)\\]\\)$", re.S | re.M), - "libtool" : re.compile("A[CM]_PROG_LIBTOOL", re.S | re.M) + "autoconf" : _re_.compile(".*AC_PREREQ\\(\\[(.*?)\\]\\)", _re_.S | _re_.M), + "auxdir" : _re_.compile("^AC_CONFIG_AUX_DIR\\(\\[(.*?)\\]\\)$", _re_.S | _re_.M), + "libtool" : _re_.compile("A[CM]_PROG_LIBTOOL", _re_.S | _re_.M) } _GNULIB_CACHE_ = { "local" : (str, "gl_LOCAL_DIR"), @@ -437,7 +438,7 @@ _GNULIB_CACHE_STR_ += [_key_] else: _GNULIB_CACHE_LIST_ += [_key_] - _GNULIB_CACHE_PATTERN_ = re.compile("^(gl_.*?)\\(\\[(.*?)\\]\\)$", re.S | re.M) + _GNULIB_CACHE_PATTERN_ = _re_.compile("^(gl_.*?)\\(\\[(.*?)\\]\\)$", _re_.S | _re_.M) def __init__(self, root, m4_base, autoconf=None, **kwargs): @@ -448,13 +449,13 @@ def __autoconf(self, root, autoconf): if not autoconf: - autoconf = os.path.join(root, "configure.ac") - if not os.path.exists(autoconf): - autoconf = os.path.join(root, "configure.in") - if not os.path.isabs(autoconf): - autoconf = os.path.join(root, autoconf) - autoconf = os.path.normpath(autoconf) - with codecs.open(autoconf, "rb", "UTF-8") as stream: + autoconf = _os_.path.join(root, "configure.ac") + if not _os_.path.exists(autoconf): + autoconf = _os_.path.join(root, "configure.in") + if not _os_.path.isabs(autoconf): + autoconf = _os_.path.join(root, autoconf) + autoconf = _os_.path.normpath(autoconf) + with _codecs_.open(autoconf, "rb", "UTF-8") as stream: data = stream.read() for key, pattern in Cache._AUTOCONF_.items(): match = pattern.findall(data) @@ -467,9 +468,9 @@ def __gnulib_cache(self, root): m4base = self.m4_base - gnulib_cache = os.path.join(root, m4base, "gnulib-cache.m4") - if os.path.exists(gnulib_cache): - with codecs.open(gnulib_cache, "rb", "UTF-8") as stream: + gnulib_cache = _os_.path.join(root, m4base, "gnulib-cache.m4") + if _os_.path.exists(gnulib_cache): + with _codecs_.open(gnulib_cache, "rb", "UTF-8") as stream: data = stream.read() for key in Cache._GNULIB_CACHE_BOOL_: (_, macro) = Cache._GNULIB_CACHE_[key] @@ -487,12 +488,12 @@ def __gnulib_comp(self, root): m4base = self.m4_base - gnulib_comp = os.path.join(root, m4base, "gnulib-comp.m4") - if os.path.exists(gnulib_comp): - with codecs.open(gnulib_comp, "rb", "UTF-8") as stream: + gnulib_comp = _os_.path.join(root, m4base, "gnulib-comp.m4") + if _os_.path.exists(gnulib_comp): + with _codecs_.open(gnulib_comp, "rb", "UTF-8") as stream: data = stream.read() regex = "AC_DEFUN\\(\\[%s_FILE_LIST\\], \\[(.*?)\\]\\)" % self["macro-prefix"] - pattern = re.compile(regex, re.S | re.M) + pattern = _re_.compile(regex, _re_.S | _re_.M) match = pattern.findall(data) if match: self.files = [_.strip() for _ in match[-1].split("\n") if _.strip()] @@ -562,7 +563,7 @@ _LINK_NOTICE_ = (1 << 3) - class _ModeAction_(argparse.Action): + class _ModeAction_(_argparse_.Action): def __init__(self, *args, **kwargs): mode = kwargs["const"] kwargs["dest"] = "mode" @@ -600,13 +601,13 @@ setattr(namespace, self.dest, new_mode) - class _AvoidAction_(argparse.Action): + class _AvoidAction_(_argparse_.Action): def __call__(self, parser, namespace, value, option=None): values = getattr(namespace, self.dest) values += value - class _VerboseAction_(argparse.Action): + class _VerboseAction_(_argparse_.Action): def __call__(self, parser, namespace, value, option=None): value = getattr(namespace, self.dest) verbose = option in ("-v", "--verbose") @@ -614,7 +615,7 @@ setattr(namespace, self.dest, value) - class _LinkAction_(argparse.Action): + class _LinkAction_(_argparse_.Action): def __call__(self, parser, namespace, value, option=None): flags = getattr(namespace, self.dest) symlink = ("-s", "--symlink", "--local-symlink", "-S", "--more-symlink") @@ -1306,20 +1307,20 @@ def __init__(self, program, argv, **kwargs): _type_assert_("program", program, str) - _type_assert_("argv", argv, collections.Iterable) + _type_assert_("argv", argv, _collections_.Iterable) super().__init__(**kwargs) - parser = argparse.ArgumentParser(prog=program, add_help=False, allow_abbrev=False) + parser = _argparse_.ArgumentParser(prog=program, add_help=False, allow_abbrev=False) for (_, _, args) in CommandLine._SECTIONS_: for arg in args: (options, kwargs) = arg parser.add_argument(*options, **kwargs) - self.__program = os.path.basename(program) + self.__program = _os_.path.basename(program) parser.format_usage = self.__usage parser.format_help = self.__help if "--help" in argv: parser.print_help() - sys.exit(0) + _sys_.exit(0) namespace = parser.parse_args(argv) namespace = vars(namespace) diff -r 3db083b5486c -r b790ffde5faa pygnulib/filesystem.py --- a/pygnulib/filesystem.py Sat Sep 09 22:54:55 2017 +0300 +++ b/pygnulib/filesystem.py Sat Sep 09 23:01:51 2017 +0300 @@ -3,7 +3,8 @@ -import os +import os as _os_ + from .error import type_assert as _type_assert_ from .config import Base as _BaseConfig_ @@ -28,12 +29,12 @@ def __init__(self, root, config): _type_assert_("root", root, str) _type_assert_("config", config, _BaseConfig_) - if not os.path.exists(root): + if not _os_.path.exists(root): raise FileNotFoundError(root) - if not os.path.isdir(root): + if not _os_.path.isdir(root): raise NotADirectoryError(root) self.__config = config - self.__root = os.path.realpath(root) + self.__root = _os_.path.realpath(root) def __getitem__(self, name): @@ -41,10 +42,10 @@ _type_assert_("name", name, str) parts = [] replaced = False - path = os.path.normpath(name) - if os.path.isabs(path): + path = _os_.path.normpath(name) + if _os_.path.isabs(path): raise ValueError("name must be a relative path") - for part in path.split(os.path.sep): + for part in path.split(_os_.path.sep): if part == "..": parts += [part] continue @@ -54,8 +55,8 @@ part = self.__config[new] replaced = True parts += [part] - path = os.path.sep.join([self.__root] + parts) - if not os.path.exists(path): + path = _os_.path.sep.join([self.__root] + parts) + if not _os_.path.exists(path): raise FileNotFoundError(name) return path @@ -84,7 +85,7 @@ def __init__(self, root, config): super().__init__(root, config) - if not os.path.isdir(os.path.join(self.root, ".git")): + if not _os_.path.isdir(_os_.path.join(self.root, ".git")): raise TypeError("%r is not a gnulib repository") @@ -94,14 +95,14 @@ _type_assert_("full", full, bool) if name in Git._EXCLUDE_: raise ValueError("illegal module name") - path = os.path.join(self["modules"], name) + path = _os_.path.join(self["modules"], name) return _FileModule_(path, name=name) if full else _BaseModule_(name) def modules(self, full=True): """iterate over all available modules""" prefix = self["modules"] - for root, _, files in os.walk(prefix): + for root, _, files in _os_.walk(prefix): names = [] for name in files: exclude = False @@ -112,6 +113,6 @@ if not exclude: names += [name] for name in names: - path = os.path.join(root, name) + path = _os_.path.join(root, name) name = path[len(prefix) + 1:] yield self.module(name, full) diff -r 3db083b5486c -r b790ffde5faa pygnulib/generator.py --- a/pygnulib/generator.py Sat Sep 09 22:54:55 2017 +0300 +++ b/pygnulib/generator.py Sat Sep 09 23:01:51 2017 +0300 @@ -3,7 +3,8 @@ -import os +import os as _os_ + from .error import type_assert as _type_assert_ from .config import Base as _BaseConfig_ @@ -124,7 +125,7 @@ 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 "top_subdir = %s" % "/".join([".." for _ in self.po_base.split(_os_.path.sep)]) for line in POMakefile._TEMPLATE_: yield line @@ -155,7 +156,7 @@ yield line yield "# List of files which contain translatable strings." for file in [_ for _ in self.files if _.startswith("lib/")]: - yield os.path.join(self.__config.source_base, file[4:]) + yield _os_.path.join(self.__config.source_base, file[4:]) diff -r 3db083b5486c -r b790ffde5faa pygnulib/module.py --- a/pygnulib/module.py Sat Sep 09 22:54:55 2017 +0300 +++ b/pygnulib/module.py Sat Sep 09 23:01:51 2017 +0300 @@ -3,11 +3,12 @@ -import codecs -import collections -import hashlib -import os -import re +import codecs as _codecs_ +import collections as _collections_ +import hashlib as _hashlib_ +import os as _os_ +import re as _re_ + from .error import type_assert as _type_assert_ @@ -31,8 +32,8 @@ "license" : (0x0C, str, "License"), "maintainers" : (0x0D, list, "Maintainer"), } - _PATTERN_DEPENDENCIES_ = re.compile("^(\\S+)(?:\\s+(.+))*$") - _PATTERN_INCLUDE_ = re.compile("^[\\<\"]([A-Za-z0-9/\\-_]+\\.h)[\\>\"](?:\\s+.*^)*$") + _PATTERN_DEPENDENCIES_ = _re_.compile("^(\\S+)(?:\\s+(.+))*$") + _PATTERN_INCLUDE_ = _re_.compile("^[\\<\"]([A-Za-z0-9/\\-_]+\\.h)[\\>\"](?:\\s+.*^)*$") def __init__(self, name, **kwargs): @@ -120,7 +121,7 @@ @files.setter def files(self, value): - _type_assert_("files", value, collections.Iterable) + _type_assert_("files", value, _collections_.Iterable) result = [] for item in value: _type_assert_("file", item, str) @@ -136,7 +137,7 @@ @dependencies.setter def dependencies(self, value): - _type_assert_("files", value, collections.Iterable) + _type_assert_("files", value, _collections_.Iterable) result = [] for (name, condition) in value: _type_assert_("name", name, str) @@ -187,7 +188,7 @@ @include.setter def include(self, value): - _type_assert_("include", value, collections.Iterable) + _type_assert_("include", value, _collections_.Iterable) result = [] for (header, comment) in value: _type_assert_("header", header, str) @@ -204,7 +205,7 @@ @link.setter def link(self, value): - _type_assert_("link", value, collections.Iterable) + _type_assert_("link", value, _collections_.Iterable) result = [] for item in value: _type_assert_("directive", item, str) @@ -231,7 +232,7 @@ @maintainers.setter def maintainers(self, value): - _type_assert_("maintainers", value, collections.Iterable) + _type_assert_("maintainers", value, _collections_.Iterable) result = [] for item in value: _type_assert_("maintainer", item, str) @@ -244,7 +245,7 @@ module = self.name if len(module) != len(module.encode()): module = (module + "\n").encode("UTF-8") - module = hashlib.md5(module).hexdigest() + module = _hashlib_.md5(module).hexdigest() return "%s_gnulib_enabled_%s" % (macro_prefix, module) @@ -253,7 +254,7 @@ module = self.name if len(module) != len(module.encode()): module = (module + "\n").encode("UTF-8") - module = hashlib.md5(module).hexdigest() + module = _hashlib_.md5(module).hexdigest() return "func_%s_gnulib_m4code_%s" % (macro_prefix, module) @@ -262,7 +263,7 @@ module = self.name if len(module) != len(module.encode()): module = (module + "\n").encode("UTF-8") - module = hashlib.md5(module).hexdigest() + module = _hashlib_.md5(module).hexdigest() return "%s_GNULIB_ENABLED_%s" % (macro_prefix, module) @@ -328,17 +329,17 @@ "Maintainer" : (list, "maintainers"), } _FIELDS_ = [field for (_, _, field) in Base._TABLE_.values()] - _PATTERN_ = re.compile("(%s):" % "|".join(_FIELDS_)) + _PATTERN_ = _re_.compile("(%s):" % "|".join(_FIELDS_)) def __init__(self, path, mode="r", name=None, **kwargs): if name is None: - name = os.path.basename(path) + name = _os_.path.basename(path) if mode not in ("r", "w", "rw"): raise ValueError("illegal mode: %r" % mode) if mode == "r": table = {} - with codecs.open(path, "rb", "UTF-8") as stream: + with _codecs_.open(path, "rb", "UTF-8") as stream: data = "" for line in stream: line = line.strip("\n") @@ -356,10 +357,10 @@ self.__stream = None elif mode == "w": super().__init__(name) - self.__stream = codecs.open(path, "w+", "UTF-8") + self.__stream = _codecs_.open(path, "w+", "UTF-8") elif mode == "rw": self.__init__(path, "r") - self.__stream = codecs.open(path, "w+", "UTF-8") + self.__stream = _codecs_.open(path, "w+", "UTF-8") else: raise ValueError("invalid mode: %r" % mode)