medcat.utils.import_utils

Attributes

_DEP_PATTERN

_DEP_NAME_MAPPER

Exceptions

IncorrectExtraComponent

Common base class for all non-exit exceptions.

MissingDependenciesError

Custom exception for missing optional dependencies.

Classes

KeyDefaultDict

dict() -> new empty dictionary

Functions

get_all_extra_deps_raw(package_name)

Get all the dependencies for a pcakge that are for an extra component.

get_required_extra_deps(package_name, extra_name)

Get the extra dependencies required for this extra part.

get_installed_extra_dependencies(package_name, extra_name)

Get installed dependencies for a given package's extra parts.

ensure_optional_extras_installed(package_name, extra_name)

Ensure that an optional dependency set is installed.

Module Contents

medcat.utils.import_utils._DEP_PATTERN
class medcat.utils.import_utils.KeyDefaultDict

Bases: dict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

__missing__(key)
__contains__()

True if the dictionary has the specified key, else False.

__delattr__()

Implement delattr(self, name).

__delitem__()

Delete self[key].

__dir__()

Default dir() implementation.

__eq__()

Return self==value.

__format__()

Default object formatter.

__ge__()

Return self>=value.

__getattribute__()

Return getattr(self, name).

__getitem__()

x.__getitem__(y) <==> x[y]

__gt__()

Return self>value.

__init__()

Initialize self. See help(type(self)) for accurate signature.

__ior__()

Return self|=value.

__iter__()

Implement iter(self).

__le__()

Return self<=value.

__len__()

Return len(self).

__lt__()

Return self<value.

__ne__()

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__or__()

Return self|value.

__reduce__()

Helper for pickle.

__reduce_ex__()

Helper for pickle.

__repr__()

Return repr(self).

__reversed__()

Return a reverse iterator over the dict keys.

__ror__()

Return value|self.

__setattr__()

Implement setattr(self, name, value).

__setitem__()

Set self[key] to value.

__sizeof__()

D.__sizeof__() -> size of D in memory, in bytes

__str__()

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

clear()

D.clear() -> None. Remove all items from D.

copy()

D.copy() -> a shallow copy of D

get()

Return the value for key if key is in the dictionary, else default.

items()

D.items() -> a set-like object providing a view on D’s items

keys()

D.keys() -> a set-like object providing a view on D’s keys

pop()

D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault()

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update()

D.update([E, ]**F) -> None. Update D from dict/iterable E and F. If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

D.values() -> an object providing a view on D’s values

medcat.utils.import_utils._DEP_NAME_MAPPER
medcat.utils.import_utils.get_all_extra_deps_raw(package_name)

Get all the dependencies for a pcakge that are for an extra component.

The output will include extra information such as the extra it’s tied to.

Parameters:

package_name (str) – The package name.

Raises:

ValueError – If the package isn’t installed.

Returns:

list[str] – The list of extra dependencies, including extra information.

Return type:

list[str]

medcat.utils.import_utils.get_required_extra_deps(package_name, extra_name)

Get the extra dependencies required for this extra part.

Parameters:
  • package_name (str) – The package name.

  • extra_name (str) – The extra name.

Returns:

list[str] – All the required extra dependencies for this part.

Return type:

list[str]

medcat.utils.import_utils.get_installed_extra_dependencies(package_name, extra_name)

Get installed dependencies for a given package’s extra parts.

Parameters:
  • package_name (str) – The package name.

  • extra_name (str)

Returns:

list[str] – The list of extra packages installed.

Return type:

list[str]

medcat.utils.import_utils.ensure_optional_extras_installed(package_name, extra_name)

Ensure that an optional dependency set is installed.

Parameters:
  • package_name (str) – The base package name.

  • extra_name (str) – The name of the extra dependency.

Raises:

MissingDependenciesError – If the extra dependency isn’t provided.

exception medcat.utils.import_utils.IncorrectExtraComponent(package_name, extra_name)

Bases: Exception

Common base class for all non-exit exceptions.

Parameters:
  • package_name (str)

  • extra_name (str)

__init__(package_name, extra_name)

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • package_name (str)

  • extra_name (str)

package_name
extra_name
class __cause__

exception cause

class __context__

exception context

__delattr__()

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__()

Return self==value.

__format__()

Default object formatter.

__ge__()

Return self>=value.

__getattribute__()

Return getattr(self, name).

__gt__()

Return self>value.

__hash__()

Return hash(self).

__le__()

Return self<=value.

__lt__()

Return self<value.

__ne__()

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

Helper for pickle.

__repr__()

Return repr(self).

__setattr__()

Implement setattr(self, name, value).

__setstate__()
__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

class __suppress_context__
class __traceback__
class args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception medcat.utils.import_utils.MissingDependenciesError(package_name, extra_name, missing)

Bases: Exception

Custom exception for missing optional dependencies.

Parameters:
  • package_name (str)

  • extra_name (str)

  • missing (list[str])

__init__(package_name, extra_name, missing)

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • package_name (str)

  • extra_name (str)

  • missing (list[str])

package_name
extra_name
missing
class __cause__

exception cause

class __context__

exception context

__delattr__()

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__()

Return self==value.

__format__()

Default object formatter.

__ge__()

Return self>=value.

__getattribute__()

Return getattr(self, name).

__gt__()

Return self>value.

__hash__()

Return hash(self).

__le__()

Return self<=value.

__lt__()

Return self<value.

__ne__()

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()
__reduce_ex__()

Helper for pickle.

__repr__()

Return repr(self).

__setattr__()

Implement setattr(self, name, value).

__setstate__()
__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

class __suppress_context__
class __traceback__
class args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.