Skip to content

Commit

Permalink
maturn develop install dependencies automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Feb 24, 2021
1 parent c39a595 commit e193faa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Change manylinux default version based on target arch by messense in [#424](https://github.com/PyO3/maturin/pull/424)
* Support local path dependencies in source distribution (i.e. you can now package a workspace into an sdist)
* Set a more reasonable LC_ID_DYLIB entry on macOS by messense [#433](https://github.com/PyO3/maturin/pull/433)
* maturn develop install dependencies automatically by messense [#443](https://github.com/PyO3/maturin/pull/443)

## 0.9.4 - 2021-02-18

Expand Down
25 changes: 24 additions & 1 deletion src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use crate::Manylinux;
use crate::PythonInterpreter;
use crate::Target;
use crate::{write_dist_info, BuildOptions};
use anyhow::{anyhow, format_err, Context, Result};
use anyhow::{anyhow, bail, format_err, Context, Result};
use fs_err as fs;
use std::path::Path;
use std::process::Command;

/// Installs a crate by compiling it and copying the shared library to site-packages.
/// Also adds the dist-info directory to make sure pip and other tools detect the library
Expand Down Expand Up @@ -46,6 +47,28 @@ pub fn develop(
anyhow!("Expected `python` to be a python interpreter inside a virtualenv ಠ_ಠ")
})?;

// Install dependencies
if !build_context.metadata21.requires_dist.is_empty() {
let mut args = vec!["-m", "pip", "install"];
args.extend(
build_context
.metadata21
.requires_dist
.iter()
.map(|x| x.as_str()),
);
let mut pip_install = Command::new(&interpreter.executable)
.args(&args)
.spawn()
.context("Failed to run pip install")?;
let status = pip_install
.wait()
.expect("Failed to wait on pip install process");
if !status.success() {
bail!(r#"pip install finished with "{}""#, status,)
}
}

let mut builder = PathWriter::venv(&target, &venv_dir, &build_context.bridge)?;

let context = "Failed to build a native library through cargo";
Expand Down
1 change: 1 addition & 0 deletions test-crates/pyo3-mixed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ classifier = [
"Programming Language :: Python",
"Programming Language :: Rust"
]
requires-dist = ["boltons"]

[dependencies]
pyo3 = { version = "0.13.2", features = ["extension-module"] }
Expand Down
3 changes: 3 additions & 0 deletions test-crates/pyo3-mixed/check_installed/check_installed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python3

from boltons.strutils import slugify
import pyo3_mixed

assert pyo3_mixed.get_42() == 42
assert slugify("First post! Hi!!!!~1 ") == "first_post_hi_1"

print("SUCCESS")
2 changes: 1 addition & 1 deletion test-dockerfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fi

docker run --rm -v $(pwd)/test-crates/pyo3-mixed:/io maturin build --no-sdist -i python3.8

venv-docker/bin/pip install pyo3-mixed --no-index --find-links test-crates/pyo3-mixed/target/wheels/
venv-docker/bin/pip install pyo3-mixed --find-links test-crates/pyo3-mixed/target/wheels/

if [[ $(venv-docker/bin/python test-crates/pyo3-mixed/check_installed/check_installed.py) != 'SUCCESS' ]]; then
exit 1
Expand Down

0 comments on commit e193faa

Please sign in to comment.