Skip to content

Commit

Permalink
Merge branch 'master' into pyflow-script-subargs
Browse files Browse the repository at this point in the history
  • Loading branch information
David-OConnor authored May 29, 2021
2 parents 6ce2d4a + fe3f0c9 commit 94a93f4
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 437 deletions.
629 changes: 312 additions & 317 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{dep_types::Req, util};
use regex::Regex;
use std::collections::HashMap;
use std::{env, fs, path::PathBuf, process::Command};
use std::{collections::HashMap, path::Path};
use std::{env, fs, process::Command};
use termcolor::Color;

// https://packaging.python.org/tutorials/packaging-projects/
Expand Down Expand Up @@ -217,7 +217,7 @@ pub fn build(
};
}

pub(crate) fn publish(bin_path: &PathBuf, cfg: &crate::Config) {
pub(crate) fn publish(bin_path: &Path, cfg: &crate::Config) {
let repo_url = match cfg.package_url.clone() {
Some(pu) => {
let mut r = pu;
Expand Down
5 changes: 3 additions & 2 deletions src/dep_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ fn get_req_cache_multiple(
let url = "https://pydeps.herokuapp.com/multiple/";
// let url = "http://localhost:8000/multiple/";

Ok(reqwest::Client::new()
reqwest::Client::new()
.post(url)
.json(&MultipleBody {
packages: packages2,
})
.send()?
.json()?)
.json()
}

/// Helper fn for `guess_graph`.
Expand Down Expand Up @@ -244,6 +244,7 @@ fn fetch_req_data(

// Build a graph: Start by assuming we can pick the newest compatible dependency at each step.
// If unable to resolve this way, subsequently run this with additional deconfliction reqs.
#[allow(clippy::clippy::too_many_arguments)]
fn guess_graph(
parent_id: u32,
reqs: &[Req],
Expand Down
46 changes: 21 additions & 25 deletions src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ pub struct Tool {
pub poetry: Option<Poetry>,
}

#[serde(untagged)]
#[derive(Debug, Deserialize)]
#[serde(untagged)]
/// Allows use of both Strings, ie "ipython = "^7.7.0", and maps: "ipython = {version = "^7.7.0", extras=["qtconsole"]}"
pub enum DepComponentWrapper {
A(String),
B(DepComponent),
}

#[serde(untagged)]
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum DepComponentWrapperPoetry {
A(String),
B(DepComponentPoetry),
Expand Down Expand Up @@ -323,18 +323,16 @@ pub fn parse_req_dot_text(cfg: &mut Config, path: &Path) {
Err(_) => return,
};

for line in BufReader::new(file).lines() {
if let Ok(l) = line {
match Req::from_pip_str(&l) {
Some(r) => {
cfg.reqs.push(r.clone());
}
None => util::print_color(
&format!("Problem parsing {} from requirements.txt", l),
Color::Red,
),
};
}
for line in BufReader::new(file).lines().flatten() {
match Req::from_pip_str(&line) {
Some(r) => {
cfg.reqs.push(r.clone());
}
None => util::print_color(
&format!("Problem parsing {} from requirements.txt", line),
Color::Red,
),
};
}
}

Expand All @@ -343,17 +341,15 @@ pub fn change_py_vers(cfg_path: &Path, specified: &Version) {
let f = fs::File::open(&cfg_path)
.expect("Unable to read pyproject.toml while adding Python version");
let mut new_data = String::new();
for line in BufReader::new(f).lines() {
if let Ok(l) = line {
if l.starts_with("py_version") {
new_data.push_str(&format!(
"py_version = \"{}.{}\"\n",
specified.major, specified.minor
));
} else {
new_data.push_str(&l);
new_data.push('\n');
}
for line in BufReader::new(f).lines().flatten() {
if line.starts_with("py_version") {
new_data.push_str(&format!(
"py_version = \"{}.{}\"\n",
specified.major, specified.minor
));
} else {
new_data.push_str(&line);
new_data.push('\n');
}
}

Expand Down
40 changes: 18 additions & 22 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,18 @@ pub fn setup_scripts(name: &str, version: &Version, lib_path: &Path, entry_pt_pa

if let Ok(ep_file) = fs::File::open(&dist_info_path.join("entry_points.txt")) {
let mut in_scripts_section = false;
for line in io::BufReader::new(ep_file).lines() {
if let Ok(l) = line {
if l.contains("[console_scripts]") {
in_scripts_section = true;
continue;
}
if l.starts_with('[') {
// no longer in scripts section.
break;
}
if in_scripts_section && !l.is_empty() {
// Remove potential leading spaces; have seen indents included.
scripts.push(l.clone().replace(" ", ""));
}
for line in io::BufReader::new(ep_file).lines().flatten() {
if line.contains("[console_scripts]") {
in_scripts_section = true;
continue;
}
if line.starts_with('[') {
// no longer in scripts section.
break;
}
if in_scripts_section && !line.is_empty() {
// Remove potential leading spaces; have seen indents included.
scripts.push(line.clone().replace(" ", ""));
}
}
} // else: Probably no scripts.
Expand Down Expand Up @@ -162,6 +160,7 @@ pub fn setup_scripts(name: &str, version: &Version, lib_path: &Path, entry_pt_pa

/// Download and install a package. For wheels, we can just extract the contents into
/// the lib folder. For source dists, make a wheel first.
#[allow(clippy::clippy::too_many_arguments)]
pub fn download_and_install_package(
name: &str,
version: &Version,
Expand Down Expand Up @@ -228,10 +227,9 @@ pub fn download_and_install_package(
// We must re-open the file after computing the hash.
let archive_file = util::open_archive(&archive_path);

let rename = match rename.as_ref() {
Some((_, new)) => Some((name.to_owned(), new.to_owned())),
None => None,
};
let rename = rename
.as_ref()
.map(|(_, new)| (name.to_owned(), new.to_owned()));

match package_type {
PackageType::Wheel => {
Expand Down Expand Up @@ -526,10 +524,8 @@ pub fn uninstall(name_ins: &str, vers_ins: &Version, lib_path: &Path) {
let folder_names = match fs::File::open(dist_info_path.join("top_level.txt")) {
Ok(f) => {
let mut names = vec![];
for line in io::BufReader::new(f).lines() {
if let Ok(l) = line {
names.push(l);
}
for line in io::BufReader::new(f).lines().flatten() {
names.push(line);
}
names
}
Expand Down
37 changes: 16 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,7 @@ fn sync_deps(
util::standardize_name(&lp.name),
Version::from_str(&lp.version).expect("Problem parsing lock version"),
),
match &lp.rename {
// todo back to our custom type?
Some(rn) => Some(parse_lockpack_rename(rn)),
None => None,
},
lp.rename.as_ref().map(|rn| parse_lockpack_rename(rn)),
)
})
.collect();
Expand Down Expand Up @@ -982,22 +978,20 @@ fn find_deps_from_script(file_path: &Path) -> Vec<String> {
let re = Regex::new(r"^__requires__\s*=\s*\[(.*?)\]$").unwrap();

let mut result = vec![];
for line in BufReader::new(f).lines() {
if let Ok(l) = line {
if let Some(c) = re.captures(&l) {
let deps_list = c.get(1).unwrap().as_str().to_owned();
let deps: Vec<&str> = deps_list.split(',').collect();
result = deps
.into_iter()
.map(|d| {
d.to_owned()
.replace(" ", "")
.replace("\"", "")
.replace("'", "")
})
.filter(|d| !d.is_empty())
.collect();
}
for line in BufReader::new(f).lines().flatten() {
if let Some(c) = re.captures(&line) {
let deps_list = c.get(1).unwrap().as_str().to_owned();
let deps: Vec<&str> = deps_list.split(',').collect();
result = deps
.into_iter()
.map(|d| {
d.to_owned()
.replace(" ", "")
.replace("\"", "")
.replace("'", "")
})
.filter(|d| !d.is_empty())
.collect();
}
}

Expand Down Expand Up @@ -1118,6 +1112,7 @@ fn run_script(

/// Function used by `Install` and `Uninstall` subcommands to syn dependencies with
/// the config and lock files.
#[allow(clippy::clippy::too_many_arguments)]
fn sync(
paths: &util::Paths,
lockpacks: &[LockPackage],
Expand Down
16 changes: 8 additions & 8 deletions src/py_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ impl PyVers {
/// todo: How cross-compat are these? Eg work across diff versions of Ubuntu?
/// todo: 32-bit
#[derive(Clone, Copy, Debug)]
#[allow(dead_code)]
enum Os {
// Don't confuse with crate::Os
Ubuntu, // Builds on Ubuntu 18.04 work on Ubuntu 19.04, Debian, Arch, and Kali
Centos, // Will this work on Red Hat and Fedora as well?
#[cfg(target_os = "windows")]
Windows,
Mac,
}
Expand Down Expand Up @@ -354,16 +356,14 @@ fn find_installed_versions(pyflow_dir: &Path) -> Vec<Version> {
for entry in pyflow_dir
.read_dir()
.expect("Can't open python installs path")
.flatten()
{
if let Ok(entry) = entry {
if !entry.path().is_dir() {
continue;
}
if !entry.path().is_dir() {
continue;
}

if let Some(v) = commands::find_py_version(entry.path().join(py_name).to_str().unwrap())
{
result.push(v);
}
if let Some(v) = commands::find_py_version(entry.path().join(py_name).to_str().unwrap()) {
result.push(v);
}
}
result
Expand Down
Loading

0 comments on commit 94a93f4

Please sign in to comment.