Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Feb 1, 2024
1 parent fe23655 commit 810f7e1
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 43 deletions.
15 changes: 2 additions & 13 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions crates/install-wheel-rs/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ fn unpack_wheel_files<R: Read + Seek>(

if let Some(p) = out_path.parent() {
if !created_dirs.contains(p) {
fs::create_dir_all(&p)?;
fs::create_dir_all(p)?;
created_dirs.insert(p.to_path_buf());
}
}
Expand Down Expand Up @@ -424,7 +424,7 @@ fn write_script_entrypoints(
record: &mut Vec<RecordEntry>,
) -> Result<(), Error> {
// for monotrail
fs::create_dir_all(site_packages.join(&bin_rel()))?;
fs::create_dir_all(site_packages.join(bin_rel()))?;
for entrypoint in entrypoints {
let entrypoint_relative = if cfg!(windows) {
// On windows we actually build an .exe wrapper
Expand Down Expand Up @@ -628,7 +628,7 @@ fn bytecode_compile_inner(
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.current_dir(&site_packages)
.current_dir(site_packages)
.spawn()
.map_err(Error::PythonSubcommand)?;

Expand Down Expand Up @@ -708,14 +708,14 @@ fn move_folder_recorded(
record: &mut [RecordEntry],
) -> Result<(), Error> {
if !dest_dir.is_dir() {
fs::create_dir_all(&dest_dir)?;
fs::create_dir_all(dest_dir)?;
}
for entry in WalkDir::new(&src_dir) {
for entry in WalkDir::new(src_dir) {
let entry = entry?;
let src = entry.path();
// This is the base path for moving to the actual target for the data
// e.g. for data it's without <..>.data/data/
let relative_to_data = src.strip_prefix(&src_dir).expect("Prefix must no change");
let relative_to_data = src.strip_prefix(src_dir).expect("Prefix must no change");
// This is the path stored in RECORD
// e.g. for data it's with .data/data/
let relative_to_site_packages = src
Expand Down Expand Up @@ -787,7 +787,7 @@ fn install_script(
} else {
// reading and writing is slow especially for large binaries, so we move them instead
drop(script);
fs::rename(&path, &site_packages.join(&target_path))?;
fs::rename(&path, site_packages.join(&target_path))?;
None
};
#[cfg(unix)]
Expand Down Expand Up @@ -1377,7 +1377,7 @@ mod test {
.join("site-packages")
.join("colander-0.9.9.dist-info")
.join("RECORD");
let record = fs::read_to_string(&record).unwrap();
let record = fs::read_to_string(record).unwrap();
for line in record.lines() {
assert!(!line.starts_with('/'), "{}", line);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/monotrail-utils/src/parse_cpython_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn naive_python_arg_parser<T: AsRef<str>>(args: &[T]) -> Result<Option<Strin
pub fn parse_plus_arg(
python_args: &[String],
) -> Result<(Vec<String>, Option<(u8, u8)>), ParsePythonVersionError> {
if let Some(first_arg) = python_args.get(0) {
if let Some(first_arg) = python_args.first() {
if first_arg.starts_with('+') {
let python_version = parse_major_minor(first_arg)?;
return Ok((python_args[1..].to_vec(), Some(python_version)));
Expand Down
2 changes: 1 addition & 1 deletion crates/monotrail-utils/src/standalone_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ mod test {
use crate::standalone_python::{find_python, PYTHON_STANDALONE_LATEST_RELEASE};
use mockito::{Mock, ServerGuard};
use std::path::PathBuf;
use tempfile::tempdir;


pub fn zstd_json_mock(url: &str, fixture: impl Into<PathBuf>) -> (ServerGuard, Mock) {
use fs_err::File;
Expand Down
2 changes: 1 addition & 1 deletion crates/monotrail/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ libloading = "0.8.0"
libz-sys = { version = "1.1.12", features = ["static"] } # For the zig build
monotrail-utils = { version = "0.0.1", path = "../monotrail-utils" }
nix = { version = "0.27.1", features = ["process"] }
pep440_rs = "0.3.11"
pep440_rs = "0.4.0"
pep508_rs = { workspace = true, features = ["serde"] }
pyo3 = { workspace = true, features = ["extension-module", "abi3-py37"], optional = true }
rayon = "1.8.0"
Expand Down
4 changes: 2 additions & 2 deletions crates/monotrail/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn download_distribution_cached(
url: &str,
) -> anyhow::Result<PathBuf> {
let target_dir = cache_dir()?.join("artifacts").join(name).join(version);
let target_file = target_dir.join(&filename);
let target_file = target_dir.join(filename);

if target_file.is_file() {
debug!(
Expand Down Expand Up @@ -433,7 +433,7 @@ pub fn run_cli(cli: Cli, venv: Option<&Path>) -> anyhow::Result<Option<i32>> {
// extended to run this in parallel.
// Would be nicer to use a fork wrapper here
let status = Command::new(env::current_exe()?)
.args(&["run", "-p", &version, "python"])
.args(["run", "-p", &version, "python"])
.args(&trail_args)
.status()
.context("Failed to start child process for python version")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/monotrail/src/inject_and_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub fn inject_and_run_python(
// is an even bigger mess
let args_cstring: Vec<WideCString> = args
.iter()
.map(|arg| WideCString::from_str(&arg).unwrap())
.map(|arg| WideCString::from_str(arg).unwrap())
.collect();
let mut args_c_char: Vec<*const wchar_t> = args_cstring
.iter()
Expand Down
8 changes: 4 additions & 4 deletions crates/monotrail/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub fn repo_at_revision(url: &str, revision: &str, repo_dir: &Path) -> anyhow::R
Ok(repo) => Some(repo),
Err(err) => {
warn!("Repository directory {} exists, but can't be opened as a git repository, recreating: {}", repo_dir.display(), err);
fs::remove_dir_all(&repo_dir).context("Failed to remove old repo dir")?;
fs::remove_dir_all(repo_dir).context("Failed to remove old repo dir")?;
None
}
}
Expand Down Expand Up @@ -323,7 +323,7 @@ pub fn repo_at_revision(url: &str, revision: &str, repo_dir: &Path) -> anyhow::R
// https://stackoverflow.com/q/3489173/3549270
let mut tries = 1;
loop {
let result = Repository::clone(url, &repo_dir);
let result = Repository::clone(url, repo_dir);
let backoff = Duration::from_secs(1);
tries -= 1;
match result {
Expand All @@ -336,7 +336,7 @@ pub fn repo_at_revision(url: &str, revision: &str, repo_dir: &Path) -> anyhow::R
backoff.as_secs()
);
if repo_dir.is_dir() {
fs::remove_dir_all(&repo_dir)
fs::remove_dir_all(repo_dir)
.context("Failed to remove broken repo dir")?;
}
sleep(backoff);
Expand Down Expand Up @@ -446,7 +446,7 @@ fn download_and_install(
true,
&spec.extras,
&spec.unique_version,
&sys_executable,
sys_executable,
)
.with_context(|| format!("Failed to install {}", spec.requested))?;
Ok((spec.python_version, spec.unique_version, tag))
Expand Down
2 changes: 1 addition & 1 deletion crates/monotrail/src/monotrail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ pub fn find_scripts(

pub fn is_python_script(executable: &Path) -> anyhow::Result<bool> {
// Check whether we're launching a monotrail python script
let mut executable_file = File::open(&executable)
let mut executable_file = File::open(executable)
.context("the executable file was right there and is now unreadable ಠ_ಠ")?;
// scripts might be binaries, so we read an exact number of bytes instead of the first line as string
let mut start = vec![0; SHEBANG_PYTHON.as_bytes().len()];
Expand Down
6 changes: 3 additions & 3 deletions crates/monotrail/src/package_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ pub(crate) fn download_distribution(
target_file: &Path,
) -> Result<()> {
debug!("Downloading wheel to {}", target_file.display());
fs::create_dir_all(&target_dir).context("Couldn't create cache dir")?;
fs::create_dir_all(target_dir).context("Couldn't create cache dir")?;
// temp file so we don't clash with other processes running in parallel
let mut temp_file = tempfile::NamedTempFile::new_in(&target_dir)
let mut temp_file = tempfile::NamedTempFile::new_in(target_dir)
.context("Couldn't create file for download")?;
let request_for_file = ureq::get(url)
.set("User-Agent", "monotrail ([email protected])")
Expand All @@ -145,7 +145,7 @@ pub(crate) fn download_distribution(
io::copy(&mut request_for_file.into_reader(), &mut temp_file)
.context("Failed to download wheel from pypi")?;
temp_file
.persist(&target_file)
.persist(target_file)
.context("Failed to moved wheel to target position")?;
Ok(())
}
6 changes: 3 additions & 3 deletions crates/monotrail/src/poetry_integration/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn poetry_resolve(
// and minimize the resolution work
let poetry_lock_path = resolve_dir.path().join("poetry.lock");
if let Some(lockfile) = lockfile {
fs::write(&poetry_lock_path, &lockfile)?;
fs::write(&poetry_lock_path, lockfile)?;
}

poetry_resolve_from_dir(&resolve_dir, &python_context)?;
Expand Down Expand Up @@ -149,7 +149,7 @@ pub fn poetry_resolve_from_dir(
let result = Command::new(&current_exe)
.args(&args)
// This will make poetry-resolve find the pyproject.toml we want to resolve
.current_dir(&resolve_dir)
.current_dir(resolve_dir)
.status();
(result, current_exe, args)
}
Expand All @@ -170,7 +170,7 @@ pub fn poetry_resolve_from_dir(
&poetry_boostrap_lock,
)
// This will make poetry lock the right deps
.current_dir(&resolve_dir)
.current_dir(resolve_dir)
.status();
(result, python_context.sys_executable.clone(), args)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/monotrail/src/ppipx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn generate_ppipx_entry(
build_system: None,
};

fs::create_dir_all(&resolution_dir).context("Failed to create ppipx resolution dir")?;
fs::create_dir_all(resolution_dir).context("Failed to create ppipx resolution dir")?;
let resolve_dir = TempDir::new()?;
fs::write(
resolve_dir.path().join("pyproject.toml"),
Expand Down
2 changes: 1 addition & 1 deletion crates/monotrail/src/python_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn monotrail_from_args(py: Python, args: Vec<String>) -> PyResult<InjectData
// step
let script = naive_python_arg_parser(&args).map_err(PyRuntimeError::new_err)?;
let script = if let Some(script) =
env::var_os(&format!("{}_CWD", env!("CARGO_PKG_NAME").to_uppercase()))
env::var_os(format!("{}_CWD", env!("CARGO_PKG_NAME").to_uppercase()))
{
Some(PathBuf::from(script))
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/monotrail/src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn build_to_wheel(
) -> Result<PathBuf> {
let output = Command::new("pip")
.current_dir(build_dir)
.args(&["wheel", "--no-deps"])
.args(["wheel", "--no-deps"])
.arg(sdist_or_dir)
.output()
.context("Failed to invoke pip")?;
Expand Down
4 changes: 2 additions & 2 deletions crates/monotrail/src/verify_installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn verify_package(
tag: &str,
) -> anyhow::Result<Vec<String>> {
let mut failing = Vec::new();
let package_root = root.join(&name).join(&unique_version).join(&tag);
let package_root = root.join(name).join(unique_version).join(tag);
let site_packages = if cfg!(windows) {
package_root.join("Lib").join("site-packages")
} else {
Expand All @@ -46,7 +46,7 @@ fn verify_package(
// normalize package name
.to_lowercase()
.replace('-', "_")
.starts_with(&name)
.starts_with(name)
&& dir.file_name().to_string_lossy().ends_with(".dist-info")
})
.map(|entry| entry.path())
Expand Down

0 comments on commit 810f7e1

Please sign in to comment.