Skip to content

Conversation

@JanuszL
Copy link
Contributor

@JanuszL JanuszL commented Dec 22, 2025

  • Handles pkg_resources deprecation/removal by providing a compatibility
    shim that uses importlib.metadata when pkg_resources is not available
    for nose tests

Category:

Other (e.g. Documentation, Tests, Configuration)

Description:

  • Handles pkg_resources deprecation/removal by providing a compatibility
    shim that uses importlib.metadata when pkg_resources is not available
    for nose tests

Additional information:

Affected modules and functionalities:

  • nose_utils

Key points relevant for the review:

  • NA

Tests:

  • Existing tests apply
    • TL0_plugin_manager for Python 3.13 in conda
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

@greptile-apps
Copy link

greptile-apps bot commented Dec 22, 2025

Greptile Summary

This PR adds a compatibility shim to handle the deprecation and removal of pkg_resources in Python 3.13+. The implementation provides a fallback using importlib.metadata when pkg_resources is not available.

Key changes:

  • Attempts to import pkg_resources first to maintain backward compatibility
  • Falls back to importlib.metadata if pkg_resources is unavailable
  • Creates a minimal pkg_resources module stub with iter_entry_points() function
  • The shim uses metadata.entry_points().select(group=group) and filters by name if specified
  • Follows the same pattern already established in the file for handling deprecated modules (like the imp module shim for Python 3.12+)

Implementation correctness:

  • The iter_entry_points() implementation correctly mimics the pkg_resources API
  • Uses metadata.entry_points().select(group=group) which returns an iterable EntryPoints object
  • Filters by name using list comprehension when name parameter is provided
  • Return types are appropriate: EntryPoints object (iterable) when no name filter, list when name filter is applied
  • The shim is only installed when pkg_resources import fails, ensuring native behavior is preserved when available

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a straightforward compatibility shim following established patterns in the codebase
  • The implementation is well-designed and follows the existing pattern in the file for handling deprecated modules. It uses try-except to maintain backward compatibility, only activating the shim when needed. The iter_entry_points() implementation correctly uses importlib.metadata APIs and properly handles both use cases (with and without name filtering). The change is isolated to test utilities and has been tested with Python 3.13 conda builds.
  • No files require special attention

Important Files Changed

Filename Overview
dali/test/python/nose_utils.py Adds compatibility shim for pkg_resources deprecation using importlib.metadata - handles Python 3.13+ where pkg_resources may not be available

Sequence Diagram

sequenceDiagram
    participant Test as Test Runner
    participant NU as nose_utils.py
    participant PR as pkg_resources
    participant IM as importlib.metadata
    participant Nose as nose library

    Test->>NU: import nose_utils
    NU->>NU: Check Python version >= 3.12
    alt Python >= 3.12
        NU->>NU: Create imp module shim
    end
    
    NU->>PR: try: import pkg_resources
    alt pkg_resources available
        PR-->>NU: Import successful
        Note over NU: Use native pkg_resources
    else pkg_resources not available
        PR-->>NU: ImportError
        NU->>IM: from importlib import metadata
        NU->>NU: Create iter_entry_points(group, name)
        Note over NU: Compatibility shim created
        NU->>NU: Create pkg_resources module stub
        NU->>NU: sys.modules["pkg_resources"] = stub
    end
    
    NU->>Nose: import nose modules
    Nose->>PR: pkg_resources.iter_entry_points(...)
    
    alt Using shim
        PR->>IM: metadata.entry_points()
        IM-->>PR: EntryPoints object
        PR->>PR: eps.select(group=group)
        alt name is not None
            PR->>PR: Filter by name
        end
        PR-->>Nose: Return filtered results
    else Using native pkg_resources
        PR-->>Nose: Return entry points
    end
    
    Nose-->>Test: Nose configured with plugins
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  1. dali/test/python/nose_utils.py, line 108-115 (link)

    style: The fallback to .get() on line 115 is redundant since Python 3.10+ always has the .select() method on entry_points(). Simplify to:

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

- Handles pkg_resources deprecation/removal by providing a compatibility
  shim that uses importlib.metadata when pkg_resources is not available
  for nose tests

Signed-off-by: Janusz Lisiecki <[email protected]>
@JanuszL JanuszL force-pushed the fix_deprecation_package_manager branch from a2ba496 to 8a1de32 Compare December 22, 2025 12:03
@greptile-apps
Copy link

greptile-apps bot commented Dec 22, 2025

Greptile's behavior is changing!

From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [40620351]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [40620351]: BUILD PASSED

@klecki
Copy link
Contributor

klecki commented Dec 22, 2025

How about #6146

@JanuszL
Copy link
Contributor Author

JanuszL commented Dec 22, 2025

How about #6146

If it works let us use #6146.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants