mirror of
https://github.com/nix-community/nurl.git
synced 2024-09-11 10:10:39 +03:00
fetchPypi support
This commit is contained in:
parent
f54eda248c
commit
619a655cba
@ -104,6 +104,7 @@ pub enum FetcherFunction {
|
||||
FetchFromRepoOrCz,
|
||||
FetchFromSourcehut,
|
||||
FetchHex,
|
||||
FetchPypi,
|
||||
Fetchgit,
|
||||
Fetchhg,
|
||||
Fetchsvn,
|
||||
|
@ -8,6 +8,7 @@ mod gitiles;
|
||||
mod gitlab;
|
||||
mod hex;
|
||||
mod hg;
|
||||
mod pypi;
|
||||
mod repo_or_cz;
|
||||
mod sourcehut;
|
||||
mod svn;
|
||||
@ -22,6 +23,7 @@ pub use gitiles::FetchFromGitiles;
|
||||
pub use gitlab::FetchFromGitLab;
|
||||
pub use hex::FetchHex;
|
||||
pub use hg::Fetchhg;
|
||||
pub use pypi::FetchPypi;
|
||||
pub use repo_or_cz::FetchFromRepoOrCz;
|
||||
pub use sourcehut::FetchFromSourcehut;
|
||||
pub use svn::Fetchsvn;
|
||||
@ -86,6 +88,7 @@ pub enum FetcherDispatch<'a> {
|
||||
FetchFromRepoOrCz(FetchFromRepoOrCz),
|
||||
FetchFromSourcehut(FetchFromSourcehut<'a>),
|
||||
FetchHex(FetchHex),
|
||||
FetchPypi(FetchPypi),
|
||||
Fetchgit(Fetchgit),
|
||||
Fetchhg(Fetchhg),
|
||||
Fetchsvn(Fetchsvn),
|
||||
|
28
src/fetcher/pypi.rs
Normal file
28
src/fetcher/pypi.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use crate::{
|
||||
impl_fetcher,
|
||||
simple::{SimpleFetcher, SimpleUrlFetcher},
|
||||
Url,
|
||||
};
|
||||
|
||||
pub struct FetchPypi;
|
||||
impl_fetcher!(FetchPypi);
|
||||
|
||||
impl<'a> SimpleFetcher<'a, 1> for FetchPypi {
|
||||
const KEYS: [&'static str; 1] = ["pname"];
|
||||
const NAME: &'static str = "fetchPypi";
|
||||
const REV_KEY: &'static str = "version";
|
||||
|
||||
fn get_values(&self, url: &'a Url<'a>) -> Option<[&'a str; 1]> {
|
||||
let pname = url.path_segments().nth(1)?;
|
||||
(!pname.is_empty()).then_some([pname])
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SimpleUrlFetcher<'a, 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")
|
||||
}
|
||||
}
|
16
src/main.rs
16
src/main.rs
@ -16,8 +16,8 @@ use crate::{
|
||||
cli::{FetcherFunction, Opts},
|
||||
fetcher::{
|
||||
BuiltinsFetchGit, FetchCrate, FetchFromBitbucket, FetchFromGitHub, FetchFromGitLab,
|
||||
FetchFromGitea, FetchFromGitiles, FetchFromRepoOrCz, FetchFromSourcehut, FetchHex, Fetcher,
|
||||
FetcherDispatch, Fetchgit, Fetchhg, Fetchsvn,
|
||||
FetchFromGitea, FetchFromGitiles, FetchFromRepoOrCz, FetchFromSourcehut, FetchHex,
|
||||
FetchPypi, Fetcher, FetcherDispatch, Fetchgit, Fetchhg, Fetchsvn,
|
||||
},
|
||||
};
|
||||
|
||||
@ -165,6 +165,11 @@ fn main() -> Result<()> {
|
||||
bail!("fetchHex only supports hex.pm");
|
||||
}
|
||||
|
||||
(None | Some(FetcherFunction::FetchPypi), Some("pypi.org"), _) => FetchPypi.into(),
|
||||
(Some(FetcherFunction::FetchPypi), ..) => {
|
||||
bail!("fetchPypi only supports pypi.org");
|
||||
}
|
||||
|
||||
(None | Some(FetcherFunction::Fetchgit), _, Scheme::Git) => Fetchgit(GitScheme::Yes).into(),
|
||||
(None | Some(FetcherFunction::Fetchgit), _, Scheme::Ext(scheme))
|
||||
if scheme.starts_with("git+") =>
|
||||
@ -201,7 +206,12 @@ fn main() -> Result<()> {
|
||||
FetcherFunction::FetchFromRepoOrCz => {
|
||||
bail!("fetchFromRepoOrCz only supports repo.or.cz");
|
||||
}
|
||||
FetcherFunction::FetchHex => FetchHex.into(),
|
||||
FetcherFunction::FetchHex => {
|
||||
bail!("fetchHex only supports hex.pm");
|
||||
}
|
||||
FetcherFunction::FetchPypi => {
|
||||
bail!("fetchPypi only supports pypi.org");
|
||||
}
|
||||
FetcherFunction::Fetchgit => Fetchgit(GitScheme::No).into(),
|
||||
FetcherFunction::Fetchhg => Fetchhg(false).into(),
|
||||
FetcherFunction::Fetchsvn => Fetchsvn.into(),
|
||||
|
5
tests/cmd/fetcher/pypi.stdout
Normal file
5
tests/cmd/fetcher/pypi.stdout
Normal file
@ -0,0 +1,5 @@
|
||||
fetchPypi {
|
||||
pname = "requests";
|
||||
version = "2.20.0";
|
||||
hash = "sha256-mdz9qusXyvblJvMrant4BGFRKrPx2ZIYeAFpTLpCdww=";
|
||||
}
|
1
tests/cmd/fetcher/pypi.toml
Normal file
1
tests/cmd/fetcher/pypi.toml
Normal file
@ -0,0 +1 @@
|
||||
args = ["https://pypi.org/project/requests", "2.20.0"]
|
Loading…
Reference in New Issue
Block a user