forked from conda/rattler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RunExportsJson (conda#566)
- Loading branch information
Showing
13 changed files
with
472 additions
and
102 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# AboutJson | ||
|
||
::: rattler.package.about_json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
# RunExportsJson | ||
|
||
::: rattler.package.run_exports_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from rattler.package.package_name import PackageName | ||
from rattler.package.about_json import AboutJson | ||
from rattler.package.run_exports_json import RunExportsJson | ||
|
||
__all__ = ["PackageName", "AboutJson"] | ||
__all__ = ["PackageName", "AboutJson", "RunExportsJson"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
from __future__ import annotations | ||
import os | ||
from pathlib import Path | ||
from typing import List | ||
|
||
from rattler.rattler import PyRunExportsJson | ||
|
||
|
||
class RunExportsJson: | ||
""" | ||
A representation of the `run_exports.json` file found in package archives. | ||
The `run_exports.json` file contains information about the run exports of a package | ||
""" | ||
|
||
_inner: PyRunExportsJson | ||
|
||
@staticmethod | ||
def from_package_archive(path: os.PathLike[str]) -> RunExportsJson: | ||
""" | ||
Parses the package file from archive. | ||
Note: If you want to extract multiple `info/*` files then this will be slightly | ||
slower than manually iterating over the archive entries with | ||
custom logic as this skips over the rest of the archive | ||
Examples | ||
-------- | ||
```python | ||
>>> run_exports = RunExportsJson.from_package_archive( | ||
... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" | ||
... ) | ||
>>> run_exports | ||
RunExportsJson() | ||
>>> | ||
``` | ||
""" | ||
return RunExportsJson._from_py_run_exports_json( | ||
PyRunExportsJson.from_package_archive(path) | ||
) | ||
|
||
@staticmethod | ||
def from_path(path: os.PathLike[str]) -> RunExportsJson: | ||
""" | ||
Parses the object from a file specified by a `path`, using a format | ||
appropriate for the file type. | ||
For example, if the file is in JSON format, this function reads the data | ||
from the file at the specified path, parse the JSON string and return the | ||
resulting object. If the file is not in a parsable format or if the file | ||
could not read, this function returns an error. | ||
""" | ||
return RunExportsJson._from_py_run_exports_json( | ||
PyRunExportsJson.from_path(Path(path)) | ||
) | ||
|
||
@staticmethod | ||
def from_package_directory(path: os.PathLike[str]) -> RunExportsJson: | ||
""" | ||
Parses the object by looking up the appropriate file from the root of the | ||
specified Conda archive directory, using a format appropriate for the file | ||
type. | ||
For example, if the file is in JSON format, this function reads the | ||
appropriate file from the archive, parse the JSON string and return the | ||
resulting object. If the file is not in a parsable format or if the file | ||
could not be read, this function returns an error. | ||
""" | ||
return RunExportsJson._from_py_run_exports_json( | ||
PyRunExportsJson.from_package_directory(Path(path)) | ||
) | ||
|
||
@staticmethod | ||
def from_str(string: str) -> RunExportsJson: | ||
""" | ||
Parses the object from a string, using a format appropriate for the file | ||
type. | ||
For example, if the file is in JSON format, this function parses the JSON | ||
string and returns the resulting object. If the file is not in a parsable | ||
format, this function returns an error. | ||
""" | ||
return RunExportsJson._from_py_run_exports_json( | ||
PyRunExportsJson.from_str(string) | ||
) | ||
|
||
@staticmethod | ||
def package_path() -> str: | ||
""" | ||
Returns the path to the file within the Conda archive. | ||
The path is relative to the root of the archive and includes any necessary | ||
directories. | ||
""" | ||
return PyRunExportsJson.package_path() | ||
|
||
@property | ||
def weak(self) -> List[str]: | ||
""" | ||
Weak run exports apply a dependency from host to run. | ||
Examples | ||
-------- | ||
```python | ||
>>> run_exports = RunExportsJson.from_package_archive( | ||
... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" | ||
... ) | ||
>>> run_exports.weak | ||
['python_abi 3.10.* *_cp310'] | ||
>>> | ||
``` | ||
""" | ||
return self._inner.weak | ||
|
||
@property | ||
def strong(self) -> List[str]: | ||
""" | ||
Strong run exports apply a dependency from build to host and run. | ||
Examples | ||
-------- | ||
```python | ||
>>> run_exports = RunExportsJson.from_package_archive( | ||
... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" | ||
... ) | ||
>>> run_exports.strong | ||
[] | ||
>>> | ||
``` | ||
""" | ||
return self._inner.strong | ||
|
||
@property | ||
def noarch(self) -> List[str]: | ||
""" | ||
NoArch run exports apply a run export only to noarch packages (other run exports are ignored). | ||
For example, python uses this to apply a dependency on python to all noarch packages, but not to | ||
the python_abi package. | ||
Examples | ||
-------- | ||
```python | ||
>>> run_exports = RunExportsJson.from_package_archive( | ||
... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" | ||
... ) | ||
>>> run_exports.noarch | ||
['python'] | ||
>>> | ||
``` | ||
""" | ||
return self._inner.noarch | ||
|
||
@property | ||
def weak_constrains(self) -> List[str]: | ||
""" | ||
Weak constrains apply a constrain dependency from host to build, or run to host. | ||
Examples | ||
-------- | ||
```python | ||
>>> run_exports = RunExportsJson.from_package_archive( | ||
... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" | ||
... ) | ||
>>> run_exports.weak_constrains | ||
[] | ||
>>> | ||
``` | ||
""" | ||
return self._inner.weak_constrains | ||
|
||
@property | ||
def strong_constrains(self) -> List[str]: | ||
""" | ||
Strong constrains apply a constrain dependency from build to host and run. | ||
Examples | ||
-------- | ||
```python | ||
>>> run_exports = RunExportsJson.from_package_archive( | ||
... "../test-data/with-symlinks/python-3.10.6-h2c4edbf_0_cpython.tar.bz2" | ||
... ) | ||
>>> run_exports.strong_constrains | ||
[] | ||
>>> | ||
``` | ||
""" | ||
return self._inner.strong_constrains | ||
|
||
@classmethod | ||
def _from_py_run_exports_json( | ||
cls, py_run_exports_json: PyRunExportsJson | ||
) -> RunExportsJson: | ||
run_exports_json = cls.__new__(cls) | ||
run_exports_json._inner = py_run_exports_json | ||
|
||
return run_exports_json | ||
|
||
def __repr__(self) -> str: | ||
""" | ||
Returns a representation of the RunExportsJson. | ||
""" | ||
return "RunExportsJson()" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.