Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change importlib to first try to import modules using the standard mechanism #11997

Merged
merged 13 commits into from
Mar 3, 2024

Commits on Mar 2, 2024

  1. testing/test_pathlib: remove test_issue131_on__init__

    The test seems wrong, and we haven't been able to figure out what it's
    trying to test (the original issue is lost in time).
    nicoddemus committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    887e251 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    300ceb4 View commit details
    Browse the repository at this point in the history
  3. testing/test_pathlib: add an importlib test

    Ensure the implementation isn't changed to trigger such a bug.
    nicoddemus committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    dcf01fd View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    7524e60 View commit details
    Browse the repository at this point in the history
  5. pathlib: extract a function _import_module_using_spec

    Will be reused.
    nicoddemus committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    4dea183 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    5867426 View commit details
    Browse the repository at this point in the history
  7. pathlib: consider namespace packages in `resolve_pkg_root_and_module_…

    …name`
    
    This applies to `append` and `prepend` import modes; support for
    `importlib` mode will be added in a separate change.
    nicoddemus committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    067daf9 View commit details
    Browse the repository at this point in the history
  8. Change importlib to first try to import modules using the standard me…

    …chanism
    
    As detailed in
    pytest-dev#11475 (comment),
    currently with `--import-mode=importlib` pytest will try to import every
    file by using a unique module name, regardless if that module could be
    imported using the normal import mechanism without touching `sys.path`.
    
    This has the consequence that non-test modules available in `sys.path`
    (via other mechanism, such as being installed into a virtualenv,
    PYTHONPATH, etc) would end up being imported as standalone modules,
    instead of imported with their expected module names.
    
    To illustrate:
    
    ```
    .env/
      lib/
        site-packages/
          anndata/
            core.py
    ```
    
    Given `anndata` is installed into the virtual environment, `python -c
    "import anndata.core"` works, but pytest with `importlib` mode would
    import that module as a standalone module named
    `".env.lib.site-packages.anndata.core"`, because importlib module was
    designed to import test files which are not reachable from `sys.path`,
    but now it is clear that normal modules should be imported using the
    standard mechanisms if possible.
    
    Now `imporlib` mode will first try to import the module normally,
    without changing `sys.path`, and if that fails it falls back to
    importing the module as a standalone module.
    
    This also makes `importlib` respect namespace packages.
    
    This supersedes pytest-dev#11931.
    
    Fix pytest-dev#11475
    Close pytest-dev#11931
    nicoddemus committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    c85fce3 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    5746b8e View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    199d4e2 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    111c0d9 View commit details
    Browse the repository at this point in the history
  12. testing/test_pathlib: parametrize namespace package option

    Test with namespace packages support even when it will not find namespace packages to ensure it will at least not give weird results or crashes.
    nicoddemus committed Mar 2, 2024
    Configuration menu
    Copy the full SHA
    aac720a View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    d6134bc View commit details
    Browse the repository at this point in the history