Skip to content

Commit

Permalink
Add support for installing optional dependencies in develop command
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Sep 24, 2021
1 parent 8742d50 commit d658ac5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn develop(
venv_dir: &Path,
release: bool,
strip: bool,
extras: Vec<String>,
) -> Result<()> {
let target = Target::from_target_triple(None)?;

Expand Down Expand Up @@ -71,14 +72,17 @@ pub fn develop(

// 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 args = vec!["-m".to_string(), "pip".to_string(), "install".to_string()];
args.extend(build_context.metadata21.requires_dist.iter().map(|x| {
let mut pkg = x.clone();
// Remove extra marker to make it installable with pip
for extra in &extras {
pkg = pkg
.replace(&format!(" and extra == '{}'", extra), "")
.replace(&format!("; extra == '{}'", extra), "");
}
pkg
}));
let status = Command::new(&interpreter.executable)
.args(&args)
.status()
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ enum Opt {
/// Use as `--rustc-extra-args="--my-arg"`
#[structopt(long = "rustc-extra-args")]
rustc_extra_args: Vec<String>,
/// Install extra requires aka. optional dependencies
///
/// Use as `--extras=extra1,extra2`
#[structopt(long, use_delimiter = true, multiple = false)]
extras: Vec<String>,
},
/// Build only a source distribution (sdist) without compiling.
///
Expand Down Expand Up @@ -549,6 +554,7 @@ fn run() -> Result<()> {
rustc_extra_args,
release,
strip,
extras,
} => {
let venv_dir = match (env::var_os("VIRTUAL_ENV"), env::var_os("CONDA_PREFIX")) {
(Some(dir), None) => PathBuf::from(dir),
Expand All @@ -574,6 +580,7 @@ fn run() -> Result<()> {
&venv_dir,
release,
strip,
extras,
)?;
}
Opt::SDist { manifest_path, out } => {
Expand Down
1 change: 1 addition & 0 deletions tests/common/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn test_develop(package: impl AsRef<Path>, bindings: Option<String>) -> Resu
&venv_dir,
false,
cfg!(feature = "faster-tests"),
vec![],
)?;

check_installed(&package.as_ref(), &python)?;
Expand Down

0 comments on commit d658ac5

Please sign in to comment.