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

Paul Moore p.f.moore at gmail.com
Thu Jan 8 20:26:39 CET 2009


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('/'):

I then get the following output:

>regrtest.bat \Apps\Python30\python.exe
test_grammar
test_opcodes
test_dict
test_builtin
test_exceptions
test_types
test_unittest
test_doctest
test_doctest2
test_SimpleHTTPServer
test___all__
test___future__
test__locale
test__locale skipped -- cannot import name RADIXCHAR
test_abc
test_abstract_numbers
test_array
test_ast
test_asynchat
test_asyncore
test_atexit
test_audioop
test_augassign
test_base64
test_bigaddrspace
test_bigmem
test_binascii
test test_binascii failed -- Traceback (most recent call last):
  File "C:\Apps\Python30\lib\test\test_binascii.py", line 177, in
test_no_binary_strings
    self.assertRaises(TypeError, f, "test")
AssertionError: TypeError not raised by crc32

test_binhex
test_binop
test_bisect
test_bool
test_bufio
test_bytes
test_bz2
test_calendar
test_call
test_capi
test_cfgparser
test_cgi
test_charmapcodec
test_class
test_cmath
test_cmd
test_cmd_line
test_cmd_line_script
test_code
test_codeccallbacks
test_codecencodings_cn
test_codecencodings_hk
test_codecencodings_jp
test_codecencodings_kr
test_codecencodings_tw
test_codecmaps_cn
test_codecmaps_cn skipped -- Use of the `urlfetch' resource not enabled
test_codecmaps_hk
test_codecmaps_hk skipped -- Use of the `urlfetch' resource not enabled
test_codecmaps_jp
test_codecmaps_jp skipped -- Use of the `urlfetch' resource not enabled
test_codecmaps_kr
test_codecmaps_kr skipped -- Use of the `urlfetch' resource not enabled
test_codecmaps_tw
test_codecmaps_tw skipped -- Use of the `urlfetch' resource not enabled
test_codecs
test_codeop
test_coding
test_collections
test_colorsys
test_compare
test_compile
test_complex
test_contains
test_contextlib
test_copy
test_copyreg
test_cprofile
test_crypt
test_crypt skipped -- No module named crypt
test_csv
test_ctypes
test_curses
test_curses skipped -- No module named _curses
test_datetime
test_dbm
test_dbm_dumb
test_dbm_gnu
test_dbm_gnu skipped -- No module named _gdbm
test_dbm_ndbm
test_dbm_ndbm skipped -- No module named _dbm
test_decimal
test_decorators
test_defaultdict
test_deque
test_descr
test_descrtut
test_dictcomps
test_dictviews
test_difflib
test_dis
test_docxmlrpc
test_dummy_thread
test_dummy_threading
test_email
test_enumerate
test_eof
test_epoll
test_epoll skipped -- test works only on Linux 2.6
test_errno
test_exception_variations
test_extcall
test_fcntl
test_fcntl skipped -- No module named fcntl
test_file
test_filecmp
test_fileinput
test_fileio
test_float
test_fnmatch
test_fork1
test_fork1 skipped -- os.fork not defined -- skipping test_fork1
test_format
test_fractions
test_frozen
test_ftplib
test_funcattrs
test_functools
test_future
test_future3
test_future4
test_future5
test_gc
test_generators
test_genericpath
test_genexps
test_getargs2
test_getopt
test_gettext
test_glob
test_global
test_grp
test_grp skipped -- No module named grp
test_gzip
test_hash
test_hashlib
test_heapq
test_hmac
test_htmlparser
test_http_cookiejar
test_http_cookies
test_httplib
test_httpservers
test_imaplib
test_imp
test_importhooks
test_index
test_inspect
test_int
test_int_literal
test_io

Testing large file ops skipped on win32.
It requires 2147483648 bytes and a long time.
Use 'regrtest.py -u largefile test_io' to run it.
test_ioctl
test_ioctl skipped -- No fcntl or termios module
test_isinstance
test_iter
test_iterlen
test_itertools
test_json
test_keywordonlyarg
test_kqueue
test_kqueue skipped -- test works only on BSD
test_largefile
test_largefile skipped -- test requires 2500000000 bytes and a long time to run
test_list
test_listcomps
test_locale
test_logging
test_long
test_longexp
test_macpath
test_mailbox
test_marshal
test_math
test_memoryio
test_memoryview
test_metaclass
test_mimetypes
test_minidom
test_mmap
test_module
test_modulefinder
test_multibytecodec
test_multibytecodec_support
test_multiprocessing
test_multiprocessing skipped -- No module named test.test_support
test_mutants
test_netrc
test_nis
test_nis skipped -- No module named nis
test_normalization
test_normalization skipped -- Use of the `urlfetch' resource not enabled
test_ntpath
test_openpty
test_openpty skipped -- No openpty() available.
test_operator
test_optparse
test_os
test_ossaudiodev
test_ossaudiodev skipped -- Use of the `audio' resource not enabled
test_parser
Expecting 's_push: parser stack overflow' in next line
s_push: parser stack overflow
test_peepholer
test_pep247
test_pep277
test_pep292
test_pep3131
test_pep352
test_pickle
test_pickletools
test_pipes
test_pipes skipped -- pipes module only works on posix
test_pkgimport
test_pkgutil
test_platform
test_plistlib
test_poll
test_poll skipped -- select.poll not defined -- skipping test_poll
test_popen
test_poplib
test_posix
test_posix skipped -- posix is not available
test_posixpath
test_pow
test_pprint
test_print
test_profile
test_profilehooks
test_property
test_pstats
test_pty
test_pty skipped -- No module named fcntl
test_pwd
test_pwd skipped -- No module named pwd
test_pyclbr
test_pyexpat
test_queue
test_quopri
test_raise
test_random
test_range
test_re
test_reprlib
test_resource
test_resource skipped -- No module named resource
test_richcmp
test_robotparser
test_runpy
test_sax
test_scope
test_select
test_set
test_setcomps
test_shelve
test_shutil
test_signal
test_signal skipped -- Can't test signal on win32
test_site
test_slice
test_smtplib
test_socket
test_socketserver
test_socketserver skipped -- Use of the `network' resource not enabled
test_sort
test_sqlite
test_ssl
test_startfile
test_strftime
test_string
test_stringprep
test_strlit
test_strptime
test_struct
test_structmembers
test_structseq
test_subprocess
    a DOS box should flash briefly ...
