From cd4616f80b96b9b95eeb3401b7d86d5998926151 Mon Sep 17 00:00:00 2001 From: David O'Connor Date: Sat, 19 Oct 2019 14:15:33 +0000 Subject: [PATCH] added build script support; fixed some poetry parsing --- .gitignore | 1 - CHANGELOG.md | 5 ++++- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 5 +---- RELEASE_CHECKLIST.md | 2 +- pip/setup.py | 20 ++++++++++++++++++++ src/build.rs | 20 ++++++++++++++------ src/dep_resolution.rs | 5 +++-- src/dep_types.rs | 4 +++- src/files.rs | 8 +++++--- src/install.rs | 4 +++- src/main.rs | 20 ++++++++++++++++---- 13 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 pip/setup.py diff --git a/.gitignore b/.gitignore index 4e32646..88c63d8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ *.workspace.xml # Prevent generated and test files from being committed -setup.py requirements.txt Pipfile pyflow.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index 5034cc1..e6923d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,10 @@ ## v0.1.8 - Fixed a bug in auto-filling name and email in `pyflow init` and `pyflow new` - Running `pyflow` alone in a directory without a `pyproject.toml` will now no -longer attempt to initialize a project. +longer attempt to initialize a project +- Added support for specifying a build script +- Treat `python_version` on `pypi` as a caret requirement, if specified like `3.6`. +- Improved error messages ## v0.1.7 - Fixed bugs in `path` dependencies diff --git a/Cargo.lock b/Cargo.lock index 743f0ca..5865820 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -920,7 +920,7 @@ dependencies = [ [[package]] name = "pyflow" -version = "0.1.7" +version = "0.1.8" dependencies = [ "crossterm 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 75cdfd4..3f7e2cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyflow" -version = "0.1.7" +version = "0.1.8" authors = ["David O'Connor "] description = "A modern Python installation and dependency manager" license = "MIT" diff --git a/README.md b/README.md index a2b6653..677db7d 100644 --- a/README.md +++ b/README.md @@ -460,13 +460,10 @@ by Steve Dower. Click the folder-tree icon at the bottom of the pop-out window → Click the `+` icon at the bottom of the new pop-out window → Navigate to and select `(projname)/__pypackages__/3.x/lib` - sss - - If using VsCode: `Settings` → search `python extra paths` → +- If using VsCode: `Settings` → search `python extra paths` → `Edit in settings.json` → Add or modify the line: `"python.autoComplete.extraPaths": ["(projname)/__pypackages__/3.7/lib"]` -- Make sure the `pyflow` binary is accessible in your path. If installing -via a `deb`, `msi`, `snap`, `rpm`, or `Cargo`, this should be set up automatically. # References - [PEP 582 - Python local packages directory](https://www.python.org/dev/peps/pep-0582/) diff --git a/RELEASE_CHECKLIST.md b/RELEASE_CHECKLIST.md index 32abbd2..17ce140 100644 --- a/RELEASE_CHECKLIST.md +++ b/RELEASE_CHECKLIST.md @@ -13,7 +13,7 @@ links to reflect the latest version. 1. Commit and push the repo 1. Check that CI pipeline passed 1. Run `cargo package` and `cargo publish` (Allows installation via cargo) -1. Run `cargo build --release` on Windows and Linux (to build binaries) +1. Run `cargo build --release` on Windows and Linux (to build standalone binaries) 1. Run `cargo deb` on Ubuntu 16.04 (one built on 18.04 works on 19.04, but not vice-versa) 1. Run `cargo build --release`, then `cargo rpm build` on Centos 7. (This allows easy installation for Red Hat, Fedora, and CentOs diff --git a/pip/setup.py b/pip/setup.py new file mode 100644 index 0000000..fad6404 --- /dev/null +++ b/pip/setup.py @@ -0,0 +1,20 @@ +from setuptools import setup, find_packages + +with open('README.rst') as f: + readme = f.read() + +setup( + name="pflow", + version="0.1.7", + packages=find_packages(), + + install_requires=[], + + author="David O'Connor", + author_email="david.alan.oconnor@gmail.com", + url='https://github.com/David-OConnor/pyflow', + description="A Python installation and dependency manager", + long_description=readme, + license="MIT", + keywords="packaging, dependencies, install", +) diff --git a/src/build.rs b/src/build.rs index 5491584..6e89e42 100644 --- a/src/build.rs +++ b/src/build.rs @@ -116,7 +116,7 @@ setuptools.setup( // entry_points={{ // "console_scripts": , // }}, - cfg.readme_filename.unwrap_or_else(|| "README.md".into()), + cfg.readme.unwrap_or_else(|| "README.md".into()), cfg.name.unwrap_or_else(|| "".into()), version, author, @@ -195,10 +195,18 @@ pub fn build( util::set_pythonpath(&[paths.lib.to_owned()]); println!("🛠️️ Building the package..."); - Command::new(paths.bin.join("python")) - .args(&[dummy_setup_fname, "sdist", "bdist_wheel"]) - .status() - .expect("Problem building"); + // todo: Run build script first, right? + if let Some(build_file) = &cfg.build { + Command::new(paths.bin.join("python")) + .arg(&build_file) + .status() + .expect(&format!("Problem building using {}", build_file)); + } + +// Command::new(paths.bin.join("python")) +// .args(&[dummy_setup_fname, "sdist", "bdist_wheel"]) +// .status() +// .expect("Problem building"); util::print_color("Build complete.", Color::Green); @@ -257,7 +265,7 @@ pub mod test { python_requires: Some(">=3.6".into()), package_url: Some("https://upload.pypi.org/legacy/".into()), scripts, - readme_filename: Some("README.md".into()), + readme: Some("README.md".into()), reqs: vec![ Req::new( "numpy".into(), diff --git a/src/dep_resolution.rs b/src/dep_resolution.rs index 408bb47..9b1a076 100644 --- a/src/dep_resolution.rs +++ b/src/dep_resolution.rs @@ -322,8 +322,9 @@ fn guess_graph( d } else { util::abort( - "Problem getting dependency data - this is\ - likely a bug in the cacheing process. Please try again in a few minutes.", + "Problem getting dependency data - this is \ + likely a bug in the cacheing process. Please try again in a few minutes. \ + Reqs: {:#?}", ); unreachable!() }; diff --git a/src/dep_types.rs b/src/dep_types.rs index d433bc6..4ef67db 100644 --- a/src/dep_types.rs +++ b/src/dep_types.rs @@ -422,7 +422,9 @@ impl Constraint { } if let Ok(parsed) = Version::from_str(s) { - return Ok(vec![Self::new(ReqType::Exact, parsed)]); + // Note the `Caret` req type; if passed in this format, assuming packages marked + // `3.6` are valid for `3.7+`. + return Ok(vec![Self::new(ReqType::Caret, parsed)]); } let s_split = s.split('.'); diff --git a/src/files.rs b/src/files.rs index a1c7d86..e7bd98f 100644 --- a/src/files.rs +++ b/src/files.rs @@ -76,7 +76,8 @@ pub struct Pyflow { pub repository: Option, pub repo_url: Option, pub package_url: Option, - pub readme_filename: Option, + pub readme: Option, + pub build: Option, // pub entry_points: Option>>, pub scripts: Option>, pub python_requires: Option, @@ -93,13 +94,14 @@ pub struct Poetry { pub description: Option, pub license: Option, pub authors: Option>, - pub readme: Option, pub homepage: Option, pub repository: Option, pub documentation: Option, pub keywords: Option>, + pub readme: Option, + pub build: Option, pub classifiers: Option>, - pub packages: Option>, + pub packages: Option>>, pub include: Option>, pub exclude: Option>, pub extras: Option>, diff --git a/src/install.rs b/src/install.rs index 3552244..f35a529 100644 --- a/src/install.rs +++ b/src/install.rs @@ -283,7 +283,9 @@ pub fn download_and_install_package( if !dist_path.exists() { util::abort(&format!( "Problem building {} from source. \ - This may occur on WSL if installing to a mounted directory.", + This may occur if a package that requires compiling has no wheels available \ + for this OS and this system is missing dependencies required to compile it, \ + or if on WSL and installing to a mounted directory.", name )); } diff --git a/src/main.rs b/src/main.rs index 495d09e..7a3d52a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -120,7 +120,7 @@ Install packages from `pyproject.toml`, `pyflow.lock`, or speficied ones. Exampl // #[structopt(name = "name")] // name: String, // }, - /// Change the Python version for this project. eg `pyflow switch 3.7`. Equivalent to setting + /// Change the Python version for this project. eg `pyflow switch 3.8`. Equivalent to setting /// `py_version` in `pyproject.toml`. #[structopt(name = "switch")] Switch { @@ -148,7 +148,8 @@ pub struct Config { repository: Option, repo_url: Option, package_url: Option, - readme_filename: Option, + readme: Option, + build: Option, // A python file used to build non-python extensions // entry_points: HashMap>, // todo option? scripts: HashMap, //todo: put under [tool.pyflow.scripts] ? // console_scripts: Vec, // We don't parse these; pass them to `setup.py` as-entered. @@ -300,7 +301,12 @@ impl Config { if let Some(v) = po.repository { result.repository = Some(v); } - + if let Some(v) = po.readme { + result.readme = Some(v); + } + if let Some(v) = po.build { + result.build = Some(v); + } // todo: Process entry pts, classifiers etc? if let Some(v) = po.classifiers { result.classifiers = v; @@ -405,7 +411,13 @@ impl Config { if let Some(v) = pf.keywords { result.keywords = v; } - // if let Some(v) = pp.entry_points { + if let Some(v) = pf.readme { + result.readme = Some(v); + } + if let Some(v) = pf.build { + result.build = Some(v); + } + // if let Some(v) = pf.entry_points { // result.entry_points = v; // } // todo if let Some(v) = pf.scripts {