Skip to content

Commit

Permalink
Remove some unused code from install-wheel-rs (#2001)
Browse files Browse the repository at this point in the history
I need to make a bunch of changes to this crate, and I'm finding that
the existing unused interfaces are really getting in the way.
  • Loading branch information
charliermarsh authored Feb 27, 2024
1 parent 6678d54 commit 5997d0d
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 824 deletions.
5 changes: 0 additions & 5 deletions Cargo.lock

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

13 changes: 1 addition & 12 deletions crates/install-wheel-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,21 @@ uv-normalize = { path = "../uv-normalize" }
uv-fs = { path = "../uv-fs" }
pypi-types = { path = "../pypi-types" }

clap = { workspace = true, optional = true, features = ["derive", "env"] }
clap = { workspace = true, optional = true, features = ["derive"] }
configparser = { workspace = true }
csv = { workspace = true }
data-encoding = { workspace = true }
fs-err = { workspace = true }
fs2 = { workspace = true }
goblin = { workspace = true }
mailparse = { workspace = true }
once_cell = { workspace = true }
platform-info = { workspace = true }
plist = { workspace = true }
pyo3 = { workspace = true, features = ["extension-module", "abi3-py37"], optional = true }
rayon = { workspace = true, optional = true }
reflink-copy = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
sha2 = { workspace = true }
target-lexicon = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
Expand All @@ -55,11 +50,5 @@ url = { workspace = true }
walkdir = { workspace = true }
zip = { workspace = true }

[features]
default = ["cli", "parallel"]
python_bindings = ["pyo3", "tracing-subscriber"]
cli = ["clap"]
parallel = ["rayon"]

[dev-dependencies]
indoc = {version = "2.0.4"}
89 changes: 0 additions & 89 deletions crates/install-wheel-rs/src/install_location.rs
Original file line number Diff line number Diff line change
@@ -1,75 +1,5 @@
use std::io;
use std::path::{Path, PathBuf};

use fs2::FileExt;
use fs_err::File;
use tracing::{error, warn};

use uv_fs::Normalized;

const INSTALL_LOCKFILE: &str = "install-wheel-rs.lock";

/// I'm not sure that's the right way to normalize here, but it's a single place to change
/// everything.
///
/// For displaying to the user, `-` is better, and it's also what poetry lockfile 2.0 does
///
/// Keep in sync with `find_distributions`
pub fn normalize_name(dep_name: &str) -> String {
dep_name.to_lowercase().replace(['.', '_'], "-")
}

/// A directory for which we acquired a install-wheel-rs.lock lockfile
pub struct LockedDir {
/// The directory to lock
path: PathBuf,
/// handle on the install-wheel-rs.lock that drops the lock
lockfile: File,
}

impl LockedDir {
/// Tries to lock the directory, returns Ok(None) if it is already locked
pub fn try_acquire(path: &Path) -> io::Result<Option<Self>> {
let lockfile = File::create(path.join(INSTALL_LOCKFILE))?;
if lockfile.file().try_lock_exclusive().is_ok() {
Ok(Some(Self {
path: path.to_path_buf(),
lockfile,
}))
} else {
Ok(None)
}
}

/// Locks the directory, if necessary blocking until the lock becomes free
pub fn acquire(path: &Path) -> io::Result<Self> {
let lockfile = File::create(path.join(INSTALL_LOCKFILE))?;
lockfile.file().lock_exclusive()?;
Ok(Self {
path: path.to_path_buf(),
lockfile,
})
}
}

impl Drop for LockedDir {
fn drop(&mut self) {
if let Err(err) = self.lockfile.file().unlock() {
error!(
"Failed to unlock {}: {}",
self.lockfile.path().normalized_display(),
err
);
}
}
}

impl AsRef<Path> for LockedDir {
fn as_ref(&self) -> &Path {
&self.path
}
}

/// A virtual environment into which a wheel can be installed.
///
/// We use a lockfile to prevent multiple instance writing stuff on the same time
Expand Down Expand Up @@ -109,22 +39,3 @@ impl<T: AsRef<Path>> InstallLocation<T> {
&self.venv_root
}
}

impl InstallLocation<PathBuf> {
pub fn acquire_lock(&self) -> io::Result<InstallLocation<LockedDir>> {
let locked_dir = if let Some(locked_dir) = LockedDir::try_acquire(&self.venv_root)? {
locked_dir
} else {
warn!(
"Could not acquire exclusive lock for installing, is another installation process \
running? Sleeping until lock becomes free"
);
LockedDir::acquire(&self.venv_root)?
};

Ok(InstallLocation {
venv_root: locked_dir,
python_version: self.python_version,
})
}
}
9 changes: 1 addition & 8 deletions crates/install-wheel-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,15 @@ use zip::result::ZipError;
use zip::ZipArchive;

use distribution_filename::WheelFilename;
pub use install_location::{normalize_name, InstallLocation, LockedDir};
pub use install_location::InstallLocation;
use pep440_rs::Version;
use platform_host::{Arch, Os};
pub use record::RecordEntry;
pub use script::Script;
pub use uninstall::{uninstall_wheel, Uninstall};
use uv_fs::Normalized;
use uv_normalize::PackageName;
pub use wheel::{
install_wheel, parse_key_value_file, read_record_file, relative_to, SHEBANG_PYTHON,
};

mod install_location;
pub mod linker;
#[cfg(feature = "python_bindings")]
mod python_bindings;
mod record;
mod script;
mod uninstall;
Expand Down
7 changes: 4 additions & 3 deletions crates/install-wheel-rs/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ use reflink_copy as reflink;
use tempfile::tempdir_in;
use tracing::{debug, instrument};

use crate::Error;
use distribution_filename::WheelFilename;
use pep440_rs::Version;
use pypi_types::DirectUrl;
use uv_normalize::PackageName;

use crate::install_location::InstallLocation;
use crate::script::scripts_from_ini;
use crate::script::{scripts_from_ini, Script};
use crate::wheel::{
extra_dist_info, install_data, parse_metadata, parse_wheel_version, write_script_entrypoints,
extra_dist_info, install_data, parse_metadata, parse_wheel_version, read_record_file,
write_script_entrypoints,
};
use crate::{read_record_file, Error, Script};

/// Install the given wheel to the given venv
///
Expand Down
79 changes: 0 additions & 79 deletions crates/install-wheel-rs/src/main.rs

This file was deleted.

92 changes: 0 additions & 92 deletions crates/install-wheel-rs/src/python_bindings.rs

This file was deleted.

8 changes: 4 additions & 4 deletions crates/install-wheel-rs/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use serde::{Deserialize, Serialize};
/// tqdm-4.62.3.dist-info/RECORD,,
/// ```
#[derive(Deserialize, Serialize, PartialOrd, PartialEq, Ord, Eq)]
pub struct RecordEntry {
pub path: String,
pub hash: Option<String>,
pub(crate) struct RecordEntry {
pub(crate) path: String,
pub(crate) hash: Option<String>,
#[allow(dead_code)]
pub size: Option<u64>,
pub(crate) size: Option<u64>,
}
Loading

0 comments on commit 5997d0d

Please sign in to comment.