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

Bump to py-rattler 0.7.0 and remove workarounds for NamelessMatchSpec url parsing #259

Open
cisaacstern opened this issue Sep 23, 2024 · 0 comments

Comments

@cisaacstern
Copy link
Collaborator

Per conda/rattler#870 (comment), the following workarounds should no longer be necessary on py-rattler 0.7.0

# FIXME: workaround for https://github.com/conda/rattler/issues/869
# this override can be removed once the issue is resolved.
class NamelessMatchSpec(_NamelessMatchSpec):
@property
def channel(self):
if (channel := self._nameless_match_spec.channel) is not None:
return next(c for c in CHANNELS if c.name == channel.name)
return None

def _namelessmatchspec_from_dict(value: dict[str, str]) -> NamelessMatchSpec:
assert "version" in value, f"Expected 'version' key in {value}"
assert "channel" in value, f"Expected 'channel' key in {value}"
# FIXME: workaround for https://github.com/conda/rattler/issues/869
# this conditional block can be removed once the issue is resolved.
match value["channel"]:
case _ if value["channel"] in [
c.base_url for c in (LOCAL_CHANNEL, RELEASE_CHANNEL)
]:
channel = next(c.name for c in CHANNELS if c.base_url == value["channel"])
case str("conda-forge"):
channel = value["channel"]
case _:
raise ValueError(f"Unknown channel {value['channel']}")
foo_pkg = "foo" # placeholder to use from_match_spec constructor
m = MatchSpec(f"{channel}::{foo_pkg} {value['version']}")
# FIXME: this type error is a side effect of the override for NamelessMatchSpec
# and can be removed once the issue linked there is resolved.
return NamelessMatchSpec.from_match_spec(m) # type: ignore[return-value]

def _serialize_namelessmatchspec(value: NamelessMatchSpec) -> dict:
# FIXME: workaround for https://github.com/conda/rattler/issues/869
# this conditional block can be removed once the issue is resolved.
match value.channel:
case None:
channel = None
case c if c.base_url in [
channel.base_url for channel in (LOCAL_CHANNEL, RELEASE_CHANNEL)
]:
channel = next(
c.base_url for c in CHANNELS if c.base_url == value.channel.base_url
)
case str("conda-forge"):
channel = c
case _:
raise ValueError(f"Unknown channel {value.channel}")
return {"version": str(value.version)} | ({"channel": channel} if channel else {})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant