1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! Pipenv, Python dependency manager.
use std::path::Path;
use std::process::Command;
/// Detected via `Pipfile` or `Pipfile.lock`.
pub(crate) fn detect(dir: &Path) -> bool {
dir.join("Pipfile").exists() || dir.join("Pipfile.lock").exists()
}
/// `pipenv install` or `pipenv sync` (frozen).
///
/// Plain `pipenv install` may update `Pipfile.lock` if `Pipfile`
/// has changed, which defeats the point of a frozen install in CI.
/// `pipenv sync` installs the exact versions recorded in
/// `Pipfile.lock` without touching the lockfile and errors if the
/// lockfile is missing. That's the documented "deterministic
/// install" command for Pipenv (similar to `pipenv install
/// --deploy` but stricter: `--deploy` keeps the install verb,
/// `sync` is the canonical name).
pub(crate) fn install_cmd(frozen: bool) -> Command {
let mut c = super::program::command("pipenv");
if frozen {
c.arg("sync");
} else {
c.arg("install");
}
c
}
/// `pipenv run <script> [args...]`, run a `[project.scripts]` console
/// entry point inside the project's virtualenv.
pub(crate) fn run_cmd(script: &str, args: &[String]) -> Command {
let mut c = super::program::command("pipenv");
c.arg("run").arg(script).args(args);
c
}
#[cfg(test)]
mod tests {
use super::{install_cmd, run_cmd};
#[test]
fn install_unfrozen_uses_install_subcommand() {
let args: Vec<_> = install_cmd(false)
.get_args()
.map(|arg| arg.to_string_lossy().into_owned())
.collect();
assert_eq!(args, ["install"]);
}
#[test]
fn install_frozen_uses_sync_subcommand() {
let args: Vec<_> = install_cmd(true)
.get_args()
.map(|arg| arg.to_string_lossy().into_owned())
.collect();
assert_eq!(args, ["sync"]);
}
#[test]
fn run_cmd_forwards_script_and_args() {
let args: Vec<_> = run_cmd("serve", &["--port".into(), "8000".into()])
.get_args()
.map(|arg| arg.to_string_lossy().into_owned())
.collect();
assert_eq!(args, ["run", "serve", "--port", "8000"]);
}
}