From 6f607da3f309db3af2990142a10d29fd2fedba02 Mon Sep 17 00:00:00 2001 From: David O'Connor Date: Sun, 24 Nov 2019 13:42:18 -0500 Subject: [PATCH] Always sync packages before commands --- CHANGELOG.md | 4 ++- README.md | 20 +++++++-------- snapcraft.yaml | 2 +- src/main.rs | 61 +++++++++++++++++++++++++--------------------- src/py_versions.rs | 4 ++- src/util.rs | 24 ++++++++++++++++++ 6 files changed, 73 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c10656..a9d3605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog -## v0.2.0 +## v0.2.1 +- Running `pyflow install` is now no longer required; Running `pyflow`, `pyflow list` etc +will now install dependencies as required from `pyproject.toml`. - `pyflow new` now asks for the Python version instead of using a default. - Now searches parent directories for `pyproject.toml`, if we can't find one in the current path. diff --git a/README.md b/README.md index 765747c..ff54034 100644 --- a/README.md +++ b/README.md @@ -26,19 +26,19 @@ and [Pep 518 (pyproject.toml)](https://www.python.org/dev/peps/pep-0518/), and s ## Installation - **Windows** - Download and run -[this installer](https://github.com/David-OConnor/pyflow/releases/download/0.1.9/pyflow-0.1.9-x86_64.msi). +[this installer](https://github.com/David-OConnor/pyflow/releases/download/0.2.1/pyflow-0.2.1-x86_64.msi). Or, if you have [Scoop](https://scoop.sh) installed, run `scoop install pyflow`. - **Ubuntu, or another Os that uses Snap** - Run `snap install pyflow --classic`. - **Ubuntu or Debian without Snap** - Download and run -[this deb](https://github.com/David-OConnor/pyflow/releases/download/0.1.9/pyflow_0.1.9_amd64.deb). +[this deb](https://github.com/David-OConnor/pyflow/releases/download/0.2.1/pyflow_0.2.1_amd64.deb). - **Fedora, CentOs, RedHat, or older versions of SUSE** - Download and run -[this rpm](https://github.com/David-OConnor/pyflow/releases/download/0.1.9/pyflow-0.1.9.x86_64.rpm). +[this rpm](https://github.com/David-OConnor/pyflow/releases/download/0.2.1/pyflow-0.2.1.x86_64.rpm). - **A different Linux distro** - Download this -[standalone binary](https://github.com/David-OConnor/pyflow/releases/download/0.1.9/pyflow) +[standalone binary](https://github.com/David-OConnor/pyflow/releases/download/0.2.1/pyflow) and place it somewhere accessible by the PATH. For example, `/usr/bin`. - **Mac** - Install Rust: `curl https://sh.rustup.rs -sSf | sh`, then run @@ -57,9 +57,6 @@ with the above ones, and it doesn't yet work with Mac. - *(Optional)* Run `pyflow init` in an existing project folder, or `pyflow new projname` to create a new project folder. `init` imports data from `requirements.txt` or `Pipfile`; `new` creates a folder with the basics. -- Run `pyflow install` in a project folder to sync dependencies with `pyproject.toml`, -or add dependencies to it. -This file will be created if it doesn't exist. - Run `pyflow` or `pyflow myfile.py` to run Python. @@ -188,7 +185,7 @@ Example contents: [tool.pyflow] py_version = "3.7" name = "runcible" -version = "0.1.9" +version = "0.2.1" authors = ["John Hackworth "] @@ -268,7 +265,8 @@ entry points for somone using the package, regardless of if they're using this t ### Managing dependencies: - `pyflow install` - Install all packages in `pyproject.toml`, and remove ones not (recursively) specified. If an environment isn't already set up for the version specified in `pyproject.toml`, sets one up. If -no version is specified, it asks you. +no version is specified, it asks you. Note that this command isn't required to sync dependencies; any relevant `pyflow` +command will do so automatically. - `pyflow install requests` - If you specify one or more packages after `install`, those packages will be added to `pyproject.toml` and installed. You can use the `--dev` flag to install dev dependencies. eg: `pyflow install black --dev`. @@ -370,7 +368,7 @@ In order to build and publish your project, additional info is needed in [tool.pyflow] name = "everythingkiller" py_version = "3.6" -version = "0.1.9" +version = "0.2.1" authors = ["Fraa Erasmas "] description = "Small, but packs a punch!" homepage = "https://everything.math" @@ -393,7 +391,7 @@ activate = "jeejah:activate" [tool.pyflow.dependencies] numpy = "^1.16.4" -manimlib = "0.1.9" +manimlib = "0.2.1" ipython = {version = "^7.7.0", extras=["qtconsole"]} diff --git a/snapcraft.yaml b/snapcraft.yaml index f6dd8fa..d31f5f1 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1,5 +1,5 @@ name: pyflow -version: 0.1.9 +version: 0.2.1 license: MIT summary: A Python installation and dependency manager. description: | diff --git a/src/main.rs b/src/main.rs index 9d759ed..9c142c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1054,13 +1054,14 @@ fn sync( .collect(); // todo: Only show this when needed. + // todo: Temporarily? Removed. // Powershell doesn't like emojis - #[cfg(target_os = "windows")] - println!("Resolving dependencies..."); - #[cfg(target_os = "linux")] - println!("🔍 Resolving dependencies..."); - #[cfg(target_os = "macos")] - println!("🔍 Resolving dependencies..."); + // #[cfg(target_os = "windows")] + // println!("Resolving dependencies..."); + // #[cfg(target_os = "linux")] + // println!("🔍 Resolving dependencies..."); + // #[cfg(target_os = "macos")] + // println!("🔍 Resolving dependencies..."); // Dev reqs and normal reqs are both installed here; we only ommit dev reqs // when packaging. @@ -1307,8 +1308,6 @@ fn main() { let pypackages_path = proj_path.join("__pypackages__"); let lock_path = &proj_path.join(lock_filename); - println!("PPP: {:?}", &pypackages_path); - let mut cfg = Config::from_file(&cfg_path).unwrap_or_default(); cfg.populate_path_subreqs(); @@ -1415,6 +1414,17 @@ fn main() { let lockpacks = lock.package.unwrap_or_else(|| vec![]); + sync( + &paths, + &lockpacks, + &cfg.reqs, + &cfg.dev_reqs, + &util::find_dont_uninstall(&cfg.reqs, &cfg.dev_reqs), + os, + &py_vers, + &lock_path, + ); + // Now handle subcommands that require info about the environment match subcmd { // Add pacakge names to `pyproject.toml` if needed. Then sync installed packages @@ -1434,25 +1444,7 @@ fn main() { // Merge reqs added via cli with those in `pyproject.toml`. let (updated_reqs, up_dev_reqs) = util::merge_reqs(&packages, dev, &cfg, &cfg_path); - // We've removed the git repos from packages to install form pypi, but make - // sure we flag them as not-to-uninstall. - let mut dont_uninstall: Vec = updated_reqs - .clone() - .into_iter() - .filter_map(|r| { - if r.git.is_some() || r.path.is_some() { - Some(r.name) - } else { - None - } - }) - .collect(); - - for r in &up_dev_reqs { - if r.git.is_some() || r.path.is_some() { - dont_uninstall.push(r.name.to_owned()); - } - } + let dont_uninstall = util::find_dont_uninstall(&updated_reqs, &up_dev_reqs); // git_reqs is used to store requirements from packages installed via git. let mut git_reqs = vec![]; // For path reqs too. @@ -1554,7 +1546,20 @@ fn main() { abort("Problem running Python"); } } - SubCommand::Package { extras } => build::build(&lockpacks, &paths, &cfg, &extras), + SubCommand::Package { extras } => { + sync( + &paths, + &lockpacks, + &cfg.reqs, + &cfg.dev_reqs, + &util::find_dont_uninstall(&cfg.reqs, &cfg.dev_reqs), + os, + &py_vers, + &lock_path, + ); + + build::build(&lockpacks, &paths, &cfg, &extras) + } SubCommand::Publish {} => build::publish(&paths.bin, &cfg), SubCommand::Run { args } => { run_cli_tool(&paths.lib, &paths.bin, &vers_path, &cfg, args); diff --git a/src/py_versions.rs b/src/py_versions.rs index d818ed6..ac1335f 100644 --- a/src/py_versions.rs +++ b/src/py_versions.rs @@ -5,7 +5,7 @@ use crate::dep_types::Version; use crate::{install, util}; use crossterm::Color; use std::error::Error; -use std::{fmt, fs, io, path::Path, path::PathBuf}; +use std::{fmt, fs, io, path::Path}; /// Only versions we've built and hosted #[derive(Clone, Copy, Debug)] @@ -328,6 +328,7 @@ pub fn create_venv( ) -> Version { let os; let python_name; + #[allow(unused_mut)] let mut py_name; #[cfg(target_os = "windows")] { @@ -452,6 +453,7 @@ pub fn create_venv( .expect("Timed out waiting for venv to be created."); // Try 64 first; if not, use 32. + #[allow(unused_variables)] let lib = if vers_path.join(".venv").join("lib64").exists() { "lib64" } else { diff --git a/src/util.rs b/src/util.rs index f37a6ef..2082543 100644 --- a/src/util.rs +++ b/src/util.rs @@ -831,3 +831,27 @@ pub fn prompt_py_vers() -> Version { fallible_v_parse(&input) } + +/// We've removed the git repos from packages to install form pypi, but make +/// sure we flag them as not-to-uninstall. +pub fn find_dont_uninstall(reqs: &[Req], dev_reqs: &[Req]) -> Vec { + let mut result: Vec = reqs + .clone() + .into_iter() + .filter_map(|r| { + if r.git.is_some() || r.path.is_some() { + Some(r.name.to_owned()) + } else { + None + } + }) + .collect(); + + for r in dev_reqs { + if r.git.is_some() || r.path.is_some() { + result.push(r.name.to_owned()); + } + } + + result +}