summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib
Commit message (Collapse)AuthorAgeFilesLines
* bpo-46125: Refactor tests to test traversable API directly. Includes changes ↵Jason R. Coombs2021-12-196-189/+129
| | | | from importlib_resources 5.4.0. (GH-30189)
* bpo-44893: Implement EntryPoint as simple class with attributes. (GH-30150)Jason R. Coombs2021-12-165-42/+90
| | | | | * bpo-44893: Implement EntryPoint as simple class and deprecate tuple access in favor of attribute access. Syncs with importlib_metadata 4.8.1. * Apply refactorings found in importlib_metadata 4.8.2.
* bpo-46105: Honor spec when generating requirement specs with urls and ↵Jason R. Coombs2021-12-161-0/+2
| | | | extras. (GH-30151)
* bpo-45514: Deprecate importlib resources legacy functions. (GH-29036)Jason R. Coombs2021-11-246-81/+144
| | | | | | | | | | | * bpo-45514: Apply changes from importlib_resources@a3ef4128c6 * Mark legacy functions as deprecated in the docs and link to the migration docs in importlib_resources docs. * Apply changes from importlib_resources@329ae9d5f2c. * Indicate importlib.resources as a module. Co-authored-by: Filipe Laíns <lains@riseup.net>
* bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_ca… ↵Miro Hrončok2021-11-231-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-29384) Consider the following directory structure: . └── PATH1 └── namespace └── sub1 └── __init__.py And both PATH1 and PATH2 in sys path: $ PYTHONPATH=PATH1:PATH2 python3.11 >>> import namespace >>> import namespace.sub1 >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace']) >>> ... While this interpreter still runs, PATH2/namespace/sub2 is created: . ├── PATH1 │ └── namespace │ └── sub1 │ └── __init__.py └── PATH2 └── namespace └── sub2 └── __init__.py The newly created module cannot be imported: >>> ... >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace']) >>> import namespace.sub2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'namespace.sub2' Calling importlib.invalidate_caches() now newly allows to import it: >>> import importlib >>> importlib.invalidate_caches() >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace']) >>> import namespace.sub2 >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace', '.../PATH2/namespace']) This was not previously possible.
* bpo-35673: Add a public alias for namespace package __loader__ attribute ↵Barry Warsaw2021-10-201-0/+7
| | | | | | | | (#29049) Rename namespace package __loader__ class to be public. Make the old name, i.e. _NamespaceLoader, an alias for the public name, for backward compatibility.
* bpo-21736: Set __file__ on frozen stdlib modules. (gh-28656)Eric Snow2021-10-142-25/+36
| | | | | | | | | | | | | | | | | | | | | | | | Currently frozen modules do not have __file__ set. In their spec, origin is set to "frozen" and they are marked as not having a location. (Similarly, for frozen packages __path__ is set to an empty list.) However, for frozen stdlib modules we are able to extrapolate __file__ as long as we can determine the stdlib directory at runtime. (We now do so since gh-28586.) Having __file__ set is helpful for a number of reasons. Likewise, having a non-empty __path__ means we can import submodules of a frozen package from the filesystem (e.g. we could partially freeze the encodings module). This change sets __file__ (and adds to __path__) for frozen stdlib modules. It uses sys._stdlibdir (from gh-28586) and the frozen module alias information (from gh-28655). All that work is done in FrozenImporter (in Lib/importlib/_bootstrap.py). Also, if a frozen module is imported before importlib is bootstrapped (during interpreter initialization) then we fix up that module and its spec during the importlib bootstrapping step (i.e. imporlib._bootstrap._setup()) to match what gets set by FrozenImporter, including setting the file info (if the stdlib dir is known). To facilitate this, modules imported using PyImport_ImportFrozenModule() have __origname__ set using the frozen module alias info. __origname__ is popped off during importlib bootstrap. (To be clear, even with this change the new code to set __file__ during fixups in imporlib._bootstrap._setup() doesn't actually get triggered yet. This is because sys._stdlibdir hasn't been set yet in interpreter initialization at the point importlib is bootstrapped. However, we do fix up such modules at that point to otherwise match the result of importing through FrozenImporter, just not the __file__ and __path__ parts. Doing so will require changes in the order in which things happen during interpreter initialization. That can be addressed separately. Once it is, the file-related fixup code from this PR will kick in.) Here are things this change does not do: * set __file__ for non-stdlib modules (no way of knowing the parent dir) * set __file__ if the stdlib dir is not known (nor assume the expense of finding it) * relatedly, set __file__ if the stdlib is in a zip file * verify that the filename set to __file__ actually exists (too expensive) * update __path__ for frozen packages that alias a non-package (since there is no package dir) Other things this change skips, but we may do later: * set __file__ on modules imported using PyImport_ImportFrozenModule() * set co_filename when we unmarshal the frozen code object while importing the module (e.g. in FrozenImporter.exec_module()) -- this would allow tracebacks to show source lines * implement FrozenImporter.get_filename() and FrozenImporter.get_source() https://bugs.python.org/issue21736
* bpo-45020: Identify which frozen modules are actually aliases. (gh-28655)Eric Snow2021-10-052-18/+48
| | | | | | | In the list of generated frozen modules at the top of Tools/scripts/freeze_modules.py, you will find that some of the modules have a different name than the module (or .py file) that is actually frozen. Let's call each case an "alias". Aliases do not come into play until we get to the (generated) list of modules in Python/frozen.c. (The tool for freezing modules, Programs/_freeze_module, is only concerned with the source file, not the module it will be used for.) Knowledge of which frozen modules are aliases (and the identity of the original module) normally isn't important. However, this information is valuable when we go to set __file__ on frozen stdlib modules. This change updates Tools/scripts/freeze_modules.py to map aliases to the original module name (or None if not a stdlib module) in Python/frozen.c. We also add a helper function in Python/import.c to look up a frozen module's alias and add the result of that function to the frozen info returned from find_frozen(). https://bugs.python.org/issue45020
* Rearrage the finder tests. (gh-28740)Eric Snow2021-10-051-30/+56
| | | | | This makes the tests a bit cleaner and makes adding more tests a little simpler. https://bugs.python.org/issue45324
* bpo-45324: Capture data in FrozenImporter.find_spec() to use in ↵Eric Snow2021-10-052-23/+60
| | | | | | | | | | | exec_module(). (gh-28633) Before this change we end up duplicating effort and throwing away data in FrozenImporter.find_spec(). Now we do the work once in find_spec() and the only thing we do in FrozenImporter.exec_module() is turn the raw frozen data into a code object and then exec it. We've added _imp.find_frozen(), add an arg to _imp.get_frozen_object(), and updated FrozenImporter. We've also moved some code around to reduce duplication, get a little more consistency in outcomes, and be more efficient. Note that this change is mostly necessary if we want to set __file__ on frozen stdlib modules. (See https://bugs.python.org/issue21736.) https://bugs.python.org/issue45324
* bpo-45020: Add more test cases for frozen modules. (gh-28664)Eric Snow2021-10-011-13/+66
| | | | | I've added a number of test-only modules. Some of those cases are covered by the recently frozen stdlib modules (and some will be once we add encodings back in). However, I figured we'd play it safe by having a set of modules guaranteed to be there during tests. https://bugs.python.org/issue45020
* [codemod] Fix non-matching bracket pairs (GH-28473)Mohamad Mansour2021-09-211-1/+1
| | | | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-45229: Remove test_main in many tests (GH-28405)Serhiy Storchaka2021-09-192-19/+12
| | | | | | | | | Instead of explicitly enumerate test classes for run_unittest() use the unittest ability to discover tests. This also makes these tests discoverable and runnable with unittest. load_tests() can be used for dynamic generating tests and adding doctests. setUpModule(), tearDownModule() and addModuleCleanup() can be used for running code before and after all module tests.
* bpo-45019: Clean up the frozen __hello__ module. (gh-28374)Eric Snow2021-09-151-14/+21
| | | | | Here's one more small cleanup that should have been in PR gh-28319. We eliminate stdout side-effects from importing the frozen __hello__ module, and update tests accordingly. We also move the module's source file into Lib/ from Toos/freeze/flag.py. https://bugs.python.org/issue45019
* bpo-45020: Add -X frozen_modules=[on|off] to explicitly control use of ↵Eric Snow2021-09-142-96/+123
| | | | | | | frozen modules. (gh-28320) Currently we freeze several modules into the runtime. For each of these modules it is essential to bootstrapping the runtime that they be frozen. Any other stdlib module that we later freeze into the runtime is not essential. We can just as well import from the .py file. This PR lets users explicitly choose which should be used, with the new "-X frozen_modules=[on|off]" CLI flag. The default is "off" for now. https://bugs.python.org/issue45020
* bpo-44784: Apply changes from importlib_metadata 4.6.3 (GH-27508)Jason R. Coombs2021-07-311-6/+12
| | | | | Addressing issues with tests under error on warnings. Automerge-Triggered-By: GH:jaraco
* bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436)Jason R. Coombs2021-07-3010-187/+363
| | | | | | | * bpo-44771: Apply changes from importlib_resources@3b24bd6307 * Add blurb * Exclude namespacedata01 from eol conversion.
* bpo-44451: Reset DeprecationWarning filters in ↵Miro Hrončok2021-06-181-0/+1
| | | | | | | | | | | | | | | | | test_importlib.test_entry_points_by_index (GH-26784) This avoids the following error if DeprecationWarnings are ignored. ====================================================================== ERROR: test_entry_points_by_index (test.test_importlib.test_metadata_api.APITests) Prior versions of Distribution.entry_points would return a ---------------------------------------------------------------------- Traceback (most recent call last): File "/builddir/build/BUILD/Python-3.10.0b3/Lib/test/test_importlib/test_metadata_api.py", line 145, in test_entry_points_by_index expected = next(iter(caught)) StopIteration ---------------------------------------------------------------------- Ran 1402 tests in 2.125s FAILED (errors=1, skipped=18, expected failures=1)
* bpo-44246: Restore compatibility in entry_points (GH-26468)Jason R. Coombs2021-05-311-0/+16
| | | | | | | * bpo-44246: Entry points performance improvements. From importlib_metadata 4.3.1. * bpo-44246: Sync with importlib_metadata 4.4
* bpo-44246: Entry points performance improvements. (GH-26467)Jason R. Coombs2021-05-311-0/+4
| | | From importlib_metadata 4.3.1.
* bpo-38693: Prefer f-strings in importlib.resources (importlib_resources ↵Jason R. Coombs2021-05-262-3/+3
| | | | | 5.0.6). (GH-26387) Automerge-Triggered-By: GH:jaraco
* bpo-43643: Sync with python/importlib_resources@c17a610aad. (GH-26284)Jason R. Coombs2021-05-211-0/+6
| | | | * bpo-43643: Sync with python/importlib_resources@c17a610aad. * Sync with python/importlib_resources@89fd5e961a.
* bpo-43926: Cleaner metadata with PEP 566 JSON support. (GH-25565)Jason R. Coombs2021-05-023-3/+37
| | | | | | | | | * bpo-43926: Cleaner metadata with PEP 566 JSON support. * Add blurb * Add versionchanged and versionadded declarations for changes to metadata. * Use descriptor for PEP 566
* bpo-43864: Silence deprecation warning in test_importlib.test_module_found ↵Shreyan Avigyan2021-04-271-2/+6
| | | | and test_importlib.test_module_not_found (GH-25656)
* bpo-43780: Sync with importlib_metadata 3.10 (GH-25297)Jason R. Coombs2021-04-242-0/+14
| | | | | | | * bpo-43780: Sync with importlib_metadata 3.10. * Add blurb * Apply changes from importlib_metadata 3.10.1.
* Silence find_module() DeprecationWarning on Windows tests (GH-25563)Brett Cannon2021-04-231-1/+4
|
* bpo-43105: Importlib now resolves relative paths when creating module spec ↵Steve Dower2021-04-072-4/+60
| | | | objects from file locations (GH-25121)
* bpo-42135: Deprecate implementations of find_module() and find_loader() ↵Brett Cannon2021-04-069-27/+44
| | | | (GH-25169)
* bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25181)Inada Naoki2021-04-058-15/+15
| | | | | | * Fix test_shutil * Fix test_imp * Fix test_import * Fix test_importlib
* bpo-43672: raise ImportWarning when calling find_loader() (GH-25119)Brett Cannon2021-04-028-92/+70
|
* bpo-42134: Raise ImportWarning when calling find_module() in the import ↵Brett Cannon2021-03-302-4/+14
| | | | system (GH-25044)
* bpo-42136: Deprecate module_repr() as found in importlib (GH-25022)Brett Cannon2021-03-263-6/+29
|
* bpo-42137: have ModuleType.__repr__ prefer __spec__ over module_repr() ↵Brett Cannon2021-03-242-9/+2
| | | | | (GH-24953) This is to work towards the removal of the use of module_repr() in Python 3.12 (documented as deprecated since 3.4).
* bpo-43517: Fix false positive in detection of circular imports (#24895)Antoine Pitrou2021-03-203-1/+78
|
* bpo-43428: Sync with importlib_metadata 3.7. (GH-24782)Jason R. Coombs2021-03-134-13/+88
| | | | | | | * bpo-43428: Sync with importlib_metadata 3.7.2 (67234b6) * Add blurb * Reformat blurb to create separate paragraphs for each change included.
* bpo-42129: Add support for resources in namespaces (GH-24670)Jason R. Coombs2021-03-0413-102/+304
| | | | | * Unify behavior in ResourceReaderDefaultsTests and align with the behavior found in importlib_resources. * Equip NamespaceLoader with a NamespaceReader. * Apply changes from importlib_resources 5.0.4
* Fix failed merge of bpo-43288. (GH-24614)Neil Schemenauer2021-02-211-2/+3
|
* bpo-43288: Fix bug in test_importlib test. (GH-24612)Neil Schemenauer2021-02-211-0/+4
|
* bpo-42382: In importlib.metadata, `EntryPoint` objects now expose `dist` ↵Jason R. Coombs2020-12-314-80/+158
| | | | | | | | | | | | | | (#23758) * bpo-42382: In importlib.metadata, `EntryPoint` objects now expose a `.dist` object referencing the `Distribution` when constructed from a `Distribution`. Also, sync importlib_metadata 3.3: - Add support for package discovery under package normalization rules. - The object returned by `metadata()` now has a formally-defined protocol called `PackageMetadata` with declared support for the `.get_all()` method. * Add blurb * Remove latent footnote.
* bpo-26131: Deprecate usage of load_module() (GH-23469)Brett Cannon2020-12-0412-143/+254
| | | Raise an ImportWarning when the import system falls back on load_module(). As for implementations of load_module(), raise a DeprecationWarning.
* bpo-41490: ``path`` and ``contents`` to aggressively close handles (#22915)Jason R. Coombs2020-10-253-0/+79
| | | | | | | | | * bpo-41490: ``path`` method to aggressively close handles * Add blurb * In ZipReader.contents, eagerly evaluate the contents to release references to the zipfile. * Instead use _ensure_sequence to ensure any iterable from a reader is eagerly converted to a list if it's not already a sequence.
* bpo-42089: Sync with current cpython branch of importlib_metadata (GH-22775)Barry Warsaw2020-10-192-6/+15
| | | | | ~~The only differences are in the test files.~~ Automerge-Triggered-By: @jaraco
* bpo-40275: Fix failed test cases by using test helpers (GH-21811)Hai Shi2020-08-102-6/+6
|
* bpo-40275: Use new test.support helper submodules in tests (GH-21727)Hai Shi2020-08-0411-26/+32
|
* bpo-40275: Use new test.support helper submodules in tests (GH-21314)Hai Shi2020-07-061-2/+3
|
* bpo-40924: Ensure importlib.resources.path returns an extant path (GH-20857)Jason R. Coombs2020-06-291-0/+9
|
* bpo-41006: importlib.util no longer imports typing (GH-20938)Victor Stinner2020-06-171-2/+2
| | | | Create importlib._abc submodule to avoid importing typing when importlib.util is imported. Move Loader ABC into importlib._abc.
* bpo-39791: Support file systems that cannot support non-ascii filenames ↵Jason R. Coombs2020-06-072-2/+18
| | | | (skipping tests in that case). (#20681)
* bpo-39791: Refresh importlib.metadata from importlib_metadata 1.6.1. (GH-20659)Jason R. Coombs2020-06-053-10/+47
| | | | | | | * Refresh importlib.metadata from importlib_metadata 1.6.1. * 📜🤖 Added by blurb_it. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* bpo-40275: Adding threading_helper submodule in test.support (GH-20263)Hai Shi2020-05-272-7/+9
|