Skip to content

python

Classes

PythonPackage

Bases: BaseModel

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/models/runtime_environment/python.py
25
26
27
28
class PythonPackage(BaseModel):

    name: str = Field(description="The name of the Python package.")
    version: str = Field(description="The version of the package.")

Attributes

name: str = Field(description='The name of the Python package.') class-attribute instance-attribute
version: str = Field(description='The version of the package.') class-attribute instance-attribute

PythonRuntimeEnvironment

Bases: RuntimeEnvironment

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/models/runtime_environment/python.py
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class PythonRuntimeEnvironment(RuntimeEnvironment):

    _kiara_model_id = "info.runtime.python"

    environment_type: Literal["python"]
    python_version: str = Field(description="The version of Python.")
    packages: List[PythonPackage] = Field(
        description="The packages installed in the Python (virtual) environment."
    )
    # python_config: typing.Dict[str, str] = Field(
    #     description="Configuration details about the Python installation."
    # )

    def _create_renderable_for_field(
        self, field_name: str, for_summary: bool = False
    ) -> Union[RenderableType, None]:

        if field_name != "packages":
            return extract_renderable(getattr(self, field_name))

        if for_summary:
            return ", ".join(p.name for p in self.packages)

        table = Table(show_header=True, box=box.SIMPLE)
        table.add_column("package name")
        table.add_column("version")

        for package in self.packages:
            table.add_row(package.name, package.version)

        return table

    def _retrieve_sub_profile_env_data(self) -> Mapping[str, Any]:

        only_packages = [p.name for p in self.packages]
        full = {k.name: k.version for k in self.packages}

        return {
            "package_names": only_packages,
            "packages": full,
            "package_names_incl_python_version": {
                "python_version": self.python_version,
                "packages": only_packages,
            },
            "packages_incl_python_version": {
                "python_version": self.python_version,
                "packages": full,
            },
        }

    @classmethod
    def retrieve_environment_data(cls) -> Dict[str, Any]:

        packages: Dict[str, str] = {}
        all_packages = find_all_distributions()

        for name, pkgs in all_packages.items():
            for pkg in pkgs:
                dist = distribution(pkg)
                if pkg in packages.keys() and packages[pkg] != dist.version:
                    raise Exception(
                        f"Multiple versions of package '{pkg}' available: {packages[pkg]} and {dist.version}."
                    )
                packages[pkg] = dist.version

        result: Dict[str, Any] = {
            "python_version": sys.version,
            "packages": [
                {"name": p, "version": packages[p]}
                for p in sorted(packages.keys(), key=lambda x: x.lower())
            ],
        }

        # if config.include_all_info:
        #     import sysconfig
        #     result["python_config"] = sysconfig.get_config_vars()

        return result

Attributes

environment_type: Literal['python'] instance-attribute
python_version: str = Field(description='The version of Python.') class-attribute instance-attribute
packages: List[PythonPackage] = Field(description='The packages installed in the Python (virtual) environment.') class-attribute instance-attribute

Functions

retrieve_environment_data() -> Dict[str, Any] classmethod
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/models/runtime_environment/python.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
@classmethod
def retrieve_environment_data(cls) -> Dict[str, Any]:

    packages: Dict[str, str] = {}
    all_packages = find_all_distributions()

    for name, pkgs in all_packages.items():
        for pkg in pkgs:
            dist = distribution(pkg)
            if pkg in packages.keys() and packages[pkg] != dist.version:
                raise Exception(
                    f"Multiple versions of package '{pkg}' available: {packages[pkg]} and {dist.version}."
                )
            packages[pkg] = dist.version

    result: Dict[str, Any] = {
        "python_version": sys.version,
        "packages": [
            {"name": p, "version": packages[p]}
            for p in sorted(packages.keys(), key=lambda x: x.lower())
        ],
    }

    # if config.include_all_info:
    #     import sysconfig
    #     result["python_config"] = sysconfig.get_config_vars()

    return result

KiaraPluginsRuntimeEnvironment

Bases: RuntimeEnvironment

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/models/runtime_environment/python.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
class KiaraPluginsRuntimeEnvironment(RuntimeEnvironment):

    _kiara_model_id = "info.runtime.kiara_plugins"

    environment_type: Literal["kiara_plugins"]
    kiara_plugins: List[PythonPackage] = Field(
        description="The kiara plugin packages installed in the Python (virtual) environment."
    )

    def _create_renderable_for_field(
        self, field_name: str, for_summary: bool = False
    ) -> Union[RenderableType, None]:

        if field_name != "packages":
            return extract_renderable(getattr(self, field_name))

        if for_summary:
            return ", ".join(p.name for p in self.kiara_plugins)

        table = Table(show_header=True, box=box.SIMPLE)
        table.add_column("package name")
        table.add_column("version")

        for package in self.kiara_plugins:
            table.add_row(package.name, package.version)

        return table

    def _retrieve_sub_profile_env_data(self) -> Mapping[str, Any]:

        only_packages = [p.name for p in self.kiara_plugins]
        full = {k.name: k.version for k in self.kiara_plugins}

        return {"package_names": only_packages, "packages": full}

    @classmethod
    def retrieve_environment_data(cls) -> Dict[str, Any]:

        packages = []
        all_packages = find_all_distributions()
        all_pkg_names = set()
        for name, pkgs in all_packages.items():

            for pkg in pkgs:
                if not pkg.startswith("kiara_plugin.") and not pkg.startswith(
                    "kiara-plugin."
                ):
                    continue
                else:
                    all_pkg_names.add(pkg)

        for pkg in sorted(all_pkg_names):
            dist = distribution(pkg)
            packages.append({"name": pkg, "version": dist.version})

        result: Dict[str, Any] = {
            "kiara_plugins": packages,
        }

        # if config.include_all_info:
        #     import sysconfig
        #     result["python_config"] = sysconfig.get_config_vars()

        return result

Attributes

environment_type: Literal['kiara_plugins'] instance-attribute
kiara_plugins: List[PythonPackage] = Field(description='The kiara plugin packages installed in the Python (virtual) environment.') class-attribute instance-attribute

Functions

retrieve_environment_data() -> Dict[str, Any] classmethod
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/models/runtime_environment/python.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
@classmethod
def retrieve_environment_data(cls) -> Dict[str, Any]:

    packages = []
    all_packages = find_all_distributions()
    all_pkg_names = set()
    for name, pkgs in all_packages.items():

        for pkg in pkgs:
            if not pkg.startswith("kiara_plugin.") and not pkg.startswith(
                "kiara-plugin."
            ):
                continue
            else:
                all_pkg_names.add(pkg)

    for pkg in sorted(all_pkg_names):
        dist = distribution(pkg)
        packages.append({"name": pkg, "version": dist.version})

    result: Dict[str, Any] = {
        "kiara_plugins": packages,
    }

    # if config.include_all_info:
    #     import sysconfig
    #     result["python_config"] = sysconfig.get_config_vars()

    return result

Functions

find_all_distributions() cached

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/models/runtime_environment/python.py
31
32
33
34
@lru_cache()
def find_all_distributions():
    all_packages = packages_distributions()
    return all_packages