From bcc8a863f3c276fc884557309cfb737755494e19 Mon Sep 17 00:00:00 2001 From: kalgoritmi Date: Fri, 22 Sep 2023 12:53:12 +0300 Subject: [PATCH 1/4] Add support for cached_property decorator for python < 3.8 through backports --- detectron2/utils/events.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/detectron2/utils/events.py b/detectron2/utils/events.py index 7d582a9a16..d1c15dfaf0 100644 --- a/detectron2/utils/events.py +++ b/detectron2/utils/events.py @@ -6,11 +6,15 @@ import time from collections import defaultdict from contextlib import contextmanager -from functools import cached_property from typing import Optional import torch from fvcore.common.history_buffer import HistoryBuffer +try: + from functools import cached_property +except: + from backports.cached_property import cached_property + from detectron2.utils.file_io import PathManager __all__ = [ From 6e6200634cbc374cb04417ddb555c0674630dc83 Mon Sep 17 00:00:00 2001 From: kalgoritmi Date: Fri, 22 Sep 2023 13:29:37 +0300 Subject: [PATCH 2/4] Add backports package required for supporting detectron2 on python < 3.8 --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index b51307a625..c118b06795 100644 --- a/setup.py +++ b/setup.py @@ -190,6 +190,7 @@ def get_model_zoo_configs() -> List[str]: "hydra-core>=1.1", "black", "packaging", + "backports.cached-property==1.0.2; python_version < '3.8'", # NOTE: When adding new dependencies, if it is required at import time (in addition # to runtime), it probably needs to appear in docs/requirements.txt, or as a mock # in docs/conf.py From 25cfeb2adda8f854fd04ffaa886414c0a6eee068 Mon Sep 17 00:00:00 2001 From: kalgoritmi Date: Wed, 8 Jan 2025 22:31:53 +0200 Subject: [PATCH 3/4] Refactor to explicit check of the version --- detectron2/utils/events.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/detectron2/utils/events.py b/detectron2/utils/events.py index 3df3c33852..8a470c8ab2 100644 --- a/detectron2/utils/events.py +++ b/detectron2/utils/events.py @@ -3,6 +3,7 @@ import json import logging import os +import sys import time from collections import defaultdict from contextlib import contextmanager @@ -10,9 +11,9 @@ import torch from fvcore.common.history_buffer import HistoryBuffer -try: +if sys.version_info >= (3, 8): from functools import cached_property -except: +else: from backports.cached_property import cached_property from detectron2.utils.file_io import PathManager From bcc172532aa760985a34f772742ee440d571b3ca Mon Sep 17 00:00:00 2001 From: kalgoritmi Date: Wed, 8 Jan 2025 23:44:16 +0200 Subject: [PATCH 4/4] Add backport version of cached property for python below 3.8 --- docs/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/requirements.txt b/docs/requirements.txt index 720a1b1193..e6d5da0f85 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -21,3 +21,4 @@ omegaconf>=2.1.0.dev24 hydra-core>=1.1.0.dev5 scipy timm +backports.cached-property==1.0.2; python_version < '3.8'