fetchPypi support

This commit is contained in:
figsoda 2023-01-24 11:09:58 -05:00
parent f54eda248c
commit 619a655cba
6 changed files with 51 additions and 3 deletions

View File

@ -104,6 +104,7 @@ pub enum FetcherFunction {
FetchFromRepoOrCz, FetchFromRepoOrCz,
FetchFromSourcehut, FetchFromSourcehut,
FetchHex, FetchHex,
FetchPypi,
Fetchgit, Fetchgit,
Fetchhg, Fetchhg,
Fetchsvn, Fetchsvn,

View File

@ -8,6 +8,7 @@ mod gitiles;
mod gitlab; mod gitlab;
mod hex; mod hex;
mod hg; mod hg;
mod pypi;
mod repo_or_cz; mod repo_or_cz;
mod sourcehut; mod sourcehut;
mod svn; mod svn;
@ -22,6 +23,7 @@ pub use gitiles::FetchFromGitiles;
pub use gitlab::FetchFromGitLab; pub use gitlab::FetchFromGitLab;
pub use hex::FetchHex; pub use hex::FetchHex;
pub use hg::Fetchhg; pub use hg::Fetchhg;
pub use pypi::FetchPypi;
pub use repo_or_cz::FetchFromRepoOrCz; pub use repo_or_cz::FetchFromRepoOrCz;
pub use sourcehut::FetchFromSourcehut; pub use sourcehut::FetchFromSourcehut;
pub use svn::Fetchsvn; pub use svn::Fetchsvn;
@ -86,6 +88,7 @@ pub enum FetcherDispatch<'a> {
FetchFromRepoOrCz(FetchFromRepoOrCz), FetchFromRepoOrCz(FetchFromRepoOrCz),
FetchFromSourcehut(FetchFromSourcehut<'a>), FetchFromSourcehut(FetchFromSourcehut<'a>),
FetchHex(FetchHex), FetchHex(FetchHex),
FetchPypi(FetchPypi),
Fetchgit(Fetchgit), Fetchgit(Fetchgit),
Fetchhg(Fetchhg), Fetchhg(Fetchhg),
Fetchsvn(Fetchsvn), Fetchsvn(Fetchsvn),

28
src/fetcher/pypi.rs Normal file
View 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")
}
}

View File

@ -16,8 +16,8 @@ use crate::{
cli::{FetcherFunction, Opts}, cli::{FetcherFunction, Opts},
fetcher::{ fetcher::{
BuiltinsFetchGit, FetchCrate, FetchFromBitbucket, FetchFromGitHub, FetchFromGitLab, BuiltinsFetchGit, FetchCrate, FetchFromBitbucket, FetchFromGitHub, FetchFromGitLab,
FetchFromGitea, FetchFromGitiles, FetchFromRepoOrCz, FetchFromSourcehut, FetchHex, Fetcher, FetchFromGitea, FetchFromGitiles, FetchFromRepoOrCz, FetchFromSourcehut, FetchHex,
FetcherDispatch, Fetchgit, Fetchhg, Fetchsvn, FetchPypi, Fetcher, FetcherDispatch, Fetchgit, Fetchhg, Fetchsvn,
}, },
}; };
@ -165,6 +165,11 @@ fn main() -> Result<()> {
bail!("fetchHex only supports hex.pm"); 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::Git) => Fetchgit(GitScheme::Yes).into(),
(None | Some(FetcherFunction::Fetchgit), _, Scheme::Ext(scheme)) (None | Some(FetcherFunction::Fetchgit), _, Scheme::Ext(scheme))
if scheme.starts_with("git+") => if scheme.starts_with("git+") =>
@ -201,7 +206,12 @@ fn main() -> Result<()> {
FetcherFunction::FetchFromRepoOrCz => { FetcherFunction::FetchFromRepoOrCz => {
bail!("fetchFromRepoOrCz only supports repo.or.cz"); 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::Fetchgit => Fetchgit(GitScheme::No).into(),
FetcherFunction::Fetchhg => Fetchhg(false).into(), FetcherFunction::Fetchhg => Fetchhg(false).into(),
FetcherFunction::Fetchsvn => Fetchsvn.into(), FetcherFunction::Fetchsvn => Fetchsvn.into(),

View File

@ -0,0 +1,5 @@
fetchPypi {
pname = "requests";
version = "2.20.0";
hash = "sha256-mdz9qusXyvblJvMrant4BGFRKrPx2ZIYeAFpTLpCdww=";
}

View File

@ -0,0 +1 @@
args = ["https://pypi.org/project/requests", "2.20.0"]