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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 16, 2014, 5:34 p.m.
Message ID <6b4ed11ecbfdcff34d47.1413480851@feefifofum>
Download mbox | patch
Permalink /patch/6333/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Oct. 16, 2014, 5:34 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@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

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.
Mads Kiilerich - Oct. 16, 2014, 5:43 p.m.
On 10/16/2014 07:34 PM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@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

The import checker do things that barely is possible and seems a bit 
fragile. It would be nice to have some actual test coverage for it. I 
failed to introduce that last time I touched it. I am glad you are 
touching it now and thus will become the caring maintainer of it ;-)

/Mads
Augie Fackler - Oct. 16, 2014, 6:31 p.m.
On Fri, Oct 17, 2014 at 02:34:11AM +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@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@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

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))