Skip to content

feat: support redirection#293

Open
drbh wants to merge 1 commit intomainfrom
enable-redirection
Open

feat: support redirection#293
drbh wants to merge 1 commit intomainfrom
enable-redirection

Conversation

@drbh
Copy link
Collaborator

@drbh drbh commented Feb 19, 2026

This PR adds a concept of redirection via a REDIRECT.toml file on the main branch.

The kernel tool will now first check for a redirection file, read and apply the redirection if it exists. The core use case is enable a way to manually redirect users from old repos to newer kernel repos with a custom message.

Note: redirections are single hop only, its not possible to redirect to another redirect

example file

destination = "kernels-community/activation"
message = "This kernel has been moved to kernels-community/activation. Please update your dependencies to use the new location."

this example file is currently hosted https://huggingface.co/drbh/test-kernel-redirect

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@danieldk danieldk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really useful functionality! I would make it more general though, because as it is now, we would have to deprecate this again if we add archived/deprecation in the future.


from kernels.compat import tomllib

REDIRECT_FILENAME = "REDIRECT.toml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have a more generic name than that, so that we can use the same file for multiple signaling purposes.

Maybe kernel-status.toml?

Comment on lines +13 to +16
@dataclass
class RedirectInfo:
destination: str
message: str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirect should be one of a union (so that we can also have e.g. deprecated/unmaintained in the future).

message: str


def parse_redirect_file(content: str) -> RedirectInfo:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have this similar to https://github.com/huggingface/kernels/blob/main/kernels/src/kernels/metadata.py where these are methods.

Maybe we should consider switching to pydantic for these deserialization/ validation purposes.

Comment on lines +48 to +50
RED_COLOR = "\033[91m"
RESET_COLOR = "\033[0m"
msg = f"\n{RED_COLOR}{msg}{RESET_COLOR}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these work well in Windows shells, I vaguely remember ASCII sequences giving issues and you need a library to make them work on *nix and Windows.

Comment on lines +54 to +56
if "@" in redirect.destination:
return redirect.destination.rsplit("@", 1)
return redirect.destination, "main"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ in the string data seems very ad-hoc if we have a structured data format like TOML?

backend: str | None = None,
variant_locks: dict[str, VariantLock] | None = None,
user_agent: str | dict | None = None,
follow_redirects: bool = True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave this out. We already have plenty of arguments and we are probably going to add framework soon. I think we should just go for doing the right thing by default. If a kernel developer sets a repo to redirect, they probably really want to redirect.

@dataclass
class RedirectInfo:
destination: str
message: str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave out a message for now.

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

Successfully merging this pull request may close these issues.

3 participants

Comments