MCPcopy Index your code
hub / github.com/modelscope/modelscope / requires

Function requires

modelscope/utils/import_utils.py:363–385  ·  view source on GitHub ↗
(obj, requirements)

Source from the content-addressed store, hash-verified

361
362
363def requires(obj, requirements):
364 if not isinstance(requirements, (list, tuple)):
365 requirements = [requirements]
366 if isinstance(obj, str):
367 name = obj
368 else:
369 name = obj.__name__ if hasattr(obj,
370 '__name__') else obj.__class__.__name__
371 checks = []
372 for req in requirements:
373 if req == '' or req in SYSTEM_PACKAGE:
374 continue
375 if req in REQUIREMENTS_MAAPING:
376 check = REQUIREMENTS_MAAPING[req]
377 else:
378 check_fn = is_package_available(req)
379 err_msg = GENERAL_IMPORT_ERROR.replace('REQ', req)
380 check = (check_fn, err_msg)
381 checks.append(check)
382
383 failed = [msg.format(name) for available, msg in checks if not available()]
384 if failed:
385 raise ImportError(''.join(failed))
386
387
388def torch_required(func):

Callers 2

_get_moduleMethod · 0.85
import_moduleMethod · 0.85

Calls 3

is_package_availableFunction · 0.85
replaceMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…