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: return correct channel urls from MatchSpec.channel.base_url #885

Merged
merged 6 commits into from
Oct 4, 2024
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
8 changes: 4 additions & 4 deletions py-rattler/Cargo.lock

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

6 changes: 6 additions & 0 deletions py-rattler/rattler/channel/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def __init__(self, name: str, channel_configuration: Optional[ChannelConfig] = N

self._channel = PyChannel(name, channel_configuration._channel_configuration)

@classmethod
def _from_py_channel(cls, py_channel: PyChannel) -> Channel:
channel = cls.__new__(cls)
channel._channel = py_channel
return channel

def to_lock_channel(self) -> LockChannel:
"""
Returns a new [`LockChannel`] from existing channel.
Expand Down
5 changes: 2 additions & 3 deletions py-rattler/rattler/match_spec/match_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ def channel(self) -> Optional[Channel]:
"""
The channel of the package.
"""
if (channel := self._match_spec.channel) is not None:
return Channel(channel.name)
return None
channel = self._match_spec.channel
return channel and Channel._from_py_channel(channel)

@property
def subdir(self) -> Optional[str]:
Expand Down
22 changes: 22 additions & 0 deletions py-rattler/tests/unit/test_matchspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,25 @@ def test_parse_channel_from_url() -> None:
assert m.channel is not None
assert m.channel.name == "conda-forge"
assert m.channel.base_url == "https://conda.anaconda.org/conda-forge/"


def test_parse_channel_from_url_filesystem() -> None:
m = MatchSpec("file:///Users/rattler/channel0::python[version=3.9]")
assert m.channel is not None
assert m.channel.name == "channel0"
assert m.channel.base_url == "file:///Users/rattler/channel0/"


def test_parse_channel_from_url_localhost() -> None:
m = MatchSpec("http://localhost:8000/channel0::python[version=3.9]")
assert m.channel is not None
assert m.channel.name == "channel0"
assert m.channel.base_url == "http://localhost:8000/channel0/"


def test_parse_no_channel() -> None:
m = MatchSpec("python[version=3.9]")
assert m.channel is None
assert m.name is not None
assert m.name.normalized == "python"
assert m.version == "==3.9"