# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1391560233 -3600
#      Wed Feb 05 01:30:33 2014 +0100
# Node ID 4990abb4729d71acedb92bda7ae84909ef98a1ba
# Parent  a82de9dc4f773422b23ed6c79472a5d55e49bf83
import-checker: fix names of dynamically loaded modules

The import checker found standard library modules such as
lib-dynload/zlibmodule.so but saw that as a 'zlibmodule' module, not as the
'zlib' module.

Debian ships Python with most modules built-in and this incorrect handling of
dynamic modules did thus not cause problems on that platform.

Fedora ships Python with as many modules as possible loaded dynamically. That
made the import checker tests fail with incorrect classification of the
following modules: array fcntl grp itertools time zlib.

This change makes test-module-imports.t pass on Fedora.

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -11,12 +11,15 @@
 def dotted_name_of_path(path):
     """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('zlibmodule.so')
+    'zlib'
     """
     parts = path.split('/')
     parts[-1] = parts[-1][:-3] # remove .py
+    if parts[-1].endswith('module'):
+        parts[-1] = parts[-1][:-6]
     return '.'.join(parts)