Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more py-rattler types #348

Merged
merged 10 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions py-rattler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions py-rattler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ crate-type = ["cdylib"]
rattler_conda_types = { path = "../crates/rattler_conda_types", default-features = false }
rattler_networking = { path = "../crates/rattler_networking", default-features = false }
rattler_shell = { path = "../crates/rattler_shell", default-features = false }
rattler_virtual_packages = { path = "../crates/rattler_virtual_packages" }
rattler_solve = { path = "../crates/rattler_solve" }

pyo3 = { version = "0.19", features = [
"abi3-py38",
Expand Down
8 changes: 8 additions & 0 deletions py-rattler/rattler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from rattler.repo_data import PackageRecord
from rattler.channel import Channel, ChannelConfig
from rattler.networking import AuthenticatedClient
from rattler.virtual_package import GenericVirtualPackage, VirtualPackage
from rattler.package import PackageName
from rattler.prefix import PrefixRecord, PrefixPaths

__all__ = [
"Version",
Expand All @@ -13,4 +16,9 @@
"Channel",
"ChannelConfig",
"AuthenticatedClient",
"GenericVirtualPackage",
"VirtualPackage",
"PackageName",
"PrefixRecord",
"PrefixPaths",
]
3 changes: 3 additions & 0 deletions py-rattler/rattler/package/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from rattler.package.package_name import PackageName

__all__ = ["PackageName"]
76 changes: 76 additions & 0 deletions py-rattler/rattler/package/package_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from __future__ import annotations
from typing import Self

from rattler.rattler import PyPackageName


class PackageName:
def __init__(self, source: str) -> None:
if not isinstance(source, str):
raise TypeError(
"PackageName constructor received unsupported type "
f" {type(source).__name__!r} for the `source` parameter"
)
self._name = PyPackageName(source)

@staticmethod
def unchecked(normalized: str) -> PackageName:
"""
Constructs a new `PackageName` from a string without checking if the string is actually a
valid or normalized conda package name. This should only be used if you are sure that the
input string is valid.

Examples
--------
>>> p = PackageName.unchecked("test_xyz")
"""
return PackageName._from_py_package_name(
PyPackageName.new_unchecked(normalized)
)

@classmethod
def _from_py_package_name(cls, py_package_name: PyPackageName) -> Self:
"""Construct Rattler PackageName from FFI PyPackageName object."""
package_name = cls.__new__(cls)
package_name._name = py_package_name
return package_name

@property
def source(self) -> str:
"""
Returns the source representation of the package name.
This is the string from which this instance was created.

Examples
--------
>>> p = PackageName("test-xyz")
>>> p.source
'test-xyz'
"""
return self._name.source

@property
def normalized(self) -> str:
"""
Returns the normalized version of the package name.
The normalized string is guaranteed to be a valid conda package name.

Examples
--------
>>> p = PackageName("test-xyz")
>>> p.normalized
'test-xyz'
"""
return self._name.normalized

def __repr__(self) -> str:
"""
Returns a representation of the version.

Examples
--------
>>> p = PackageName("test-xyz")
>>> p
PackageName("test-xyz")
"""
return f'PackageName("{self.source}")'
4 changes: 4 additions & 0 deletions py-rattler/rattler/prefix/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from rattler.prefix.prefix_record import PrefixRecord
from rattler.prefix.prefix_paths import PrefixPaths

__all__ = ["PrefixRecord", "PrefixPaths"]
65 changes: 65 additions & 0 deletions py-rattler/rattler/prefix/prefix_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from __future__ import annotations
import os
from typing import List, Self

from rattler.rattler import PyPrefixPaths


class PrefixPaths:
_paths: PyPrefixPaths

@classmethod
def _from_py_prefix_paths(cls, py_prefix_paths: PyPrefixPaths) -> Self:
"""Construct Rattler PrefixRecord from FFI PyPrefixRecord object."""
paths = cls.__new__(cls)
paths._paths = py_prefix_paths
return paths

@property
def paths_version(self) -> int:
"""
The version of the file.

Examples
--------
>>> from rattler.prefix.prefix_record import PrefixRecord
>>> r = PrefixRecord.from_path(
... "../test-data/conda-meta/requests-2.28.2-pyhd8ed1ab_0.json"
... )
>>> paths = r.paths_data
>>> paths.paths_version
1
"""
return self._paths.paths_version

@property
def paths(self) -> List[os.PathLike[str]]:
"""
All entries included in the package.

Examples
--------
>>> from rattler.prefix.prefix_record import PrefixRecord
>>> r = PrefixRecord.from_path(
... "../test-data/conda-meta/requests-2.28.2-pyhd8ed1ab_0.json"
... )
>>> paths = r.paths_data
>>> paths.paths # doctest:+ELLIPSIS
[...]
"""
return self._paths.paths

def __repr__(self) -> str:
"""
Returns a representation of the version.

Examples
--------
>>> from rattler.prefix.prefix_record import PrefixRecord
>>> r = PrefixRecord.from_path(
... "../test-data/conda-meta/requests-2.28.2-pyhd8ed1ab_0.json"
... )
>>> r.paths_data
PrefixPaths()
"""
return "PrefixPaths()"
tarunps marked this conversation as resolved.
Show resolved Hide resolved
Loading