Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error in archive file matching functionality for sdists #138

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea/
*.sqlite3
**/__pycache__/**
.DS_STORE
20 changes: 12 additions & 8 deletions crates/rattler_installs_packages/src/artifacts/sdist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use flate2::read::GzDecoder;
use miette::IntoDiagnostic;
use parking_lot::{Mutex, MutexGuard};
use serde::Serialize;

use std::ffi::OsStr;
use std::io::{ErrorKind, Read, Seek};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -61,16 +62,20 @@ impl SDist {
}

/// Find entry in tar archive
fn find_entry(&self, name: impl AsRef<str>) -> std::io::Result<Option<Vec<u8>>> {
fn find_entry(&self, name: impl AsRef<Path>) -> std::io::Result<Option<Vec<u8>>> {
let mut lock = self.file.lock();
let mut archive = generic_archive_reader(&mut lock, self.name.format)?;

fn skip_first_component(path: &Path) -> PathBuf {
path.components().skip(1).collect()
}

// Loop over entries
for entry in archive.entries()? {
let mut entry = entry?;

// Find name in archive and return this
if entry.path()?.ends_with(name.as_ref()) {
if skip_first_component(entry.path()?.as_ref()) == name.as_ref() {
let mut bytes = Vec::new();
entry.read_to_end(&mut bytes)?;
return Ok(Some(bytes));
Expand All @@ -91,7 +96,6 @@ impl SDist {
}

/// Read the build system info from the pyproject.toml
#[allow(dead_code)]
pub fn read_build_info(&self) -> Result<pyproject_toml::BuildSystem, SDistError> {
if let Some(bytes) = self.find_entry("pyproject.toml")? {
let source = String::from_utf8(bytes).map_err(|e| {
Expand Down Expand Up @@ -124,13 +128,13 @@ impl SDist {

/// Checks if this artifact implements PEP 643
/// and returns the metadata if it does
pub fn pep643_metadata(&self) -> Option<(Vec<u8>, WheelCoreMetadata)> {
pub fn pep643_metadata(&self) -> Result<Option<(Vec<u8>, WheelCoreMetadata)>, SDistError> {
// Assume we have a PKG-INFO
let (bytes, metadata) = self.read_package_info().ok()?;
let (bytes, metadata) = self.read_package_info()?;
if metadata.metadata_version.implements_pep643() {
Some((bytes, metadata))
Ok(Some((bytes, metadata)))
} else {
None
Ok(None)
}
}

Expand Down Expand Up @@ -220,7 +224,7 @@ mod tests {
// Should not fail as it is a valid PKG-INFO
// and considered reliable
let _package_db = get_package_db();
sdist.pep643_metadata().unwrap();
sdist.pep643_metadata().unwrap().unwrap();
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl PackageDb {
match result {
Ok(sdist) => {
// Save the pep643 metadata in the cache if it is available
let metadata = sdist.pep643_metadata();
let metadata = sdist.pep643_metadata().into_diagnostic()?;
if let Some((bytes, _)) = metadata {
self.put_metadata_in_cache(artifact_info, &bytes).await?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl<'db> BuildEnvironment<'db> {
build_backend: None,
backend_path: None,
});

// Find the build requirements
let build_requirements = build_requirements(&build_system);
tracing::info!(
Expand Down
Binary file modified test-data/sdists/fake-flask-3.0.0.tar.gz
Binary file not shown.