Skip to content

Commit

Permalink
Cleaned up some Windows bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
David-OConnor committed Aug 11, 2019
1 parent 77da410 commit 341d4eb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
8 changes: 2 additions & 6 deletions README.md
Expand Up @@ -60,15 +60,12 @@ how to specify dependencies in this `Cargo.toml`-inspired
and will be added to `pyproject.toml`.
- `pypackage install numpy==1.16.4 matplotlib>=3.1.` - Example with multiple dependencies, and specified versions
- `pypackage uninstall toolz` - Remove a dependency
- `pypackage install ipython -b` - Install a dependency which includes a binary script.
(eg `ipython`, `black`, `mypy`, `poetry` etc). These won't work properly if you don't include
the `-b` or `--bin` flag.


### Running REPL and Python files in the environment:
- `pypackage python` - Run a Python REPL
- `pypackage python main.py` - Run a python file
- `pypackage black`, `pypackage ipython` etc - Run a custom binary, if it's installed.


### Building and publishing:
- `pypackage package` - Package for distribution (uses setuptools internally, and
Expand All @@ -80,8 +77,7 @@ builds both source and binary if applicable.)
- `pypackage init` - Create a `pyproject.toml` file in an existing project directory. Pull info from
`requirements.text`, `Pipfile` etc as required.
a project: a readme, pyproject.toml, and directory for source code
- `pypackage list` - Run `pip list` in the environment
- `pypackage version` - Get the current version of this tool
- `pypackage -V` - Get the current version of this tool
- `pypackage help` Get help, including a list of available commands

## How dependencies are resolved
Expand Down
10 changes: 10 additions & 0 deletions pypackage.lock
@@ -1,3 +1,13 @@
[[package]]
name = "siunits"
version = "0.0.4"
source = "pypi+https://pypi.org/pypi/siunits/0.0.4/json"

[[package]]
name = "backcall"
version = "0.1.0"
source = "pypi+https://pypi.org/pypi/backcall/0.1.0/json"

[[package]]
name = "fplot"
version = "0.2.3"
Expand Down
2 changes: 1 addition & 1 deletion src/install.rs
Expand Up @@ -49,7 +49,7 @@ fn sha256_digest<R: io::Read>(mut reader: R) -> Result<digest::Digest, std::io::
/// If the setup.py file uses `distutils.core`, replace with `setuptools`. This is required to build
/// a wheel. Eg, replace `from distutils.core import setup` with `from setuptools import setup`.
fn replace_distutils(setup_path: &PathBuf) {
let mut setup_text =
let setup_text =
fs::read_to_string(setup_path).expect("Can't find setup.py on a source distribution.");

let re = Regex::new(r"distutils.core").unwrap();
Expand Down
19 changes: 16 additions & 3 deletions src/main.rs
Expand Up @@ -396,7 +396,7 @@ fn find_py_alias() -> Result<(String, Version), AliasError> {
}
}

match possible_aliases.len() {
match found_aliases.len() {
0 => Err(AliasError {
details: "Can't find Python on the path.".into(),
}),
Expand Down Expand Up @@ -523,7 +523,7 @@ fn create_venv(cfg_v: Option<&Constraint>, pyypackage_dir: &PathBuf) -> Version
"wheel",
])
.spawn()
.expect("Problem installing Wheel");
.expect("Problem installing `wheel`");

py_ver_from_alias
}
Expand Down Expand Up @@ -893,6 +893,18 @@ py_version = \"3.7\"",
// Add pacakge names to `pyproject.toml` if needed. Then sync installed packages
// and `pyproject.lock` with the `pyproject.toml`.
SubCommand::Install { packages, bin } => {
Command::new("python.exe")
.current_dir(&bin_path)
.args(&[
"-m",
"pip",
"install",
// "--quiet",
"wheel",
])
.spawn()
.expect("Problem installing `wheel`");

let mut added_reqs = vec![];
for p in packages.into_iter() {
match Req::from_str(&p, false) {
Expand Down Expand Up @@ -1007,7 +1019,8 @@ py_version = \"3.7\"",
&installed,
&py_vers,
);
println!("{}{}", Colored::Fg(Color::Green), "Installation complete",);
// todo: Utility fn to simplify colored-output code
println!("{}{}{}", Colored::Fg(Color::Green), "Installation complete", Colored::Fg(Color::Reset));
}
SubCommand::Uninstall { packages } => {
let removed_reqs: Vec<String> = packages
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Expand Up @@ -6,7 +6,7 @@ use std::{env, path::PathBuf, process, thread, time};
/// A convenience function
pub fn abort(message: &str) {
{
println!("{}{}", Colored::Fg(Color::Red), message);
println!("{}{}{}", Colored::Fg(Color::Red), message, Colored::Fg(Color::Reset));
process::exit(1)
}
}
Expand All @@ -23,7 +23,7 @@ pub fn possible_py_versions() -> Vec<Version> {

pub fn venv_exists(venv_path: &PathBuf) -> bool {
(venv_path.join("bin/python").exists() && venv_path.join("bin/pip").exists())
|| (venv_path.join("Scripts/python").exists() && venv_path.join("Scripts/pip").exists())
|| (venv_path.join("Scripts/python.exe").exists() && venv_path.join("Scripts/pip.exe").exists())
}

/// Checks whether the path is under `/bin` (Linux generally) or `/Scripts` (Windows generally)
Expand Down

0 comments on commit 341d4eb

Please sign in to comment.