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

fix: add repodata gateway names #931

Merged
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
37 changes: 37 additions & 0 deletions py-rattler/rattler/repo_data/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,43 @@ async def query(
# Convert the records into python objects
return [[RepoDataRecord._from_py_record(record) for record in records] for records in py_records]

async def names(
self, channels: List[Channel | str], platforms: List[Platform | PlatformLiteral]
) -> List[PackageName]:
"""Queries all the names of packages in a channel.

Arguments:
channels: The channels to query.
platforms: The platforms to query.

Returns:
A list of package names that are present in the given subdirectories.

Examples
--------
```python
>>> import asyncio
>>> gateway = Gateway()
>>> records = asyncio.run(gateway.names(["conda-forge"], ["linux-64"]))
>>> PackageName("python") in records
True
>>>
```
"""

py_package_names = await self._gateway.names(
channels=[
channel._channel if isinstance(channel, Channel) else Channel(channel)._channel for channel in channels
],
platforms=[
platform._inner if isinstance(platform, Platform) else Platform(platform)._inner
for platform in platforms
],
)

# Convert the records into python objects
return [PackageName._from_py_package_name(package_name) for package_name in py_package_names]

def clear_repodata_cache(
self, channel: Channel | str, subdirs: Optional[List[Platform | PlatformLiteral]] = None
) -> None:
Expand Down
23 changes: 23 additions & 0 deletions py-rattler/src/repo_data/gateway.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::error::PyRattlerError;
use crate::match_spec::PyMatchSpec;
use crate::package_name::PyPackageName;
use crate::platform::PyPlatform;
use crate::record::PyRecord;
use crate::{PyChannel, Wrap};
Expand Down Expand Up @@ -110,6 +111,28 @@ impl PyGateway {
.collect::<Vec<_>>())
})
}

pub fn names<'a>(
&self,
py: Python<'a>,
channels: Vec<PyChannel>,
platforms: Vec<PyPlatform>,
) -> PyResult<Bound<'a, PyAny>> {
let gateway = self.inner.clone();
future_into_py(py, async move {
let names = gateway
.names(channels, platforms.into_iter().map(|p| p.inner))
.execute()
.await
.map_err(PyRattlerError::from)?;

// Convert the records into a list of lists
Ok(names
.into_iter()
.map(PyPackageName::from)
.collect::<Vec<_>>())
})
}
}

#[pyclass]
Expand Down