Skip to content

Commit 7b2ed6d

Browse files
committed
fix: update api interface and nix configs
1 parent 48f08fe commit 7b2ed6d

8 files changed

Lines changed: 21 additions & 27 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kernel-builder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ clap-markdown = "0.1.5"
1616
clap_complete = "4"
1717
eyre = "0.6.12"
1818
git2 = "0.20"
19-
hf-hub = { git = "https://github.com/huggingface/hf-hub.git", rev = "54d70e8afc95dad00e7fcebf8e0d74a39c395856", features = ["blocking"] }
19+
hf-hub = { git = "https://github.com/huggingface/hf-hub.git", rev = "670b3f489cc10e1c4a7325fb8632bffbe07f0c40", features = ["blocking"] }
2020
itertools = "0.13"
2121
minijinja = "2.5"
2222
minijinja-embed = "2.5"

kernel-builder/src/hf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ pub fn api() -> Result<hf_hub::HFClientSync> {
77
}
88

99
/// Get a repo handle.
10-
pub fn repo_handle(api: &HFClientSync, repo_type: RepoType, repo_id: &str) -> HFRepositorySync {
10+
pub fn repo_handle<T: RepoType>(api: &HFClientSync, repo_id: &str) -> HFRepositorySync<T> {
1111
let parts: Vec<&str> = repo_id.splitn(2, '/').collect();
1212
if parts.len() == 2 {
13-
api.repo(repo_type, parts[0], parts[1])
13+
api.repository::<T>(parts[0], parts[1])
1414
} else {
15-
api.repo(repo_type, "", repo_id)
15+
api.repository::<T>("", repo_id)
1616
}
1717
}
1818

kernel-builder/src/upload.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use clap::Args;
99
use eyre::{bail, Context, Result};
1010
use hf_hub::{
1111
repository::{AddSource, CommitOperation},
12-
RepoType,
12+
RepoType, RepoTypeKernel, RepoTypeModel,
1313
};
1414
use kernels_data::metadata::Metadata;
1515
use walkdir::WalkDir;
@@ -29,15 +29,6 @@ pub enum RepoTypeArg {
2929
Kernel,
3030
}
3131

32-
impl From<RepoTypeArg> for RepoType {
33-
fn from(arg: RepoTypeArg) -> Self {
34-
match arg {
35-
RepoTypeArg::Model => RepoType::Model,
36-
RepoTypeArg::Kernel => RepoType::Kernel,
37-
}
38-
}
39-
}
40-
4132
#[derive(Debug, Args)]
4233
pub struct UploadArgs {
4334
/// Directory of the kernel build (defaults to current directory).
@@ -96,8 +87,14 @@ fn get_repo_and_branch(
9687
}
9788

9889
pub fn run_upload(args: UploadArgs) -> Result<()> {
90+
match args.repo_type {
91+
RepoTypeArg::Model => run_upload_typed::<RepoTypeModel>(args),
92+
RepoTypeArg::Kernel => run_upload_typed::<RepoTypeKernel>(args),
93+
}
94+
}
95+
96+
fn run_upload_typed<T: RepoType>(args: UploadArgs) -> Result<()> {
9997
let api = hf::api()?;
100-
let repo_type: RepoType = args.repo_type.into();
10198
let kernel_dir = check_or_infer_kernel_dir(args.kernel_dir)?;
10299
let kernel_dir = fs::canonicalize(&kernel_dir)
103100
.wrap_err_with(|| format!("Cannot resolve kernel directory `{}`", kernel_dir.display()))?;
@@ -112,9 +109,9 @@ pub fn run_upload(args: UploadArgs) -> Result<()> {
112109
let (repo_id, branch) = get_repo_and_branch(&kernel_dir, args.repo_id, args.branch, &variants)?;
113110

114111
let repo_url = api
115-
.create_repo()
112+
.create_repository()
116113
.repo_id(&repo_id)
117-
.repo_type(repo_type)
114+
.repo_type(T::default())
118115
.private(args.private)
119116
.exist_ok(true)
120117
.send()
@@ -128,7 +125,7 @@ pub fn run_upload(args: UploadArgs) -> Result<()> {
128125
.unwrap_or(&repo_id)
129126
.to_owned();
130127

131-
let repo = repo_handle(&api, repo_type, &repo_id);
128+
let repo = repo_handle::<T>(&api, &repo_id);
132129

133130
let is_new_version_branch = if let Some(ref branch) = branch {
134131
let refs = repo
@@ -240,10 +237,7 @@ pub fn run_upload(args: UploadArgs) -> Result<()> {
240237
if total_ops == 0 {
241238
eprintln!("No changes to upload.");
242239
} else {
243-
let type_prefix = match repo_type {
244-
RepoType::Kernel => "kernels/",
245-
_ => "",
246-
};
240+
let type_prefix = T::default().url_prefix();
247241
let tree_path = branch
248242
.as_ref()
249243
.map_or(String::new(), |b| format!("/tree/{b}"));

nix-builder/pkgs/kernel-abi-check/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ rustPlatform.buildRustPackage {
3333
cargoLock = {
3434
lockFile = ../../../Cargo.lock;
3535
outputHashes = {
36-
"huggingface-hub-0.0.1" = "sha256-By8b1NUPWu+XF3Om1NcEO+o2qdZUco+FxvrJGNRqxWs=";
36+
"hf-hub-1.0.0" = "sha256-XJVbG/dfxeSaTvyZMqB/6oF0I5cqKXIXzG5Zq00xmnk=";
3737
};
3838
};
3939

nix-builder/pkgs/kernel-builder/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ rustPlatform.buildRustPackage {
5252
cargoLock = {
5353
lockFile = ../../../Cargo.lock;
5454
outputHashes = {
55-
"huggingface-hub-0.0.1" = "sha256-By8b1NUPWu+XF3Om1NcEO+o2qdZUco+FxvrJGNRqxWs=";
55+
"hf-hub-1.0.0" = "sha256-XJVbG/dfxeSaTvyZMqB/6oF0I5cqKXIXzG5Zq00xmnk=";
5656
};
5757
};
5858

nix-builder/pkgs/python-modules/kernel-abi-check/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ buildPythonPackage {
3737
cargoDeps = rustPlatform.importCargoLock {
3838
lockFile = ../../../../Cargo.lock;
3939
outputHashes = {
40-
"huggingface-hub-0.0.1" = "sha256-By8b1NUPWu+XF3Om1NcEO+o2qdZUco+FxvrJGNRqxWs=";
40+
"hf-hub-1.0.0" = "sha256-XJVbG/dfxeSaTvyZMqB/6oF0I5cqKXIXzG5Zq00xmnk=";
4141
};
4242
};
4343

nix-builder/pkgs/python-modules/kernels-data/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ buildPythonPackage {
3535
cargoDeps = rustPlatform.importCargoLock {
3636
lockFile = ../../../../Cargo.lock;
3737
outputHashes = {
38-
"huggingface-hub-0.0.1" = "sha256-By8b1NUPWu+XF3Om1NcEO+o2qdZUco+FxvrJGNRqxWs=";
38+
"hf-hub-1.0.0" = "sha256-XJVbG/dfxeSaTvyZMqB/6oF0I5cqKXIXzG5Zq00xmnk=";
3939
};
4040
};
4141

0 commit comments

Comments
 (0)