-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add channel types to py-rattler (#313)
- Loading branch information
Showing
9 changed files
with
201 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,5 +1,13 @@ | ||
from rattler.version import Version | ||
from rattler.match_spec import MatchSpec, NamelessMatchSpec | ||
from rattler.repo_data import PackageRecord | ||
from rattler.channel import Channel, ChannelConfig | ||
|
||
__all__ = ["Version", "MatchSpec", "NamelessMatchSpec", "PackageRecord"] | ||
__all__ = [ | ||
"Version", | ||
"MatchSpec", | ||
"NamelessMatchSpec", | ||
"PackageRecord", | ||
"Channel", | ||
"ChannelConfig", | ||
] |
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 @@ | ||
from rattler.channel.channel import Channel | ||
from rattler.channel.channel_config import ChannelConfig | ||
|
||
__all__ = ["Channel", "ChannelConfig"] |
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,45 @@ | ||
from __future__ import annotations | ||
from typing import Optional | ||
|
||
from rattler.rattler import PyChannel | ||
from rattler.channel.channel_config import ChannelConfig | ||
|
||
|
||
class Channel: | ||
def __init__(self, name: str, channel_configuration: ChannelConfig): | ||
""" | ||
Create a new channel. | ||
>>> channel = Channel("conda-forge", ChannelConfig()) | ||
>>> channel | ||
Channel(name="conda-forge", base_url="https://conda.anaconda.org/conda-forge/") | ||
""" | ||
self._channel = PyChannel(name, channel_configuration._channel_configuration) | ||
|
||
@property | ||
def name(self) -> Optional[str]: | ||
""" | ||
Return the name of this channel. | ||
>>> channel = Channel("conda-forge", ChannelConfig()) | ||
>>> channel.name | ||
'conda-forge' | ||
""" | ||
return self._channel.name | ||
|
||
@property | ||
def base_url(self) -> str: | ||
""" | ||
Return the base URL of this channel. | ||
>>> channel = Channel("conda-forge", ChannelConfig()) | ||
>>> channel.base_url | ||
'https://conda.anaconda.org/conda-forge/' | ||
""" | ||
return self._channel.base_url | ||
|
||
def __repr__(self) -> str: | ||
""" | ||
Return a string representation of this channel. | ||
""" | ||
return f'Channel(name="{self.name}", base_url="{self.base_url}")' |
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,26 @@ | ||
from __future__ import annotations | ||
|
||
from rattler.rattler import PyChannelConfig | ||
|
||
|
||
class ChannelConfig: | ||
def __init__(self, channel_alias="https://conda.anaconda.org/"): | ||
""" | ||
Create a new channel configuration. | ||
>>> channel_config = ChannelConfig() | ||
>>> channel_config | ||
ChannelConfig(channel_alias="https://conda.anaconda.org/") | ||
>>> channel_config = ChannelConfig("https://repo.prefix.dev/") | ||
>>> channel_config | ||
ChannelConfig(channel_alias="https://repo.prefix.dev/") | ||
""" | ||
self._channel_configuration = PyChannelConfig(channel_alias) | ||
|
||
def __repr__(self) -> str: | ||
""" | ||
Return a string representation of this channel configuration. | ||
""" | ||
alias = self._channel_configuration.channel_alias | ||
return f'ChannelConfig(channel_alias="{alias}")' |
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,71 @@ | ||
use pyo3::{pyclass, pymethods}; | ||
use rattler_conda_types::{Channel, ChannelConfig}; | ||
use url::Url; | ||
|
||
use crate::error::PyRattlerError; | ||
|
||
#[pyclass] | ||
#[repr(transparent)] | ||
#[derive(Clone)] | ||
pub struct PyChannelConfig { | ||
pub(crate) inner: ChannelConfig, | ||
} | ||
|
||
#[pymethods] | ||
impl PyChannelConfig { | ||
#[new] | ||
pub fn __init__(channel_alias: &str) -> pyo3::PyResult<Self> { | ||
Ok(Self { | ||
inner: ChannelConfig { | ||
channel_alias: Url::parse(channel_alias).map_err(PyRattlerError::from)?, | ||
}, | ||
}) | ||
} | ||
|
||
/// Return the channel alias that is configured | ||
#[getter] | ||
fn channel_alias(&self) -> String { | ||
self.inner.channel_alias.to_string() | ||
} | ||
} | ||
|
||
#[pyclass] | ||
#[repr(transparent)] | ||
#[derive(Clone)] | ||
pub struct PyChannel { | ||
pub(crate) inner: Channel, | ||
} | ||
|
||
impl From<Channel> for PyChannel { | ||
fn from(value: Channel) -> Self { | ||
Self { inner: value } | ||
} | ||
} | ||
|
||
impl From<PyChannel> for Channel { | ||
fn from(val: PyChannel) -> Self { | ||
val.inner | ||
} | ||
} | ||
|
||
#[pymethods] | ||
impl PyChannel { | ||
#[new] | ||
pub fn __init__(version: &str, config: &PyChannelConfig) -> pyo3::PyResult<Self> { | ||
Ok(Channel::from_str(version, &config.inner) | ||
.map(Into::into) | ||
.map_err(PyRattlerError::from)?) | ||
} | ||
|
||
/// Return the name of the channel | ||
#[getter] | ||
fn name(&self) -> Option<String> { | ||
self.inner.name.clone() | ||
} | ||
|
||
/// Return the base url of the channel | ||
#[getter] | ||
fn base_url(&self) -> String { | ||
self.inner.base_url.to_string() | ||
} | ||
} |
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