Use temp_dir casing everywhere (#440)

This commit is contained in:
Charlie Marsh 2023-11-16 13:04:10 -08:00 committed by GitHub
parent 1883dbdc21
commit b1c29447df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 78 additions and 78 deletions

View file

@ -519,9 +519,9 @@ fn bytecode_compile_inner(
py_source_paths: &[PathBuf],
sys_executable: &Path,
) -> Result<(ExitStatus, Vec<String>), Error> {
let tempdir = tempdir()?;
let temp_dir = tempdir()?;
// Running python with an actual file will produce better error messages
let pip_compileall_py = tempdir.path().join("pip_compileall.py");
let pip_compileall_py = temp_dir.path().join("pip_compileall.py");
fs::write(&pip_compileall_py, include_str!("pip_compileall.py"))?;
// We input the paths through stdin and get the successful paths returned through stdout
let mut bytecode_compiler = Command::new(sys_executable)

View file

@ -26,7 +26,7 @@ pub struct CacheDir {
/// the temporary directory exists for the length of the operation, but is dropped at the end
/// as appropriate.
#[allow(dead_code)]
tempdir: Option<TempDir>,
temp_dir: Option<TempDir>,
}
impl TryFrom<CacheArgs> for CacheDir {
@ -40,26 +40,26 @@ impl TryFrom<CacheArgs> for CacheDir {
fn try_from(value: CacheArgs) -> Result<Self, Self::Error> {
let project_dirs = ProjectDirs::from("", "", "puffin");
if value.no_cache {
let tempdir = tempdir()?;
let cache_dir = tempdir.path().to_path_buf();
let temp_dir = tempdir()?;
let cache_dir = temp_dir.path().to_path_buf();
Ok(Self {
cache_dir,
tempdir: Some(tempdir),
temp_dir: Some(temp_dir),
})
} else if let Some(cache_dir) = value.cache_dir {
Ok(Self {
cache_dir,
tempdir: None,
temp_dir: None,
})
} else if let Some(project_dirs) = project_dirs {
Ok(Self {
cache_dir: project_dirs.cache_dir().to_path_buf(),
tempdir: None,
temp_dir: None,
})
} else {
Ok(Self {
cache_dir: PathBuf::from(".puffin_cache"),
tempdir: None,
temp_dir: None,
})
}
}

View file

@ -10,13 +10,13 @@ mod common;
#[test]
fn missing_pyproject_toml() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("flask")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(predicates::path::missing());
@ -25,14 +25,14 @@ fn missing_pyproject_toml() -> Result<()> {
#[test]
fn missing_project_table() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("flask")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]
@ -47,8 +47,8 @@ dependencies = [
#[test]
fn missing_dependencies_array() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -59,7 +59,7 @@ name = "project"
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("flask")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]
@ -75,8 +75,8 @@ dependencies = [
#[test]
fn replace_dependency() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -90,7 +90,7 @@ dependencies = [
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("flask==2.0.0")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]
@ -106,8 +106,8 @@ dependencies = [
#[test]
fn reformat_array() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -119,7 +119,7 @@ dependencies = ["flask==1.0.0"]
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("requests")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]

View file

@ -11,44 +11,44 @@ mod common;
#[test]
fn no_arguments() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let temp_dir = assert_fs::TempDir::new()?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-uninstall")
.current_dir(&tempdir));
.current_dir(&temp_dir));
Ok(())
}
#[test]
fn invalid_requirement() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let temp_dir = assert_fs::TempDir::new()?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-uninstall")
.arg("flask==1.0.x")
.current_dir(&tempdir));
.current_dir(&temp_dir));
Ok(())
}
#[test]
fn missing_requirements_txt() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let temp_dir = assert_fs::TempDir::new()?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-uninstall")
.arg("-r")
.arg("requirements.txt")
.current_dir(&tempdir));
.current_dir(&temp_dir));
Ok(())
}
#[test]
fn invalid_requirements_txt_requirement() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let requirements_txt = tempdir.child("requirements.txt");
let temp_dir = assert_fs::TempDir::new()?;
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("flask==1.0.x")?;
@ -56,28 +56,28 @@ fn invalid_requirements_txt_requirement() -> Result<()> {
.arg("pip-uninstall")
.arg("-r")
.arg("requirements.txt")
.current_dir(&tempdir));
.current_dir(&temp_dir));
Ok(())
}
#[test]
fn missing_pyproject_toml() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let temp_dir = assert_fs::TempDir::new()?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-uninstall")
.arg("-r")
.arg("pyproject.toml")
.current_dir(&tempdir));
.current_dir(&temp_dir));
Ok(())
}
#[test]
fn invalid_pyproject_toml_syntax() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str("123 - 456")?;
@ -85,15 +85,15 @@ fn invalid_pyproject_toml_syntax() -> Result<()> {
.arg("pip-uninstall")
.arg("-r")
.arg("pyproject.toml")
.current_dir(&tempdir));
.current_dir(&temp_dir));
Ok(())
}
#[test]
fn invalid_pyproject_toml_schema() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str("[project]")?;
@ -101,15 +101,15 @@ fn invalid_pyproject_toml_schema() -> Result<()> {
.arg("pip-uninstall")
.arg("-r")
.arg("pyproject.toml")
.current_dir(&tempdir));
.current_dir(&temp_dir));
Ok(())
}
#[test]
fn invalid_pyproject_toml_requirement() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -122,7 +122,7 @@ dependencies = ["flask==1.0.x"]
.arg("pip-uninstall")
.arg("-r")
.arg("pyproject.toml")
.current_dir(&tempdir));
.current_dir(&temp_dir));
Ok(())
}

