[PATCH 3 of 3] import-checker: check modules for pure Python build correctly

Augie Fackler raf at durin42.com
Thu Oct 16 13:31:40 CDT 2014


On Fri, Oct 17, 2014 at 02:34:11AM +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1413479225 -32400
> #      Fri Oct 17 02:07:05 2014 +0900
> # Node ID 6b4ed11ecbfdcff34d47b93f5c7c20193788da79
> # Parent  7ab6646d00d4aa88820d87a1f728d641f9279caf
> import-checker: check modules for pure Python build correctly

Queued per sid0's LGTM on the first one (I like the second two).

>
> Before this patch, "import-checker.py" just replaces "/" in specified
> filenames by ".". This makes modules for pure Python build belong to
> "mercurial.pure" package, and prevents "import-checker.py" from
> correctly checking about cyclic dependency in them.
>
> This patch discards "pure" component from fully qualified name of such
> modules.
>
> To avoid discarding "pure" from the module name of standard libraries
> unexpectedly, this patch allows "dotted_name_of_path" to discard
> "pure" only from Mercurial specific modules, which are specified via
> command line arguments.
>
> diff --git a/contrib/import-checker.py b/contrib/import-checker.py
> --- a/contrib/import-checker.py
> +++ b/contrib/import-checker.py
> @@ -8,11 +8,13 @@
>  import BaseHTTPServer
>  import zlib
>
> -def dotted_name_of_path(path):
> +def dotted_name_of_path(path, trimpure=False):
>      """Given a relative path to a source file, return its dotted module name.
>
>      >>> dotted_name_of_path('mercurial/error.py')
>      'mercurial.error'
> +    >>> dotted_name_of_path('mercurial/pure/parsers.py', trimpure=True)
> +    'mercurial.parsers'
>      >>> dotted_name_of_path('zlibmodule.so')
>      'zlib'
>      """
> @@ -20,6 +22,8 @@
>      parts[-1] = parts[-1].split('.', 1)[0] # remove .py and .so and .ARCH.so
>      if parts[-1].endswith('module'):
>          parts[-1] = parts[-1][:-6]
> +    if trimpure:
> +        return '.'.join(p for p in parts if p != 'pure')
>      return '.'.join(parts)
>
>
> @@ -220,7 +224,7 @@
>      any_errors = False
>      for source_path in argv[1:]:
>          f = open(source_path)
> -        modname = dotted_name_of_path(source_path)
> +        modname = dotted_name_of_path(source_path, trimpure=True)
>          src = f.read()
>          used_imports[modname] = sorted(
>              imported_modules(src, ignore_nested=True))
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list