|
| 1 | +from __future__ import annotations |
| 2 | +import os |
| 3 | +from pathlib import Path |
| 4 | +from typing import List |
| 5 | + |
| 6 | +from rattler.rattler import PyRunExportsJson |
| 7 | + |
| 8 | + |
| 9 | +class RunExportsJson: |
| 10 | + """ |
| 11 | + A representation of the `run_exports.json` file found in package archives. |
| 12 | + The `run_exports.json` file contains information about the run exports of a package |
| 13 | + """ |
| 14 | + |
| 15 | + _inner: PyRunExportsJson |
| 16 | + |
| 17 | + @staticmethod |
| 18 | + def from_package_archive(path: os.PathLike[str]) -> RunExportsJson: |
| 19 | + """ |
| 20 | + Parses the package file from archive. |
| 21 | + Note: If you want to extract multiple `info/*` files then this will be slightly |
| 22 | + slower than manually iterating over the archive entries with |
| 23 | + custom logic as this skips over the rest of the archive |
| 24 | +
|
| 25 | + Examples |
| 26 | + -------- |
| 27 | + ```python |
| 28 | + >>> run_exports = RunExportsJson.from_package_archive( |
| 29 | + ... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" |
| 30 | + ... ) |
| 31 | + >>> run_exports |
| 32 | + RunExportsJson() |
| 33 | + >>> |
| 34 | + ``` |
| 35 | + """ |
| 36 | + return RunExportsJson._from_py_run_exports_json( |
| 37 | + PyRunExportsJson.from_package_archive(path) |
| 38 | + ) |
| 39 | + |
| 40 | + @staticmethod |
| 41 | + def from_path(path: os.PathLike[str]) -> RunExportsJson: |
| 42 | + """ |
| 43 | + Parses the object from a file specified by a `path`, using a format |
| 44 | + appropriate for the file type. |
| 45 | +
|
| 46 | + For example, if the file is in JSON format, this function reads the data |
| 47 | + from the file at the specified path, parse the JSON string and return the |
| 48 | + resulting object. If the file is not in a parsable format or if the file |
| 49 | + could not read, this function returns an error. |
| 50 | + """ |
| 51 | + return RunExportsJson._from_py_run_exports_json( |
| 52 | + PyRunExportsJson.from_path(Path(path)) |
| 53 | + ) |
| 54 | + |
| 55 | + @staticmethod |
| 56 | + def from_package_directory(path: os.PathLike[str]) -> RunExportsJson: |
| 57 | + """ |
| 58 | + Parses the object by looking up the appropriate file from the root of the |
| 59 | + specified Conda archive directory, using a format appropriate for the file |
| 60 | + type. |
| 61 | +
|
| 62 | + For example, if the file is in JSON format, this function reads the |
| 63 | + appropriate file from the archive, parse the JSON string and return the |
| 64 | + resulting object. If the file is not in a parsable format or if the file |
| 65 | + could not be read, this function returns an error. |
| 66 | + """ |
| 67 | + return RunExportsJson._from_py_run_exports_json( |
| 68 | + PyRunExportsJson.from_package_directory(Path(path)) |
| 69 | + ) |
| 70 | + |
| 71 | + @staticmethod |
| 72 | + def from_str(string: str) -> RunExportsJson: |
| 73 | + """ |
| 74 | + Parses the object from a string, using a format appropriate for the file |
| 75 | + type. |
| 76 | +
|
| 77 | + For example, if the file is in JSON format, this function parses the JSON |
| 78 | + string and returns the resulting object. If the file is not in a parsable |
| 79 | + format, this function returns an error. |
| 80 | + """ |
| 81 | + return RunExportsJson._from_py_run_exports_json( |
| 82 | + PyRunExportsJson.from_str(string) |
| 83 | + ) |
| 84 | + |
| 85 | + @staticmethod |
| 86 | + def package_path() -> str: |
| 87 | + """ |
| 88 | + Returns the path to the file within the Conda archive. |
| 89 | +
|
| 90 | + The path is relative to the root of the archive and includes any necessary |
| 91 | + directories. |
| 92 | + """ |
| 93 | + return PyRunExportsJson.package_path() |
| 94 | + |
| 95 | + @property |
| 96 | + def weak(self) -> List[str]: |
| 97 | + """ |
| 98 | + Weak run exports apply a dependency from host to run. |
| 99 | +
|
| 100 | + Examples |
| 101 | + -------- |
| 102 | + ```python |
| 103 | + >>> run_exports = RunExportsJson.from_package_archive( |
| 104 | + ... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" |
| 105 | + ... ) |
| 106 | + >>> run_exports.weak |
| 107 | + ['python_abi 3.10.* *_cp310'] |
| 108 | + >>> |
| 109 | + ``` |
| 110 | + """ |
| 111 | + return self._inner.weak |
| 112 | + |
| 113 | + @property |
| 114 | + def strong(self) -> List[str]: |
| 115 | + """ |
| 116 | + Strong run exports apply a dependency from build to host and run. |
| 117 | +
|
| 118 | + Examples |
| 119 | + -------- |
| 120 | + ```python |
| 121 | + >>> run_exports = RunExportsJson.from_package_archive( |
| 122 | + ... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" |
| 123 | + ... ) |
| 124 | + >>> run_exports.strong |
| 125 | + [] |
| 126 | + >>> |
| 127 | + ``` |
| 128 | + """ |
| 129 | + return self._inner.strong |
| 130 | + |
| 131 | + @property |
| 132 | + def noarch(self) -> List[str]: |
| 133 | + """ |
| 134 | + NoArch run exports apply a run export only to noarch packages (other run exports are ignored). |
| 135 | + For example, python uses this to apply a dependency on python to all noarch packages, but not to |
| 136 | + the python_abi package. |
| 137 | +
|
| 138 | + Examples |
| 139 | + -------- |
| 140 | + ```python |
| 141 | + >>> run_exports = RunExportsJson.from_package_archive( |
| 142 | + ... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" |
| 143 | + ... ) |
| 144 | + >>> run_exports.noarch |
| 145 | + ['python'] |
| 146 | + >>> |
| 147 | + ``` |
| 148 | + """ |
| 149 | + return self._inner.noarch |
| 150 | + |
| 151 | + @property |
| 152 | + def weak_constrains(self) -> List[str]: |
| 153 | + """ |
| 154 | + Weak constrains apply a constrain dependency from host to build, or run to host. |
| 155 | +
|
| 156 | + Examples |
| 157 | + -------- |
| 158 | + ```python |
| 159 | + >>> run_exports = RunExportsJson.from_package_archive( |
| 160 | + ... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" |
| 161 | + ... ) |
| 162 | + >>> run_exports.weak_constrains |
| 163 | + [] |
| 164 | + >>> |
| 165 | + ``` |
| 166 | + """ |
| 167 | + return self._inner.weak_constrains |
| 168 | + |
| 169 | + @property |
| 170 | + def strong_constrains(self) -> List[str]: |
| 171 | + """ |
| 172 | + Strong constrains apply a constrain dependency from build to host and run. |
| 173 | +
|
| 174 | + Examples |
| 175 | + -------- |
| 176 | + ```python |
| 177 | + >>> run_exports = RunExportsJson.from_package_archive( |
| 178 | + ... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" |
| 179 | + ... ) |
| 180 | + >>> run_exports.strong_constrains |
| 181 | + [] |
| 182 | + >>> |
| 183 | + ``` |
| 184 | + """ |
| 185 | + return self._inner.strong_constrains |
| 186 | + |
| 187 | + @classmethod |
| 188 | + def _from_py_run_exports_json( |
| 189 | + cls, py_run_exports_json: PyRunExportsJson |
| 190 | + ) -> RunExportsJson: |
| 191 | + run_exports_json = cls.__new__(cls) |
| 192 | + run_exports_json._inner = py_run_exports_json |
| 193 | + |
| 194 | + return run_exports_json |
| 195 | + |
| 196 | + def __repr__(self) -> str: |
| 197 | + """ |
| 198 | + Returns a representation of the RunExportsJson. |
| 199 | + """ |
| 200 | + return "RunExportsJson()" |
0 commit comments