Skip to content

Commit

Permalink
Add proper version check
Browse files Browse the repository at this point in the history
  • Loading branch information
guarin committed Jan 25, 2024
1 parent 994d65e commit 0b0b264
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lightly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@


import os
import packaging.version
from packaging.version import Version as _Version
from packaging.version import InvalidVersion
from typing import Optional

# see if torchvision vision transformer is available
try:
Expand All @@ -97,10 +101,13 @@
import timm
except ImportError:
_timm_available = False
_timm_version = ""
_timm_version: Optional[_Version] = None
else:
_timm_available = True
_timm_version = timm.__version__
try:
_timm_version = packaging.version.parse(timm.__version__)
except InvalidVersion:
_timm_version = None

Check warning on line 110 in lightly/__init__.py

View check run for this annotation

Codecov / codecov/patch

lightly/__init__.py#L107-L110

Added lines #L107 - L110 were not covered by tests


if os.getenv("LIGHTLY_DID_VERSION_CHECK", "False") == "False":
Expand Down
3 changes: 2 additions & 1 deletion lightly/models/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
SwaVPrototypes,
)
from lightly.models.modules.nn_memory_bank import NNMemoryBankModule
from packaging.version import Version as _Version

if _torchvision_vit_available:
# Requires torchvision >=0.12
Expand All @@ -35,7 +36,7 @@
MAEDecoder,
MAEEncoder,
)
if _timm_available and _timm_version >= "0.9.9":
if _timm_available and _timm_version is not None and _timm_version >= _Version("0.9.9"):
# Requires timm >= 0.9.9
from lightly.models.modules.heads_timm import AIMPredictionHead
from lightly.models.modules.masked_causal_vision_transformer import (
Expand Down
3 changes: 2 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ six>=1.10
tqdm>=4.44
urllib3 >= 1.25.3
pydantic >= 1.10.5, < 2
aenum >= 3.1.11
aenum >= 3.1.11
packaging
1 change: 1 addition & 0 deletions requirements/minimal_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pytorch_lightning==1.7.1
torch==1.11.0
torchvision==0.12.0
pillow==7.1.2
packaging

tox
sphinx
Expand Down

0 comments on commit 0b0b264

Please sign in to comment.