mirror of
https://github.com/nix-community/nurl.git
synced 2024-10-26 12:04:01 +03:00
optimize fetchPypi with extension
specified
This commit is contained in:
parent
370a9c983c
commit
467dbfbe84
@ -1,8 +1,6 @@
|
||||
use crate::{
|
||||
impl_fetcher,
|
||||
simple::{SimpleFetcher, SimpleUrlFetcher},
|
||||
Url,
|
||||
};
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::{impl_fetcher, prefetch::url_prefetch, simple::SimpleFetcher, Url};
|
||||
|
||||
pub struct FetchPypi;
|
||||
impl_fetcher!(FetchPypi);
|
||||
@ -18,11 +16,27 @@ impl<'a> SimpleFetcher<'a, 1> for FetchPypi {
|
||||
}
|
||||
}
|
||||
|
||||
impl SimpleUrlFetcher<'_, 1> for FetchPypi {
|
||||
const UNPACK: bool = false;
|
||||
|
||||
fn get_url(&self, [pname]: &[&str; 1], version: &str) -> String {
|
||||
let Some(first) = pname.chars().next() else { unreachable!(); };
|
||||
format!("https://pypi.org/packages/source/{first}/{pname}/{pname}-{version}.tar.gz")
|
||||
impl FetchPypi {
|
||||
fn fetch(
|
||||
&self,
|
||||
values @ [pname]: &[&str; 1],
|
||||
version: &str,
|
||||
submodules: bool,
|
||||
args: &[(String, String)],
|
||||
args_str: &[(String, String)],
|
||||
nixpkgs: String,
|
||||
) -> Result<String> {
|
||||
match (args, args_str) {
|
||||
([], []) => url_prefetch(get_url(pname, version, "tar.gz"), false),
|
||||
([], [(key, ext)]) if key == "extension" => {
|
||||
url_prefetch(get_url(pname, version, ext), false)
|
||||
}
|
||||
_ => self.fetch_fod(values, version, submodules, args, args_str, nixpkgs),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_url(pname: &str, version: &str, ext: &str) -> String {
|
||||
let Some(first) = pname.chars().next() else { unreachable!(); };
|
||||
format!("https://pypi.org/packages/source/{first}/{pname}/{pname}-{version}.{ext}")
|
||||
}
|
||||
|
6
tests/cmd/fetcher/pypi/extension.stdout
Normal file
6
tests/cmd/fetcher/pypi/extension.stdout
Normal file
@ -0,0 +1,6 @@
|
||||
fetchPypi {
|
||||
pname = "nltk";
|
||||
version = "3.8";
|
||||
hash = "sha256-dLMIJqN9eNU0JxBbvQN92IAlG+Jp/KZO5TCDikbtVfw=";
|
||||
extension = "zip";
|
||||
}
|
1
tests/cmd/fetcher/pypi/extension.toml
Normal file
1
tests/cmd/fetcher/pypi/extension.toml
Normal file
@ -0,0 +1 @@
|
||||
args = ["https://pypi.org/project/nltk", "3.8", "--arg-str", "extension", "zip"]
|
Loading…
Reference in New Issue
Block a user