py.py


Overview

`py.py` serves as a compatibility shim for the `pylib` package, which is being deprecated or removed. Its main purpose is to provide seamless backward compatibility for projects or modules that depend on `py.error` and `py.path` submodules.

If `pylib` is installed and available with higher priority, this shim file will be bypassed in favor of the actual `py` package implementation (typically located at `py/__init__.py`). When the shim is active, it redirects import requests for `py.error` and `py.path` to corresponding internal `_pytest._py` modules, ensuring that existing code relying on these modules continues to function without modification.

This approach allows a smooth transition away from `pylib` while maintaining compatibility and avoiding import errors in legacy codebases or during migration.


Detailed Explanation

Module-Level Behavior


Usage Examples

This file itself is not intended to be directly imported by developers. Instead, it transparently hooks into the import mechanism.

For example, with this shim in place, the following code:

import py.error
import py.path

try:
    raise py.error.Exception("Error occurred")
except py.error.Exception as e:
    print("Caught py error:", e)

p = py.path.local("/tmp")
print("Local path:", p)

will work correctly by using the `_pytest._py.error` and `_pytest._py.path` implementations, even if the original `pylib` is not installed.


Important Implementation Details


Interaction with the System


Mermaid Diagram: Module Structure

flowchart TD
    A[py.py (shim)] --> B[_pytest._py.error]
    A --> C[_pytest._py.path]

    subgraph sys.modules
        direction LR
        D["py.error"] -->|redirects to| B
        E["py.path"] -->|redirects to| C
    end

Summary

This design ensures minimal disruption and a clean path forward as the `pylib` package is phased out.