.
    this bit of output is from a test of stdout in a different process ...
test_sundry
test_super
test_symtable
test_syntax
test_sys
test_syslog
test_syslog skipped -- No module named syslog
test_tarfile
test_tcl
test_telnetlib
test_tempfile
test_textwrap
test_thread
test_threaded_import
test_threadedtempfile
test_threading
test_threading_local
test_threadsignals
test_threadsignals skipped -- Can't test signal on win32
test_time
test_timeout
test_timeout skipped -- Use of the `network' resource not enabled
test_tokenize
test_trace
test_traceback
test_tuple
test_typechecks
test_ucn
test_unary
test_unicode
test_unicode_file
test_unicodedata
test_univnewlines
test_unpack
test_unpack_ex
test_urllib
test_urllib2
test_urllib2_localnet
test_urllib2net
test_urllib2net skipped -- Use of the `network' resource not enabled
test_urllibnet
test_urllibnet skipped -- Use of the `network' resource not enabled
test_urlparse
test_userdict
test_userlist
test_userstring
test_uu
test_uuid
    WARNING: uuid.getnode is unreliable on many platforms.
        It is disabled until the code and/or test can be fixed properly.
    WARNING: uuid._ifconfig_getnode is unreliable on many platforms.
        It is disabled until the code and/or test can be fixed properly.
    WARNING: uuid._unixdll_getnode is unreliable on many platforms.
        It is disabled until the code and/or test can be fixed properly.
test_wait3
test_wait3 skipped -- os.fork not defined -- skipping test_wait3
test_wait4
test_wait4 skipped -- os.fork not defined -- skipping test_wait4
test_warnings
test_wave
test_weakref
test_weakset
test_winreg
test_winsound
test_winsound skipped -- Use of the `audio' resource not enabled
test_with
test_wsgiref
test_xdrlib
test_xml_etree
test_xml_etree_c
test_xmlrpc
test_xmlrpc_net
test_xmlrpc_net skipped -- Use of the `network' resource not enabled
test_zipfile
test_zipfile64
test_zipfile64 skipped -- test requires loads of disk-space bytes and
a long time to run
test_zipimport
test_zlib
272 tests OK.
1 test failed:
    test_binascii
40 tests skipped:
    test__locale test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp
    test_codecmaps_kr test_codecmaps_tw test_crypt test_curses
    test_dbm_gnu test_dbm_ndbm test_epoll test_fcntl test_fork1
    test_grp test_ioctl test_kqueue test_largefile
    test_multiprocessing test_nis test_normalization test_openpty
    test_ossaudiodev test_pipes test_poll test_posix test_pty test_pwd
    test_resource test_signal test_socketserver test_syslog
    test_threadsignals test_timeout test_urllib2net test_urllibnet
    test_wait3 test_wait4 test_winsound test_xmlrpc_net test_zipfile64
2 skips unexpected on win32:
    test_dbm_ndbm test_multiprocessing

Hope this helps,
Paul


More information about the Python-Dev mailing list