Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Formating & Merge Conflicts
  • Loading branch information
Allstreamer committed Aug 9, 2022
commit a89442678837dc2a41a041e1f95dcdcc7797fb0f
104 changes: 5 additions & 99 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@ repository = "https://github.com/John15321/rust-pip"

[dependencies]
anyhow = { version = "1.0.58", features = ["backtrace"] }
clap = { version = "3.2", features = ["derive"] }
reqwest = { version = "0.11", features = ["blocking", "json"] }
structopt = { version = "0.3.26", features = ["color"] }
strum = "0.24.1"
strum_macros = "0.24.2"
<<<<<<< Updated upstream
=======
log = "0.4"
strum = { version = "0.24.1", features = ["derive"] }
serde = {version = "1", features = ["derive"]}
serde_json = "1.0"
regex = "1"
lazy_static = "1.4.0"
pomsky-macro = "0.6.0"

>>>>>>> Stashed changes


[dev-dependencies]
12 changes: 5 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use std::path::PathBuf;
use structopt::StructOpt;
use clap::{AppSettings, Parser};

mod package_version;

/// Python package manager written in Rust
#[derive(Parser, Debug)]
#[clap(global_setting = AppSettings::DeriveDisplayOrder)]

enum Opt {
/// Install packages.
Install {},
/// Download packages.
Download {
#[structopt(short = "n", long = "name")]
#[clap(short = 'n', long = "name")]
name: String,
#[structopt(short = "i", long = "index", default_value = "https://pypi.org/")]
#[clap(short = 'i', long = "index", default_value = "https://pypi.org/")]
index: String,
},
/// Uninstall packages.
Expand Down Expand Up @@ -47,10 +45,10 @@ enum Opt {
Help {},
}

fn download_package(package_name: String, package_index: &String) {}
fn download_package(_package_name: String, _package_index: &str) {}

fn main() {
let opt = Opt::from_args();
let opt = Opt::parse();
println!("{:#?}", opt);

match opt {
Expand Down
47 changes: 25 additions & 22 deletions src/package_version.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Handling of pep-440
use serde::{Deserialize, Serialize};
use anyhow::{Result};
use anyhow::Result;
use lazy_static::lazy_static;
use pomsky_macro::pomsky;
use serde::{Deserialize, Serialize};

static VALIDATION_REGEX:&'static str = pomsky!(
static VALIDATION_REGEX: &'static str = pomsky!(
"v"?

(:epoch(['0'-'9']+)'!')?
Expand Down Expand Up @@ -72,7 +72,6 @@ pub struct VersionRelease {
minor: u32,
}


#[derive(Debug, Serialize, Deserialize)]
pub struct PackageVersion {
epoch: Option<u32>,
Expand All @@ -84,12 +83,11 @@ pub struct PackageVersion {
}

impl PackageVersion {
pub fn new(version: &str) -> Result<Self>
{
pub fn new(version: &str) -> Result<Self> {
lazy_static! {
// Safe to unwrap since Regex is predefined
// Regex as defined in PEP-0440
static ref VERSION_VALIDATIOR: regex::Regex =
static ref VERSION_VALIDATIOR: regex::Regex =
regex::Regex::new(VALIDATION_REGEX).unwrap();
}

Expand All @@ -100,7 +98,7 @@ impl PackageVersion {

let epoch: Option<u32> = match version_match.name("epoch") {
Some(v) => Some(v.as_str().parse::<u32>()?),
None => None
None => None,
};

let release: VersionRelease = match version_match.name("release") {
Expand All @@ -111,15 +109,15 @@ impl PackageVersion {
major: split[0].parse::<u32>()?,
minor: split[1].parse::<u32>()?,
}
}else {
} else {
VersionRelease {
major: v.as_str().parse::<u32>()?,
minor: 0,
}
}
},
}
// There always has to be at least a major version
None => anyhow::bail!("Failed to decode version {}", version)
None => anyhow::bail!("Failed to decode version {}", version),
};

let pre: Option<PreHeader> = match version_match.name("pre") {
Expand All @@ -141,29 +139,36 @@ impl PackageVersion {
"pre" => Some(PreHeader::Preview(pre_n)),
_ => None,
}
},
None => None
}
None => None,
};

// TODO!
let post: Option<String> = match version_match.name("post") {
Some(v) => Some(v.as_str().to_string()),
None => None
None => None,
};

// TODO!
let dev: Option<String> = match version_match.name("dev") {
Some(v) => Some(v.as_str().to_string()),
None => None
None => None,
};

// TODO!
let local: Option<String> = match version_match.name("local") {
Some(v) => Some(v.as_str().to_string()),
None => None
None => None,
};

Ok(Self{ epoch, release, pre, post, dev, local })

Ok(Self {
epoch,
release,
pre,
post,
dev,
local,
})
}
}

Expand Down Expand Up @@ -199,16 +204,14 @@ mod tests {
for version in versions {
match PackageVersion::new(version) {
Ok(v) => println!("{:?}", v),
Err(e) => panic!("Oh no {}", e)
Err(e) => panic!("Oh no {}", e),
}
}
}

#[test]
fn check_pep440_negative() {
let versions = vec![
"not a version",
];
let versions = vec!["not a version"];

for version in versions {
match PackageVersion::new(version) {
Expand Down