View file

@ -10,13 +10,13 @@ mod common;
#[test]
fn missing_pyproject_toml() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("flask")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(predicates::path::missing());
@ -25,14 +25,14 @@ fn missing_pyproject_toml() -> Result<()> {
#[test]
fn missing_project_table() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("flask")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(predicates::str::is_empty());
@ -41,8 +41,8 @@ fn missing_project_table() -> Result<()> {
#[test]
fn missing_dependencies_array() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -53,7 +53,7 @@ name = "project"
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("flask")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]
@ -66,8 +66,8 @@ name = "project"
#[test]
fn missing_dependency() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -81,7 +81,7 @@ dependencies = [
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("requests")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]
@ -97,8 +97,8 @@ dependencies = [
#[test]
fn remove_dependency() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -113,7 +113,7 @@ dependencies = [
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("flask")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]
@ -129,8 +129,8 @@ dependencies = [
#[test]
fn empty_array() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -144,7 +144,7 @@ dependencies = [
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("requests")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]
@ -158,8 +158,8 @@ dependencies = []
#[test]
fn normalize_name() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -174,7 +174,7 @@ dependencies = [
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("Flask")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]
@ -190,8 +190,8 @@ dependencies = [
#[test]
fn reformat_array() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let pyproject_toml = tempdir.child("pyproject.toml");
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
pyproject_toml.write_str(
r#"[project]
@ -203,7 +203,7 @@ dependencies = ["flask==1.0.0", "requests"]
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("requests")
.current_dir(&tempdir));
.current_dir(&temp_dir));
pyproject_toml.assert(
r#"[project]

View file

@ -13,13 +13,13 @@ mod common;
#[test]
fn create_venv() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let venv = tempdir.child(".venv");
let temp_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
insta::with_settings!({
filters => vec![
(r"Using Python 3.12 at .+", "Using Python 3.11 at [PATH]"),
(tempdir.to_str().unwrap(), "/home/ferris/project"),
(temp_dir.to_str().unwrap(), "/home/ferris/project"),
]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
@ -27,7 +27,7 @@ fn create_venv() -> Result<()> {
.arg(venv.as_os_str())
.arg("--python")
.arg("python3.12")
.current_dir(&tempdir));
.current_dir(&temp_dir));
});
venv.assert(predicates::path::is_dir());
@ -37,20 +37,20 @@ fn create_venv() -> Result<()> {
#[test]
fn create_venv_defaults_to_cwd() -> Result<()> {
let tempdir = assert_fs::TempDir::new()?;
let venv = tempdir.child(".venv");
let temp_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
insta::with_settings!({
filters => vec![
(r"Using Python 3.12 at .+", "Using Python 3.11 at [PATH]"),
(tempdir.to_str().unwrap(), "/home/ferris/project"),
(temp_dir.to_str().unwrap(), "/home/ferris/project"),
]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg("--python")
.arg("python3.12")
.current_dir(&tempdir));
.current_dir(&temp_dir));
});
venv.assert(predicates::path::is_dir());

View file

@ -68,8 +68,8 @@ async fn resolve(
markers: &'static MarkerEnvironment,
tags: &Tags,
) -> Result<Graph> {
let tempdir = tempdir()?;
let client = RegistryClientBuilder::new(tempdir.path()).build();
let temp_dir = tempdir()?;
let client = RegistryClientBuilder::new(temp_dir.path()).build();
let build_context = DummyContext {
interpreter_info: InterpreterInfo::artificial(
Platform::current()?,