lmcinnes / umap

Uniform Manifold Approximation and Projection
BSD 3-Clause "New" or "Revised" License
7.46k stars 809 forks source link

Enhance Compatibility for Python Versions Below 3.8 #1135

Open TNTksals opened 5 months ago

TNTksals commented 5 months ago

Hi, I've popped in a pull request to propose a small yet significant enhancement to the [umap package/project]. This enhancement aims to improve the package's compatibility with Python versions below 3.8, ensuring a broader user base can benefit from its powerful features without facing import errors.

Currently, the package utilizes importlib.metadata for importing version and PackageNotFoundError, which is available in Python 3.8 and newer versions. However, this leads to compatibility issues with older Python versions, as they lack this module, potentially alienating a segment of the user base still on these versions.

To address this issue, I have implemented a conditional import strategy in the __init__.py file. The code attempts to import version and PackageNotFoundError from importlib.metadata (available in Python 3.8+). If this import fails (indicating the user is on an older Python version), it falls back to importing the same modules from the importlib_metadata package, which is a backport of importlib.metadata for older Python versions.