summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
Commit message (Collapse)AuthorAgeFilesLines
* Silence the FileExistsError which can be raised because of the O_EXCL flagAntoine Pitrou2011-10-191-7/+7
| | | | (as in import.c)
* Issue #13146: Writing a pyc file is now atomic under POSIX.Antoine Pitrou2011-10-171-3/+23
|
* Make importlib compatible with __import__ by "fixing" code.co_filenameBrett Cannon2011-03-231-0/+1
| | | | | | | | | | | | | | | | | | paths. __import__ does a little trick when importing from bytecode by back-patching the co_filename paths to point to the file location where the code object was loaded from, *not* where the code object was originally created. This allows co_filename to point to a valid path. Problem is that co_filename is immutable from Python, so a private function -- imp._fix_co_filename() -- had to be introduced in order to get things working properly. Originally the plan was to add a file argument to marshal.loads(), but that failed as the algorithm used by __import__ is not fully recursive as one might expect, so to be fully backwards-compatible the code used by __import__ needed to be exposed. This closes issue #6811 by taking a different approach than outlined in the issue.
* Have importlib use the repr of a module name in error messages.Brett Cannon2011-03-231-1/+1
| | | | | | | This makes it obvious that an import failed because of some extraneous whitespace (e.g., a newline). This is a partial fix for issue #8754.
* #11515: Merge with 3.2.Ezio Melotti2011-03-151-2/+2
|\
| * #11515: Merge with 3.1.Ezio Melotti2011-03-151-2/+2
| |\
| | * #11515: fix several typos. Patch by Piotr Kasprzyk.Ezio Melotti2011-03-151-1/+1
| | |
| | * Merged revisions 78242 via svnmerge fromBrett Cannon2010-02-191-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r78242 | brett.cannon | 2010-02-19 11:01:06 -0500 (Fri, 19 Feb 2010) | 5 lines Importlib was not matching import's handling of .pyc files where it had less then 8 bytes total in the file. Fixes issues 7361 & 7875. ........
| | * Merged revisions 76146 via svnmerge fromBrett Cannon2009-11-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r76146 | brett.cannon | 2009-11-07 15:55:05 -0800 (Sat, 07 Nov 2009) | 6 lines When trying to write new bytecode, importlib was not catching the IOError thrown if the file happened to be read-only to keep the failure silent. Fixes issue #7187. Thanks, Dave Malcolm for the report and analysis of the problem. ........
| | * Merged revisions 74584 via svnmerge fromBrett Cannon2009-08-301-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r74584 | brett.cannon | 2009-08-29 20:47:36 -0700 (Sat, 29 Aug 2009) | 3 lines Have importlib raise ImportError if None is found in sys.modules. This matches current import semantics. ........
* | | Skip test if zlib not present. Closes #11498. Patch by Natalia B. Bidart.Eric V. Smith2011-03-141-1/+1
| | |
* | | Typos.Eric V. Smith2011-03-141-2/+2
|/ /
* | Issue 10899: Remove function type annotations from the stdlibRaymond Hettinger2011-01-131-3/+3
| |
* | Issue 10899: Remove function type annotations from the stdlibRaymond Hettinger2011-01-131-2/+2
| |
* | Fix a minor inconsistency in capitalization for the 'No module named' exceptionBrett Cannon2010-11-181-3/+5
| | | | | | | | | | | | message in importlib. Thanks to Éric Araujo for spotting the inconsistency.
* | Remove redundant context manager.Florent Xicluna2010-09-031-15/+1
| |
* | OSError is the exception raised when one tries to create a directory thatBrett Cannon2010-08-261-2/+5
| | | | | | | | | | | | already exists, not IOError. Part of the continuing saga of issue #9572.
* | Fix a bug where an attribute was lacking an object to work off of.Brett Cannon2010-08-241-1/+1
| | | | | | | | | | Related to the fix for issue #9572. Thanks to Łukasz Czuja for catching the bug.
* | One of the joys of having test_multiprocessing occasionally execute afterBrett Cannon2010-08-221-18/+26
| | | | | | | | | | | | | | | | | | | | | | test_importlib is that it discovers special little race conditions. For instance, it turns out that importlib would throw an exception if two different Python processes both tried to create the __pycache__ directory as one process would succeed, causing the other process to fail as it didn't expect to get any "help". So now importlib simply stays calm and just accepts someone else did the work of creating the __pycache__ directory for it, moving on with life. Closes issue #9572.
* | Make importlib.abc.SourceLoader the primary mechanism for importlib.Brett Cannon2010-07-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This required moving the class from importlib/abc.py into importlib/_bootstrap.py and jiggering some code to work better with the class. This included changing how the file finder worked to better meet import semantics. This also led to fixing importlib to handle the empty string from sys.path as import currently does (and making me wish we didn't support that instead just required people to insert '.' instead to represent cwd). It also required making the new set_data abstractmethod create any needed subdirectories implicitly thanks to __pycache__ (it was either this or grow the SourceLoader ABC to gain an 'exists' method and either a mkdir method or have set_data with no data arg mean to create a directory). Lastly, as an optimization the file loaders cache the file path where the finder found something to use for loading (this is thanks to having a sourceless loader separate from the source loader to simplify the code and cut out stat calls). Unfortunately test_runpy assumed a loader would always work for a module, even if you changed from underneath it what it was expected to work with. By simply dropping the previous loader in test_runpy so the proper loader can be returned by the finder fixed the failure. At this point importlib deviates from import on two points: 1. The exception raised when trying to import a file is different (import does an explicit file check to print a special message, importlib just says the path cannot be imported as if it was just some module name). 2. the co_filename on a code object is not being set to where bytecode was actually loaded from instead of where the marshalled code object originally came from (a solution for this has already been agreed upon on python-dev but has not been implemented yet; issue8611).
* | Make importlib.abc.SourceLoader the primary mechanism for importlib.Brett Cannon2010-07-031-407/+182
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This required moving the class from importlib/abc.py into importlib/_bootstrap.py and jiggering some code to work better with the class. This included changing how the file finder worked to better meet import semantics. This also led to fixing importlib to handle the empty string from sys.path as import currently does (and making me wish we didn't support that instead just required people to insert '.' instead to represent cwd). It also required making the new set_data abstractmethod create any needed subdirectories implicitly thanks to __pycache__ (it was either this or grow the SourceLoader ABC to gain an 'exists' method and either a mkdir method or have set_data with no data arg mean to create a directory). Lastly, as an optimization the file loaders cache the file path where the finder found something to use for loading (this is thanks to having a sourceless loader separate from the source loader to simplify the code and cut out stat calls). Unfortunately test_runpy assumed a loader would always work for a module, even if you changed from underneath it what it was expected to work with. By simply dropping the previous loader in test_runpy so the proper loader can be returned by the finder fixed the failure. At this point importlib deviates from import on two points: 1. The exception raised when trying to import a file is different (import does an explicit file check to print a special message, importlib just says the path cannot be imported as if it was just some module name). 2. the co_filename on a code object is not being set to where bytecode was actually loaded from instead of where the marshalled code object originally came from (a solution for this has already been agreed upon on python-dev but has not been implemented yet; issue8611).
* | Move importlib.abc.SourceLoader to _bootstrap.Brett Cannon2010-06-281-0/+137
| | | | | | | | | | | | | | | | | | | | | | Required updating code relying on other modules to switch to _bootstrap's unique module requirements. This led to the realization that get_code was being too liberal in its exception catching when calling set_data by blindly grabbing IOError. Shifted the responsibility of safely ignoring writes to a read-only path to set_data. Importlib is still not relying on SourceLoader yet; requires creating a SourcelessLoader and updating the source finder.
* | Repair test failure. Bug 8727.Barry Warsaw2010-05-181-2/+10
| |
* | PEP 3147Barry Warsaw2010-04-171-1/+20
| |
* | Importlib was not matching import's handling of .pyc files where it had lessBrett Cannon2010-02-191-5/+10
| | | | | | | | | | | | then 8 bytes total in the file. Fixes issues 7361 & 7875.
* | no need to translate newlines in python code anymoreBenjamin Peterson2009-11-131-15/+0
| |
* | When trying to write new bytecode, importlib was not catching the IOErrorBrett Cannon2009-11-071-2/+2
| | | | | | | | | | | | | | thrown if the file happened to be read-only to keep the failure silent. Fixes issue #7187. Thanks, Dave Malcolm for the report and analysis of the problem.
* | Trying to import a submodule from another module and not a package was raisingBrett Cannon2009-08-301-1/+5
| | | | | | | | | | | | AttributeError in importlib when it should be an ImportError. Found when running importlib against test_runpy.
* | When the globals argument to importlib.__import__() contained any value forBrett Cannon2009-08-301-4/+4
| | | | | | | | | | | | | | | | __package__, it was used. This was incorrect since it could be set to None to represent the fact that a proper value was unknown. Now None will trigger the calculation for __package__. Discovered when running importlib against test_importhooks.
* | Raise TypeError if the name given to importlib.__import__() lacks an rpartitionBrett Cannon2009-08-301-0/+2
| | | | | | | | | | | | | | | | attribute. Was throwing AttributeError before. Discovered when running test_builtin against importlib. This exception change is specific to importlib.__import__() and does not apply to import_module() as it is being done for compatibility reasons only.
* | Allow importlib.__import__ to accept any iterable for fromlist. Discovered whenBrett Cannon2009-08-301-0/+1
| | | | | | | | running importlib against test___all__.
* | Have importlib raise ImportError if None is found in sys.modules. This matchesBrett Cannon2009-08-301-1/+6
| | | | | | | | current import semantics.
* | Implement the PEP 302 protocol for get_filename() asBrett Cannon2009-07-201-17/+21
|/ | | | | | importlib.abc.ExecutionLoader. PyLoader now inherits from this ABC instead of InspectLoader directly. Both PyLoader and PyPycLoader provide concrete implementations of get_filename in terms of source_path and bytecode_path.
* Rip out a useless method that the superclass implements properly.Brett Cannon2009-04-011-19/+0
|
* Fix importlib.machinery.PathFinder.find_module() to essentially skip over NoneBrett Cannon2009-03-301-3/+4
| | | | | | entries in sys.path_importer_cache. While this differs from semantics in how __import__ works, it prevents any implicit semantics from taking hold with users.
* Implement InspectLoader for FrozenImporter.Brett Cannon2009-03-151-2/+29
|
* Implement InspectLoader for BuiltinImporter.Brett Cannon2009-03-151-2/+29
|
* A few more docstring/API cleanups for importlib.Brett Cannon2009-03-151-12/+16
|
* Clean up docstring from importlib.util.module_for_loader.Brett Cannon2009-03-151-8/+8
|
* Finish properly hiding importlib implementation code.Brett Cannon2009-03-121-14/+9
|
* Last big re-organization of importlib._bootstrap. Should actually be able to ↵Brett Cannon2009-03-121-172/+173
| | | | find something in the file now.
* Do a little bit of reorganization on importlib._bootstrap.Brett Cannon2009-03-121-58/+69
|
* Make utility code in importlib._bootstrap private.Brett Cannon2009-03-121-32/+32
|
* Implement importlib.util.set_loader: a decorator to automatically setBrett Cannon2009-03-101-3/+15
| | | | __loader__ on modules.
* Implement get_source for importlib.abc.PyLoader using source_path and get_data.Brett Cannon2009-03-101-0/+20
|
* Introduce importlib.abc. The module contains various ABCs related to importsBrett Cannon2009-03-091-8/+2
| | | | | | | (mostly stuff specified by PEP 302). There are two ABCs, PyLoader and PyPycLoader, which help with implementing source and source/bytecode loaders by implementing load_module in terms of other methods. This removes a lot of gritty details loaders typically have to worry about.
* Fix importlib._bootstrap.PyPycLoader.load_module() to better handleBrett Cannon2009-03-091-3/+10
| | | | source/bytecode paths and what to do when they don't exist.
* Minor changes to Python source base loader.Brett Cannon2009-03-081-3/+7
| | | | | | | Fixed a bug where 'self' was left off a method call. Was masked by the fact the source/bytecode loader subclass is always used. Cleaned up when the source path is fetched. Also made sure ImportError is raised when a source path cannot be found.
* Rename importlib.util.set___package__ to set_package.Brett Cannon2009-03-041-4/+4
|
* Move importlib over to _io.Brett Cannon2009-03-041-5/+5
|