[Python-Dev] Getting importlib into the standard library for 3.1

Brett Cannon brett at python.org
Thu Jan 8 20:50:54 CET 2009


On Thu, Jan 8, 2009 at 11:26, Paul Moore <p.f.moore at gmail.com> wrote:
> 2009/1/8 Brett Cannon <brett at python.org>:
>> My work rewriting import in pure Python code has reached beta.
>> Basically the code is semantically complete and as
>> backwards-compatible as I can make it short of widespread testing or
>> running on a Windows box.
>
> I should have done this earlier, sorry. A quick test on Windows XP,
> using the released Python 3.0 installer and a hacked regrtest.bat
> (which is basically regrtest.sh converted to Windows bat file syntax)
> gives:
>
>>regrtest.bat \Apps\Python30\python.exe
> Traceback (most recent call last):
>  File "_importlib.py", line 836, in _import_module
>    loader = self._search_meta_path(name, path)
>  File "_importlib.py", line 751, in _search_meta_path
>    raise ImportError("No module named %s" % name)
> ImportError: No module named test
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>  File "<string>", line 1, in <module>
>  File "_importlib.py", line 1047, in __call__
>    self._import_full_module(name)
>  File "_importlib.py", line 887, in _import_full_module
>    self._import_module(current_name, path_list)
>  File "_importlib.py", line 840, in _import_module
>    loader = self._search_std_path(name, path)
>  File "_importlib.py", line 798, in _search_std_path
>    importer = self._sys_path_importer(entry)
>  File "_importlib.py", line 766, in _sys_path_importer
>    return self.default_path_hook(path_entry)
>  File "_importlib.py", line 245, in chained_fs_path_hook
>    absolute_path = _path_absolute(path_entry)
>  File "_importlib.py", line 112, in _path_absolute
>    return _os._getfullpathname(path)
> WindowsError: [Error 2] The system cannot find the file specified: ''
>
> Looks like ntpath._getfullpathname doesn't like an empty string as an
> argument. The following patch seems to fix this:
>
> --- _importlib.py.orig  2009-01-03 19:50:22.121422900 +0000
> +++ _importlib.py       2009-01-08 19:23:06.218750000 +0000
> @@ -109,6 +109,8 @@
>  def _path_absolute(path):
>     """Replacement for os.path.abspath."""
>     try:
> +        if path == '':
> +            return _os._getfullpathname(_os._getcwd())
>         return _os._getfullpathname(path)
>     except AttributeError:
>         if path.startswith('/'):
>

Thanks, Paul! I changed it to _os.getcwd() since that's what nt exposes.

-Brett


More information about the Python-Dev mailing list