Skip to content

medcat.plugins.downloadable

Protocol definitions for plugin installation backends.

Classes:

CredentialProvider

Bases: Protocol

Protocol for providing credentials for private repositories.

Methods:

get_credentials

get_credentials(source: str) -> Optional[dict]

Get credentials for a given source.

Parameters:

  • source

    (str) –

    The source URL or identifier

Returns:

  • Optional[dict]

    Dictionary with credentials (e.g., {'token': '...'}) or None

Source code in medcat-v2/medcat/plugins/downloadable.py
119
120
121
122
123
124
125
126
127
128
129
def get_credentials(self, source: str) -> Optional[dict]:
    """
    Get credentials for a given source.

    Args:
        source: The source URL or identifier

    Returns:
        Dictionary with credentials (e.g., {'token': '...'}) or None
    """
    pass

PluginInstallSpec

Bases: BaseModel

Specification for installing a plugin.

Methods:

Attributes:

name instance-attribute

name: str

source_spec instance-attribute

source_spec: PluginSourceSpec

version_spec instance-attribute

version_spec: str

to_pip_spec

to_pip_spec() -> str

Convert to pip-installable spec.

Source code in medcat-v2/medcat/plugins/downloadable.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def to_pip_spec(self) -> str:
    """Convert to pip-installable spec."""
    src = self.source_spec
    if src.source_type == "pypi":
        return f"{src.source}{self.version_spec}"
    elif src.source_type == "github":
        # Standard GitHub install
        return f"git+{src.source}@{self.version_spec}"
    elif src.source_type == "github_subdir":
        # GitHub with subdirectory
        # Format: git+https://github.com/user/repo.git@ref#subdirectory=path/to/plugin
        base_url = src.source.rstrip('/')
        if not base_url.endswith('.git'):
            base_url += '.git'

        spec = f"git+{base_url}@{self.version_spec}"
        if src.subdirectory:
            spec += f"#subdirectory={src.subdirectory}"
        return spec
    elif src.source_type == "github_ssh":
        # GitHub SSH install
        # Format: git+ssh://git@github.com/user/repo.git@ref
        ssh_url = self._normalize_ssh_url(src.source)
        return f"git+{ssh_url}@{self.version_spec}"
    elif src.source_type == "github_ssh_subdir":
        # GitHub SSH with subdirectory
        # Format: git+ssh://git@github.com/user/repo.git@ref#subdirectory=path
        ssh_url = self._normalize_ssh_url(src.source)
        spec = f"git+{ssh_url}@{self.version_spec}"
        if src.subdirectory:
            spec += f"#subdirectory={src.subdirectory}"
        return spec
    elif src.source_type == "url":
        # Direct URL (could be a tarball, wheel, etc.)
        return src.source
    else:
        raise ValueError(f"Unknown source_type: {src.source_type}")

PluginInstaller

Bases: Protocol

Protocol for plugin installation backends.

Methods:

  • get_name

    Get the name of this installer (e.g., 'pip', 'uv').

  • install

    Install a plugin.

  • is_available

    Check if this installer is available in the environment.

get_name

get_name() -> str

Get the name of this installer (e.g., 'pip', 'uv').

Source code in medcat-v2/medcat/plugins/downloadable.py
111
112
113
def get_name(self) -> str:
    """Get the name of this installer (e.g., 'pip', 'uv')."""
    pass

install

install(spec: PluginInstallSpec, dry_run: bool = False) -> bool

Install a plugin.

Parameters:

  • spec

    (PluginInstallSpec) –

    Plugin installation specification

  • dry_run

    (bool, default: False ) –

    If True, only check what would be installed

Returns:

  • bool

    True if successful, False otherwise

Source code in medcat-v2/medcat/plugins/downloadable.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def install(self, spec: PluginInstallSpec, dry_run: bool = False) -> bool:
    """
    Install a plugin.

    Args:
        spec: Plugin installation specification
        dry_run: If True, only check what would be installed

    Returns:
        True if successful, False otherwise
    """
    pass

is_available

is_available() -> bool

Check if this installer is available in the environment.

Source code in medcat-v2/medcat/plugins/downloadable.py
107
108
109
def is_available(self) -> bool:
    """Check if this installer is available in the environment."""
    pass

PluginSourceSpec

Bases: BaseModel

Where and how to obtain a plugin.

Attributes:

source instance-attribute

source: str

source_type instance-attribute

source_type: str

subdirectory class-attribute instance-attribute

subdirectory: Optional[str] = None