Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Dec 13, 2023
1 parent 84cee2d commit 517202b
Show file tree
Hide file tree
Showing 64 changed files with 864 additions and 311 deletions.
15 changes: 12 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.venv

# Generated by Cargo
# will have compiled files and executables
debug/
Expand All @@ -14,5 +12,16 @@ target/
# Use e.g. `--cache-dir cache-docker` to keep a cache across container invocations
cache-*

# python tmp files
# Python tmp files
__pycache__

# Maturin builds, and other native editable builds
*.so
*.pyd
*.dll

# Profiling
flamegraph.svg
perf.data
perf.data.old
profile.json
6 changes: 6 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 crates/distribution-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ puffin-cache = { path = "../puffin-cache" }
puffin-git = { path = "../puffin-git" }
puffin-normalize = { path = "../puffin-normalize" }
pypi-types = { path = "../pypi-types" }
requirements-txt = { path = "../requirements-txt" }

anyhow = { workspace = true }
fs-err = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/distribution-types/src/direct_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl TryFrom<&LocalFileUrl> for pypi_types::DirectUrl {

fn try_from(value: &LocalFileUrl) -> Result<Self, Self::Error> {
Ok(pypi_types::DirectUrl::LocalDirectory {
url: value.url.to_string(),
url: value.url.clone(),
dir_info: pypi_types::DirInfo { editable: None },
})
}
Expand All @@ -141,7 +141,7 @@ impl TryFrom<&DirectArchiveUrl> for pypi_types::DirectUrl {

fn try_from(value: &DirectArchiveUrl) -> Result<Self, Self::Error> {
Ok(pypi_types::DirectUrl::ArchiveUrl {
url: value.url.to_string(),
url: value.url.clone(),
archive_info: pypi_types::ArchiveInfo {
hash: None,
hashes: None,
Expand All @@ -156,7 +156,7 @@ impl TryFrom<&DirectGitUrl> for pypi_types::DirectUrl {

fn try_from(value: &DirectGitUrl) -> Result<Self, Self::Error> {
Ok(pypi_types::DirectUrl::VcsUrl {
url: value.url.repository().to_string(),
url: value.url.repository().clone(),
vcs_info: pypi_types::VcsInfo {
vcs: pypi_types::VcsKind::Git,
commit_id: value.url.precise().as_ref().map(ToString::to_string),
Expand Down
23 changes: 23 additions & 0 deletions crates/distribution-types/src/editable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use requirements_txt::EditableRequirement;
use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use url::Url;

#[derive(Debug, Clone)]
pub struct LocalEditable {
pub requirement: EditableRequirement,
/// Either the path to the editable or its checkout
pub path: PathBuf,
}

impl LocalEditable {
pub fn url(&self) -> Url {
Url::from_directory_path(&self.path).expect("A valid path makes a valid url")
}
}

impl Display for LocalEditable {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.requirement.fmt(f)
}
}
2 changes: 2 additions & 0 deletions crates/distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ use pypi_types::{File, IndexUrl};

pub use crate::any::*;
pub use crate::cached::*;
pub use crate::editable::LocalEditable;
pub use crate::error::*;
pub use crate::installed::*;
pub use crate::traits::*;

mod any;
mod cached;
pub mod direct_url;
mod editable;
mod error;
mod installed;
mod traits;
Expand Down
17 changes: 10 additions & 7 deletions crates/install-wheel-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub enum Error {
/// the metadata name and the dist info name are lowercase, while the wheel name is uppercase.
/// Either way, we just search the wheel for the name.
///
/// Returns the dist info dir prefix without the `.dist-info` extension.
///
/// Reference implementation: <https://github.com/pypa/packaging/blob/2f83540272e79e3fe1f5d42abae8df0c14ddf4c2/src/packaging/utils.py#L146-L172>
pub fn find_dist_info<'a, T: Copy>(
filename: &WheelFilename,
Expand All @@ -106,13 +108,13 @@ pub fn find_dist_info<'a, T: Copy>(
&& Version::from_str(version).ok()? == filename.version
&& file == "METADATA"
{
Some((payload, dist_info_dir))
Some((payload, dir_stem))
} else {
None
}
})
.collect();
let (payload, dist_info_dir) = match metadatas[..] {
let (payload, dist_info_prefix) = match metadatas[..] {
[] => {
return Err(Error::MissingDistInfo);
}
Expand All @@ -127,18 +129,19 @@ pub fn find_dist_info<'a, T: Copy>(
));
}
};
Ok((payload, dist_info_dir))
Ok((payload, dist_info_prefix))
}

/// Given an archive, read the `dist-info` metadata into a buffer.
pub fn read_dist_info(
filename: &WheelFilename,
archive: &mut ZipArchive<impl Read + Seek + Sized>,
) -> Result<Vec<u8>, Error> {
let dist_info_dir = find_dist_info(filename, archive.file_names().map(|name| (name, name)))?.1;
let dist_info_prefix =
find_dist_info(filename, archive.file_names().map(|name| (name, name)))?.1;

let mut file = archive
.by_name(&format!("{dist_info_dir}/METADATA"))
.by_name(&format!("{dist_info_prefix}.dist-info/METADATA"))
.map_err(|err| Error::Zip(filename.to_string(), err))?;

#[allow(clippy::cast_possible_truncation)]
Expand Down Expand Up @@ -170,8 +173,8 @@ mod test {
"Mastodon.py-1.5.1.dist-info/RECORD",
];
let filename = WheelFilename::from_str("Mastodon.py-1.5.1-py2.py3-none-any.whl").unwrap();
let (_, dist_info_dir) =
let (_, dist_info_prefix) =
find_dist_info(&filename, files.into_iter().map(|file| (file, file))).unwrap();
assert_eq!(dist_info_dir, "Mastodon.py-1.5.1.dist-info");
assert_eq!(dist_info_prefix, "Mastodon.py-1.5.1");
}
}
6 changes: 3 additions & 3 deletions crates/install-wheel-rs/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ pub(crate) fn read_scripts_from_section(
/// Extras are supposed to be ignored, which happens if you pass None for extras
fn parse_scripts<R: Read + Seek>(
archive: &mut ZipArchive<R>,
dist_info_prefix: &str,
dist_info_dir: &str,
extras: Option<&[String]>,
) -> Result<(Vec<Script>, Vec<Script>), Error> {
let entry_points_path = format!("{dist_info_prefix}.dist-info/entry_points.txt");
let entry_points_path = format!("{dist_info_dir}/entry_points.txt");
let entry_points_mapping = match archive.by_name(&entry_points_path) {
Ok(mut file) => {
let mut ini_text = String::new();
Expand Down Expand Up @@ -1043,7 +1043,7 @@ fn dist_info_metadata(
archive: &mut ZipArchive<impl Read + Seek + Sized>,
) -> Result<Vec<u8>, Error> {
let mut content = Vec::new();
let dist_info_file = format!("{dist_info_prefix}.dist-info/DIST-INFO");
let dist_info_file = format!("{dist_info_prefix}.dist-info/METADATA");
archive
.by_name(&dist_info_file)
.map_err(|err| Error::Zip(dist_info_file.clone(), err))?
Expand Down
20 changes: 1 addition & 19 deletions crates/puffin-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use zip::ZipArchive;

use pep508_rs::Requirement;
use puffin_interpreter::{Interpreter, Virtualenv};
use puffin_traits::BuildContext;
use puffin_traits::{BuildContext, BuildKind};

/// e.g. `pygraphviz/graphviz_wrap.c:3020:10: fatal error: graphviz/cgraph.h: No such file or directory`
static MISSING_HEADER_RE: Lazy<Regex> = Lazy::new(|| {
Expand Down Expand Up @@ -184,24 +184,6 @@ impl Pep517Backend {
}
}

#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum BuildKind {
/// A regular PEP 517 wheel build
#[default]
Wheel,
/// A PEP 660 editable installation wheel build
Editable,
}

impl Display for BuildKind {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
BuildKind::Wheel => f.write_str("wheel"),
BuildKind::Editable => f.write_str("editable"),
}
}
}

/// Uses an [`Arc`] internally, clone freely
#[derive(Debug, Default, Clone)]
pub struct SourceBuildContext {
Expand Down
5 changes: 4 additions & 1 deletion crates/puffin-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ name = "puffin"
path = "src/main.rs"

[dependencies]
distribution-filename = { path = "../distribution-filename" }
distribution-types = { path = "../distribution-types" }
gourgeist = { path = "../gourgeist" }
install-wheel-rs = { path = "../install-wheel-rs", default-features = false }
pep440_rs = { path = "../pep440-rs" }
pep508_rs = { path = "../pep508-rs" }
platform-host = { path = "../platform-host" }
platform-tags = { path = "../platform-tags" }
puffin-build = { path = "../puffin-build" }
puffin-cache = { path = "../puffin-cache", features = ["clap"] }
puffin-client = { path = "../puffin-client" }
puffin-dispatch = { path = "../puffin-dispatch" }
distribution-types = { path = "../distribution-types" }
puffin-distribution = { path = "../puffin-distribution" }
puffin-installer = { path = "../puffin-installer" }
puffin-interpreter = { path = "../puffin-interpreter" }
Expand Down Expand Up @@ -71,6 +73,7 @@ tikv-jemallocator = "0.5.0"
[dev-dependencies]
assert_cmd = { version = "2.0.12" }
assert_fs = { version = "1.0.13" }
indoc = { version = "2.0.4" }
insta-cmd = { version = "0.4.0" }
insta = { version = "1.34.0", features = ["filters"] }
predicates = { version = "3.0.4" }
Expand Down
Loading

0 comments on commit 517202b

Please sign in to comment.