Skip to content

Commit 06a9ab4

Browse files
authored
fs.get_missing_deps: use find_spec to check if packages are missing instead of importing them (#191)
fs.get_missing_deps: use importlib.util.find_spec to check if packages are missing instead of importing from them This speeds up `dvc version` from >1s to ~0.35s in my machine.
1 parent 445ba16 commit 06a9ab4

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/dvc_objects/fs/base.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,9 @@ def _prepare_credentials(
134134

135135
@classmethod
136136
def get_missing_deps(cls) -> List[str]:
137-
import importlib
137+
from importlib.util import find_spec
138138

139-
missing: List[str] = []
140-
for package, module in cls.REQUIRES.items():
141-
try:
142-
importlib.import_module(module)
143-
except ImportError:
144-
missing.append(package)
145-
146-
return missing
139+
return [pkg for pkg, mod in cls.REQUIRES.items() if not find_spec(mod)]
147140

148141
def _check_requires(self, **kwargs):
149142
from .scheme import Schemes

0 commit comments

Comments
 (0)