Skip to content

Commit

Permalink
Always sync packages before commands
Browse files Browse the repository at this point in the history
  • Loading branch information
David-OConnor committed Nov 24, 2019
1 parent 1bfbd7f commit 6f607da
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 42 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.


Expand Down Expand Up @@ -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 <[email protected]>"]


Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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 <[email protected]>"]
description = "Small, but packs a punch!"
homepage = "https://everything.math"
Expand All @@ -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"]}


Expand Down
2 changes: 1 addition & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pyflow
version: 0.1.9
version: 0.2.1
license: MIT
summary: A Python installation and dependency manager.
description: |
Expand Down
61 changes: 33 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand All @@ -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<String> = 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.
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/py_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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")]
{
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
let mut result: Vec<String> = 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
}

0 comments on commit 6f607da

Please sign in to comment.