Skip to content

Commit

Permalink
Move crate
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 6, 2024
1 parent 34b03e0 commit 0e5c2f8
Show file tree
Hide file tree
Showing 42 changed files with 154 additions and 95 deletions.
22 changes: 17 additions & 5 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 @@ -30,6 +30,7 @@ requirements-txt = { path = "crates/requirements-txt" }
uv-auth = { path = "crates/uv-auth" }
uv-build = { path = "crates/uv-build" }
uv-cache = { path = "crates/uv-cache" }
uv-cache-info = { path = "crates/uv-cache-info" }
uv-cli = { path = "crates/uv-cli" }
uv-client = { path = "crates/uv-client" }
uv-configuration = { path = "crates/uv-configuration" }
Expand Down
4 changes: 2 additions & 2 deletions crates/distribution-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pep440_rs = { workspace = true }
pep508_rs = { workspace = true, features = ["serde"] }
platform-tags = { workspace = true }
pypi-types = { workspace = true }
uv-cache-info = { workspace = true }
uv-fs = { workspace = true }
uv-git = { workspace = true }
uv-normalize = { workspace = true }
Expand All @@ -32,7 +33,6 @@ schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
toml = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
urlencoding = { workspace = true }
urlencoding = { workspace = true }
5 changes: 3 additions & 2 deletions crates/distribution-types/src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use anyhow::{anyhow, Result};
use distribution_filename::WheelFilename;
use pep508_rs::VerbatimUrl;
use pypi_types::{HashDigest, ParsedDirectoryUrl};
use uv_cache_info::CacheInfo;
use uv_normalize::PackageName;

use crate::{
BuiltDist, CacheInfo, Dist, DistributionMetadata, Hashed, InstalledMetadata, InstalledVersion,
Name, ParsedUrl, SourceDist, VersionOrUrlRef,
BuiltDist, Dist, DistributionMetadata, Hashed, InstalledMetadata, InstalledVersion, Name,
ParsedUrl, SourceDist, VersionOrUrlRef,
};

/// A built distribution (wheel) that exists in the local cache.
Expand Down
14 changes: 7 additions & 7 deletions crates/distribution-types/src/installed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use url::Url;
use distribution_filename::EggInfoFilename;
use pep440_rs::Version;
use pypi_types::DirectUrl;
use uv_cache_info::CacheInfo;
use uv_fs::Simplified;
use uv_normalize::PackageName;

use crate::cache_info::CacheInfo;
use crate::{DistributionMetadata, InstalledMetadata, InstalledVersion, Name, VersionOrUrlRef};

/// A built distribution (wheel) that is installed in a virtual environment.
Expand All @@ -36,7 +36,7 @@ pub struct InstalledRegistryDist {
pub name: PackageName,
pub version: Version,
pub path: PathBuf,
pub cache: Option<CacheInfo>,
pub cache_info: Option<CacheInfo>,
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
Expand All @@ -47,7 +47,7 @@ pub struct InstalledDirectUrlDist {
pub url: Url,
pub editable: bool,
pub path: PathBuf,
pub cache: Option<CacheInfo>,
pub cache_info: Option<CacheInfo>,
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -93,7 +93,7 @@ impl InstalledDist {

let name = PackageName::from_str(name)?;
let version = Version::from_str(version).map_err(|err| anyhow!(err))?;
let cache = Self::cache_info(path)?;
let cache_info = Self::cache_info(path)?;

return if let Some(direct_url) = Self::direct_url(path)? {
match Url::try_from(&direct_url) {
Expand All @@ -104,15 +104,15 @@ impl InstalledDist {
direct_url: Box::new(direct_url),
url,
path: path.to_path_buf(),
cache,
cache_info,
}))),
Err(err) => {
warn!("Failed to parse direct URL: {err}");
Ok(Some(Self::Registry(InstalledRegistryDist {
name,
version,
path: path.to_path_buf(),
cache,
cache_info,
})))
}
}
Expand All @@ -121,7 +121,7 @@ impl InstalledDist {
name,
version,
path: path.to_path_buf(),
cache,
cache_info,
})))
};
}
Expand Down
5 changes: 0 additions & 5 deletions crates/distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use uv_normalize::PackageName;
pub use crate::annotation::*;
pub use crate::any::*;
pub use crate::buildable::*;
pub use crate::cache_info::*;
pub use crate::cached::*;
pub use crate::diagnostic::*;
pub use crate::error::*;
Expand All @@ -63,15 +62,12 @@ pub use crate::prioritized_distribution::*;
pub use crate::resolution::*;
pub use crate::resolved::*;
pub use crate::specified_requirement::*;
pub use crate::timestamp::*;
pub use crate::traits::*;

mod annotation;
mod any;
mod buildable;
mod cache_info;
mod cached;
mod commit_info;
mod diagnostic;
mod error;
mod file;
Expand All @@ -83,7 +79,6 @@ mod prioritized_distribution;
mod resolution;
mod resolved;
mod specified_requirement;
mod timestamp;
mod traits;

#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/install-wheel-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ name = "install_wheel_rs"

