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

Avoid entry_points deprecation warning #14052

Merged
merged 9 commits into from
Aug 10, 2022
3 changes: 3 additions & 0 deletions src/pytorch_lightning/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed the `NeptuneLogger` dependency being unrecognized ([#13988](https://github.com/Lightning-AI/lightning/pull/13988))


- Avoid `metadata.entry_points` depreaction warning on Python 3.10 ([#14052](https://github.com/Lightning-AI/lightning/pull/14052))
carmocca marked this conversation as resolved.
Show resolved Hide resolved


- Fixed an issue where users would be warned about unset `max_epochs` even when `fast_dev_run` was set ([#13262](https://github.com/Lightning-AI/lightning/pull/13262))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from pytorch_lightning.callbacks.rich_model_summary import RichModelSummary
from pytorch_lightning.callbacks.timer import Timer
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from pytorch_lightning.utilities.imports import _PYTHON_GREATER_EQUAL_3_8_0
from pytorch_lightning.utilities.imports import _PYTHON_GREATER_EQUAL_3_8_0, _PYTHON_GREATER_EQUAL_3_10_0
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation, rank_zero_info

_log = logging.getLogger(__name__)
Expand Down Expand Up @@ -256,14 +256,16 @@ def _configure_external_callbacks() -> List[Callback]:
Return:
A list of all callbacks collected from external factories.
"""
group = "pytorch_lightning.callbacks_factory"

if _PYTHON_GREATER_EQUAL_3_8_0:
from importlib.metadata import entry_points

factories = entry_points().get("pytorch_lightning.callbacks_factory", ())
factories = entry_points(group=group) if _PYTHON_GREATER_EQUAL_3_10_0 else entry_points().get(group, ())
else:
from pkg_resources import iter_entry_points

factories = iter_entry_points("pytorch_lightning.callbacks_factory")
factories = iter_entry_points(group)

external_callbacks = []
for factory in factories:
Expand Down
1 change: 1 addition & 0 deletions src/pytorch_lightning/utilities/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __repr__(self) -> str:
_IS_WINDOWS = platform.system() == "Windows"
_IS_INTERACTIVE = hasattr(sys, "ps1") # https://stackoverflow.com/a/64523765
_PYTHON_GREATER_EQUAL_3_8_0 = (sys.version_info.major, sys.version_info.minor) >= (3, 8)
_PYTHON_GREATER_EQUAL_3_10_0 = (sys.version_info.major, sys.version_info.minor) >= (3, 10)
_TORCH_GREATER_EQUAL_1_9_1 = _compare_version("torch", operator.ge, "1.9.1")
_TORCH_GREATER_EQUAL_1_10 = _compare_version("torch", operator.ge, "1.10.0")
_TORCH_LESSER_EQUAL_1_10_2 = _compare_version("torch", operator.le, "1.10.2")
Expand Down