Build backend: Add functions to collect file list (#9602)

Using the directory writer trait, we can collect the files instead of
writing them to a real sink. This builds up to a `uv build --list`
similar to `cargo package --list`. It is not connected to the cli yet.
This commit is contained in:
konsti 2024-12-03 11:58:02 +01:00 committed by GitHub
parent cadba18c1f
commit fee6ab58c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 173 additions and 19 deletions

View file

@ -1,6 +1,6 @@
use crate::metadata::{BuildBackendSettings, DEFAULT_EXCLUDES};
use crate::wheel::build_exclude_matcher;
use crate::{DirectoryWriter, Error, PyProjectToml};
use crate::{DirectoryWriter, Error, FileList, ListWriter, PyProjectToml};
use flate2::write::GzEncoder;
use flate2::Compression;
use fs_err::File;
@ -35,6 +35,26 @@ pub fn build_source_dist(
Ok(filename)
}
/// List the files that would be included in a source distribution and their origin.
pub fn list_source_dist(
source_tree: &Path,
uv_version: &str,
) -> Result<(SourceDistFilename, FileList), Error> {
let contents = fs_err::read_to_string(source_tree.join("pyproject.toml"))?;
let pyproject_toml = PyProjectToml::parse(&contents)?;
let filename = SourceDistFilename {
name: pyproject_toml.name().clone(),
version: pyproject_toml.version().clone(),
extension: SourceDistExtension::TarGz,
};
let mut files = FileList::new();
let writer = ListWriter::new(&mut files);
write_source_dist(source_tree, writer, uv_version)?;
// Ensure a deterministic order even when file walking changes
files.sort_unstable();
Ok((filename, files))
}
/// Build includes and excludes for source tree walking for source dists.
fn source_dist_matcher(
pyproject_toml: &PyProjectToml,