Skip to content

Commit

Permalink
fix: Address (#648) Missing FileMode causes an AttributeError in py-r…
Browse files Browse the repository at this point in the history
…attler and fix missing properties (#651)
  • Loading branch information
iamthebot committed May 10, 2024
1 parent 50dae59 commit ab2bd4d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
24 changes: 21 additions & 3 deletions py-rattler/rattler/package/paths_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class FileMode:
The file mode of the entry.
"""

_inner: PyFileMode
_inner: PyFileMode | None = None

@property
def binary(self) -> bool:
Expand All @@ -472,7 +472,7 @@ def binary(self) -> bool:
>>>
```
"""
return self._inner.binary
return self._inner.binary if self._inner else False

@property
def text(self) -> bool:
Expand All @@ -492,7 +492,25 @@ def text(self) -> bool:
>>>
```
"""
return self._inner.text
return self._inner.text if self._inner else False

@property
def unknown(self) -> bool:
"""
The file mode is unknown/unspecified
Examples
--------
```python
>>> paths_json = PathsJson.from_package_archive(
... "../test-data/conda-22.9.0-py38haa244fe_2.tar.bz2"
... )
>>> entry = paths_json.paths[-1]
>>> file_mode = entry.prefix_placeholder.file_mode
>>> file_mode.unknown
False
>>>
"""
return self._inner is None

@classmethod
def _from_py_file_mode(cls, py_file_mode: PyFileMode) -> FileMode:
Expand Down
3 changes: 3 additions & 0 deletions py-rattler/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
def gateway() -> Gateway:
return Gateway()


@pytest.fixture
def test_data_dir() -> str:
return os.path.normpath(os.path.join(os.path.dirname(__file__), "../../test-data"))


@pytest.fixture
def conda_forge_channel(test_data_dir: str) -> Channel:
return Channel(os.path.join(test_data_dir, "channels/conda-forge"))


@pytest.fixture
def pytorch_channel(test_data_dir: str) -> Channel:
return Channel(os.path.join(test_data_dir, "channels/pytorch"))
9 changes: 2 additions & 7 deletions py-rattler/tests/unit/test_fetch_repo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
def serve_repo_data(xprocess) -> None:
port, repo_name = 8912, "test-repo"

test_data_dir = os.path.join(
os.path.dirname(__file__), "../../../test-data/test-server"
)
test_data_dir = os.path.join(os.path.dirname(__file__), "../../../test-data/test-server")

class Starter(ProcessStarter):
# startup pattern
Expand Down Expand Up @@ -70,7 +68,4 @@ async def test_fetch_repo_data(
assert repodata_record.channel == f"http://localhost:{port}/{repo}/"
assert repodata_record.file_name == "test-package-0.1-0.tar.bz2"
assert repodata_record.name == PackageName("test-package")
assert (
repodata_record.url
== f"http://localhost:{port}/test-repo/noarch/test-package-0.1-0.tar.bz2"
)
assert repodata_record.url == f"http://localhost:{port}/test-repo/noarch/test-package-0.1-0.tar.bz2"
8 changes: 6 additions & 2 deletions py-rattler/tests/unit/test_prefix_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ def test_load_prefix_record() -> None:
paths_with_placeholder += 1
assert isinstance(entry.file_mode, FileMode)
assert entry.file_mode.text or entry.file_mode.binary
assert entry.sha256_in_prefix is not None
assert entry.sha256 is not None
assert entry.sha256_in_prefix.hex() is not None
else:
assert entry.file_mode.unknown
assert entry.sha256.hex() is not None
assert entry.size_in_bytes > 0

# check that it implements os.PathLike
isinstance(entry, os.PathLike)

assert paths_with_placeholder == 3
14 changes: 11 additions & 3 deletions py-rattler/tests/unit/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
from rattler import (
solve,
ChannelPriority,
RepoDataRecord, Channel, Gateway,
RepoDataRecord,
Channel,
Gateway,
)


@pytest.mark.asyncio
async def test_solve(gateway: Gateway, conda_forge_channel: Channel) -> None:
solved_data = await solve(
Expand All @@ -21,7 +24,9 @@ async def test_solve(gateway: Gateway, conda_forge_channel: Channel) -> None:


@pytest.mark.asyncio
async def test_solve_channel_priority_disabled(gateway: Gateway, pytorch_channel: Channel, conda_forge_channel: Channel) -> None:
async def test_solve_channel_priority_disabled(
gateway: Gateway, pytorch_channel: Channel, conda_forge_channel: Channel
) -> None:
solved_data = await solve(
[conda_forge_channel, pytorch_channel],
["linux-64"],
Expand All @@ -32,5 +37,8 @@ async def test_solve_channel_priority_disabled(gateway: Gateway, pytorch_channel

assert isinstance(solved_data, list)
assert isinstance(solved_data[0], RepoDataRecord)
assert list(filter(lambda r: r.file_name.startswith("pytorch-cpu-0.4.1-py36_cpu_1"), solved_data))[0].channel == pytorch_channel.base_url
assert (
list(filter(lambda r: r.file_name.startswith("pytorch-cpu-0.4.1-py36_cpu_1"), solved_data))[0].channel
== pytorch_channel.base_url
)
assert len(solved_data) == 32

0 comments on commit ab2bd4d

Please sign in to comment.