Skip to content

Commit

Permalink
Merge pull request #941 from messense/dunce
Browse files Browse the repository at this point in the history
Replace `adjust_canonicalization` with the `dunce` crate
  • Loading branch information
messense authored May 27, 2022
2 parents 659c62e + d68dc80 commit fd75248
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 49 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ rpassword = { version = "6.0.1", optional = true }
ureq = { version = "2.3.1", features = ["gzip", "socks-proxy"], default-features = false, optional = true }
native-tls-crate = { package = "native-tls", version = "0.2.8", optional = true }
tracing = "0.1.34"
dunce = "1.0.2"

[dev-dependencies]
indoc = "1.0.3"
Expand Down
21 changes: 1 addition & 20 deletions src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ pub fn develop(
"--disable-pip-version-check",
"install",
"--force-reinstall",
&adjust_canonicalization(filename),
];
let output = Command::new(&python)
.args(&command)
.arg(dunce::simplified(filename))
.output()
.context(format!("pip install failed with {:?}", python))?;
if !output.status.success() {
Expand Down Expand Up @@ -110,22 +110,3 @@ pub fn develop(

Ok(())
}

// Y U NO accept windows path prefix, pip?
// Anyways, here's shepmasters stack overflow solution
// https://stackoverflow.com/a/50323079/3549270
#[cfg(target_family = "unix")]
fn adjust_canonicalization(p: impl AsRef<Path>) -> String {
p.as_ref().display().to_string()
}

#[cfg(target_os = "windows")]
fn adjust_canonicalization(p: impl AsRef<Path>) -> String {
const VERBATIM_PREFIX: &str = r#"\\?\"#;
let p = p.as_ref().display().to_string();
if p.starts_with(VERBATIM_PREFIX) {
p[VERBATIM_PREFIX.len()..].to_string()
} else {
p
}
}
6 changes: 2 additions & 4 deletions tests/common/editable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::common::{
adjust_canonicalization, check_installed, create_virtualenv, maybe_mock_cargo,
};
use crate::common::{check_installed, create_virtualenv, maybe_mock_cargo};
use anyhow::{bail, Context, Result};
use clap::Parser;
use maturin::BuildOptions;
Expand Down Expand Up @@ -59,10 +57,10 @@ pub fn test_editable(
"--no-cache-dir",
"install",
"--force-reinstall",
&adjust_canonicalization(filename),
];
let output = Command::new(&python)
.args(&command)
.arg(dunce::simplified(filename))
.output()
.context(format!("pip install failed with {:?}", python))?;
if !output.status.success() {
Expand Down
8 changes: 3 additions & 5 deletions tests/common/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::common::{
adjust_canonicalization, check_installed, create_virtualenv, maybe_mock_cargo,
};
use crate::common::{check_installed, create_virtualenv, maybe_mock_cargo};
use anyhow::{bail, Context, Result};
use cargo_zigbuild::Zig;
use clap::Parser;
Expand Down Expand Up @@ -99,10 +97,10 @@ pub fn test_integration(
"--no-cache-dir",
"install",
"--force-reinstall",
&adjust_canonicalization(filename),
];
let output = Command::new(&python)
.args(&command)
.arg(dunce::simplified(filename))
.output()
.context(format!("pip install failed with {:?}", python))?;
if !output.status.success() {
Expand Down Expand Up @@ -210,8 +208,8 @@ pub fn test_integration_conda(package: impl AsRef<Path>, bindings: Option<String
"--disable-pip-version-check",
"install",
"--force-reinstall",
&adjust_canonicalization(wheel_file),
])
.arg(dunce::simplified(&wheel_file))
.stderr(Stdio::inherit())
.output()?;
if !output.status.success() {
Expand Down
21 changes: 1 addition & 20 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,6 @@ pub mod errors;
pub mod integration;
pub mod other;

// Y U NO accept windows path prefix, pip?
// Anyways, here's shepmasters stack overflow solution
// https://stackoverflow.com/a/50323079/3549270
#[cfg(target_family = "unix")]
pub fn adjust_canonicalization(p: impl AsRef<Path>) -> String {
p.as_ref().display().to_string()
}

#[cfg(target_os = "windows")]
pub fn adjust_canonicalization(p: impl AsRef<Path>) -> String {
const VERBATIM_PREFIX: &str = r#"\\?\"#;
let p = p.as_ref().display().to_string();
if p.starts_with(VERBATIM_PREFIX) {
p[VERBATIM_PREFIX.len()..].to_string()
} else {
p
}
}

/// Check that the package is either not installed or works correctly
pub fn check_installed(package: &Path, python: &Path) -> Result<()> {
let check_installed = Path::new(package)
Expand Down Expand Up @@ -125,7 +106,7 @@ pub fn create_virtualenv(
cmd.arg("-p").arg(interp);
}
let output = cmd
.arg(adjust_canonicalization(&venv_dir))
.arg(dunce::simplified(&venv_dir))
.stderr(Stdio::inherit())
.output()
.expect("Failed to create a virtualenv");
Expand Down

0 comments on commit fd75248

Please sign in to comment.