Move portable glob parsing to struct (#13311)

Refactoring to make fixing #13280 easier.
This commit is contained in:
konsti 2025-05-06 13:22:54 +02:00 committed by GitHub
parent 3218e364ae
commit 9071e0eeac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 129 additions and 115 deletions

View file

@ -12,7 +12,7 @@ use version_ranges::Ranges;
use walkdir::WalkDir;
use uv_fs::Simplified;
use uv_globfilter::{parse_portable_glob, GlobDirFilter};
use uv_globfilter::{GlobDirFilter, PortableGlobParser};
use uv_normalize::{ExtraName, PackageName};
use uv_pep440::{Version, VersionSpecifiers};
use uv_pep508::{
@ -395,11 +395,12 @@ impl PyProjectToml {
let mut license_files = Vec::new();
let mut license_globs_parsed = Vec::new();
for license_glob in license_globs {
let pep639_glob =
parse_portable_glob(license_glob).map_err(|err| Error::PortableGlob {
let pep639_glob = PortableGlobParser.parse(license_glob).map_err(|err| {
Error::PortableGlob {
field: license_glob.to_string(),
source: err,
})?;
}
})?;
license_globs_parsed.push(pep639_glob);
}
let license_globs =

View file

@ -15,7 +15,7 @@ use tar::{EntryType, Header};
use tracing::{debug, trace};
use uv_distribution_filename::{SourceDistExtension, SourceDistFilename};
use uv_fs::Simplified;
use uv_globfilter::{parse_portable_glob, GlobDirFilter};
use uv_globfilter::{GlobDirFilter, PortableGlobParser};
use uv_pypi_types::Identifier;
use uv_warnings::warn_user_once;
use walkdir::WalkDir;
@ -88,10 +88,12 @@ fn source_dist_matcher(
.to_string();
includes.push(format!("{}/**", globset::escape(import_path)));
for include in includes {
let glob = parse_portable_glob(&include).map_err(|err| Error::PortableGlob {
field: "tool.uv.build-backend.source-include".to_string(),
source: err,
})?;
let glob = PortableGlobParser
.parse(&include)
.map_err(|err| Error::PortableGlob {
field: "tool.uv.build-backend.source-include".to_string(),
source: err,
})?;
include_globs.push(glob.clone());
}
@ -111,21 +113,22 @@ fn source_dist_matcher(
// Include the license files
for license_files in pyproject_toml.license_files_source_dist() {
trace!("Including license files at: `{license_files}`");
let glob = parse_portable_glob(license_files).map_err(|err| Error::PortableGlob {
field: "project.license-files".to_string(),
source: err,
})?;
let glob = PortableGlobParser
.parse(license_files)
.map_err(|err| Error::PortableGlob {
field: "project.license-files".to_string(),
source: err,
})?;
include_globs.push(glob);
}
// Include the data files
for (name, directory) in settings.data.iter() {
let glob =
parse_portable_glob(&format!("{}/**", globset::escape(directory))).map_err(|err| {
Error::PortableGlob {
field: format!("tool.uv.build-backend.data.{name}"),
source: err,
}
let glob = PortableGlobParser
.parse(&format!("{}/**", globset::escape(directory)))
.map_err(|err| Error::PortableGlob {
field: format!("tool.uv.build-backend.data.{name}"),
source: err,
})?;
trace!("Including data ({name}) at: `{directory}`");
include_globs.push(glob);

View file

@ -12,7 +12,7 @@ use zip::{CompressionMethod, ZipWriter};
use uv_distribution_filename::WheelFilename;
use uv_fs::Simplified;
use uv_globfilter::{parse_portable_glob, GlobDirFilter};
use uv_globfilter::{GlobDirFilter, PortableGlobParser};
use uv_platform_tags::{AbiTag, LanguageTag, PlatformTag};
use uv_pypi_types::Identifier;
use uv_warnings::warn_user_once;
@ -432,10 +432,12 @@ pub(crate) fn build_exclude_matcher(
} else {
format!("**/{exclude}").to_string()
};
let glob = parse_portable_glob(&exclude).map_err(|err| Error::PortableGlob {
field: "tool.uv.build-backend.*-exclude".to_string(),
source: err,
})?;
let glob = PortableGlobParser
.parse(&exclude)
.map_err(|err| Error::PortableGlob {
field: "tool.uv.build-backend.*-exclude".to_string(),
source: err,
})?;
exclude_builder.add(glob);
}
let exclude_matcher = exclude_builder
@ -467,7 +469,7 @@ fn wheel_subdir_from_globs(
src.user_display(),
license_files
);
parse_portable_glob(license_files)
PortableGlobParser.parse(license_files)
})
.collect::<Result<_, _>>()
.map_err(|err| Error::PortableGlob {