Skip to content

Conversation

@dmbrmv
Copy link

@dmbrmv dmbrmv commented Oct 30, 2025

Summary

Replaces deprecated pkg_resources with importlib.metadata for version retrieval in the Python package.

Problem

Users experience deprecation warnings when importing richdem with setuptools ≥81:

  • pkg_resources is deprecated and scheduled for removal (2025-11-30)
  • Warning appears on every import, cluttering logs

Changes

  • Replaced pkg_resources.require("richdem")[0].version with importlib.metadata.version("richdem")
  • Added proper error handling with PackageNotFoundError fallback
  • Maintains backward compatibility

References

- Replace pkg_resources with importlib.metadata for version retrieval
- Add proper error handling with PackageNotFoundError fallback
- Fixes deprecation warning on setuptools >=81
- Compatible with Python 3.8+ (stdlib solution)
- pkg_resources scheduled for removal (2025-11-30)

This change modernizes the package version detection mechanism
while maintaining backward compatibility. The importlib.metadata
module is part of the standard library since Python 3.8 and is
the recommended replacement for pkg_resources.
Copilot AI review requested due to automatic review settings October 30, 2025 09:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modernizes the package version retrieval by replacing the deprecated pkg_resources API with the standard library's importlib.metadata module, which is the recommended approach for Python 3.8+.

  • Replaced pkg_resources.require() with importlib.metadata.version()
  • Added exception handling for cases where the package metadata is not found

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

1 participant