[dependencies]
distribution-filename = { workspace = true }
distribution-types = { workspace = true }
pep440_rs = { workspace = true }
platform-tags = { workspace = true }
pypi-types = { workspace = true }
uv-cache-info = { workspace = true }
uv-fs = { workspace = true }
uv-normalize = { workspace = true }
uv-warnings = { workspace = true }
Expand Down
16 changes: 2 additions & 14 deletions crates/install-wheel-rs/Readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
Reimplementation of wheel installing in rust. Supports both classical venvs and monotrail.
# install-wheel-rs

There are simple python bindings:

```python
from install_wheel_rs import LockedVenv

locked_venv = LockedVenv("path/to/.venv")
locked_venv.install_wheel("path/to/some_tagged_wheel.whl")
```

and there's only one function: `install_wheels_venv(wheels: List[str], venv: str)`, where `wheels`
is a list of paths to wheel files and `venv` is the location of the venv to install the packages in.

See monotrail for benchmarks.
Reimplementation of wheel installing in Rust.
2 changes: 1 addition & 1 deletion crates/install-wheel-rs/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::wheel::{
};
use crate::{Error, Layout};
use distribution_filename::WheelFilename;
use distribution_types::CacheInfo;
use fs_err as fs;
use fs_err::{DirEntry, File};
use pypi_types::{DirectUrl, Metadata12};
Expand All @@ -21,6 +20,7 @@ use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use tempfile::tempdir_in;
use tracing::{debug, instrument};
use uv_cache_info::CacheInfo;
use uv_warnings::warn_user_once;
use walkdir::WalkDir;

Expand Down
9 changes: 4 additions & 5 deletions crates/install-wheel-rs/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ use std::io::{BufReader, Cursor, Read, Seek, Write};
use std::path::{Path, PathBuf};
use std::{env, io};

use crate::record::RecordEntry;
use crate::script::Script;
use crate::{Error, Layout};
use data_encoding::BASE64URL_NOPAD;
use distribution_types::CacheInfo;
use fs_err as fs;
use fs_err::{DirEntry, File};
use mailparse::parse_headers;
use pypi_types::DirectUrl;
use rustc_hash::FxHashMap;
use sha2::{Digest, Sha256};
use tracing::{instrument, warn};
use uv_cache_info::CacheInfo;
use uv_fs::{relative_to, Simplified};
use uv_normalize::PackageName;
use walkdir::WalkDir;
use zip::write::FileOptions;
use zip::ZipWriter;

use crate::record::RecordEntry;
use crate::script::Script;
use crate::{Error, Layout};

const LAUNCHER_MAGIC_NUMBER: [u8; 4] = [b'U', b'V', b'U', b'V'];

#[cfg(all(windows, target_arch = "x86"))]
Expand Down
2 changes: 0 additions & 2 deletions crates/pypi-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ license = { workspace = true }
workspace = true

[dependencies]
cache-key = { workspace = true }
distribution-filename = { workspace = true }
pep440_rs = { workspace = true }
pep508_rs = { workspace = true }
Expand All @@ -28,7 +27,6 @@ mailparse = { workspace = true }
regex = { workspace = true }
rkyv = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
toml = { workspace = true }
tracing = { workspace = true }
Expand Down
18 changes: 18 additions & 0 deletions crates/uv-cache-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "uv-cache-info"
version = "0.0.1"
edition = { workspace = true }
rust-version = { workspace = true }
homepage = { workspace = true }
documentation = { workspace = true }
repository = { workspace = true }
authors = { workspace = true }
license = { workspace = true }

[lints]
workspace = true

[dependencies]
fs-err = { workspace = true }
serde = { workspace = true, features = ["derive"] }
toml = { workspace = true }
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::path::{Path, PathBuf};

/// The current commit information for a repository.
/// The current commit for a repository.
#[derive(Default, Debug, Clone, Hash, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub(crate) struct Commit(String);

impl Commit {
/// Return the [`CommitInfo`] for the repository at the given path.
/// Return the [`Commit`] for the repository at the given path.
pub(crate) fn from_repository(path: &Path) -> Option<Self> {
// Find the `.git` directory, searching through parent directories if necessary.
let git_dir = path
Expand Down
6 changes: 6 additions & 0 deletions crates/uv-cache-info/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub use crate::cache_info::*;
pub use crate::timestamp::*;

mod cache_info;
mod commit_info;
mod timestamp;
File renamed without changes.
1 change: 1 addition & 0 deletions crates/uv-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ workspace = true
cache-key = { workspace = true }
distribution-types = { workspace = true }
pypi-types = { workspace = true }
uv-cache-info = { workspace = true }
uv-fs = { workspace = true, features = ["tokio"] }
uv-normalize = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-cache/src/by_timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use distribution_types::Timestamp;
use serde::{Deserialize, Serialize};
use uv_cache_info::Timestamp;

#[derive(Deserialize, Serialize)]
pub struct CachedByTimestamp<Data> {
Expand Down
Loading

0 comments on commit 0e5c2f8

Please sign in to comment.