mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-20 15:22:53 +00:00
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:
parent
cadba18c1f
commit
fee6ab58c0
3 changed files with 173 additions and 19 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue