Move extra specification into uv-configuration (#3897)

## Summary

I need to use this in the resolver (and it's at-home with other, similar
configuration options).
This commit is contained in:
Charlie Marsh 2024-05-29 00:49:57 -04:00 committed by GitHub
parent 2b6c24ed2d
commit 3461c8b585
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 69 additions and 70 deletions

View file

@ -24,13 +24,13 @@ use distribution_types::{Requirement, RequirementSource, Requirements};
use pep440_rs::VersionSpecifiers;
use pep508_rs::{Pep508Error, RequirementOrigin, VerbatimUrl, VersionOrUrl};
use pypi_types::VerbatimParsedUrl;
use uv_configuration::PreviewMode;
use uv_configuration::{ExtrasSpecification, PreviewMode};
use uv_fs::Simplified;
use uv_git::GitReference;
use uv_normalize::{ExtraName, PackageName};
use uv_warnings::warn_user_once;
use crate::{ExtrasSpecification, Workspace};
use crate::Workspace;
#[derive(Debug, Error)]
pub enum Pep621Error {
@ -683,12 +683,12 @@ mod test {
use indoc::indoc;
use insta::assert_snapshot;
use uv_configuration::PreviewMode;
use uv_configuration::{ExtrasSpecification, PreviewMode};
use uv_fs::Simplified;
use uv_normalize::PackageName;
use crate::ProjectWorkspace;
use crate::{ExtrasSpecification, RequirementsSpecification};
use crate::RequirementsSpecification;
fn from_source(
contents: &str,

View file

@ -12,13 +12,12 @@ use distribution_types::{
};
use pep508_rs::RequirementOrigin;
use pypi_types::VerbatimParsedUrl;
use uv_configuration::ExtrasSpecification;
use uv_distribution::{DistributionDatabase, Reporter};
use uv_fs::Simplified;
use uv_resolver::{InMemoryIndex, MetadataResponse};
use uv_types::{BuildContext, HashStrategy};
use crate::ExtrasSpecification;
/// A resolver for requirements specified via source trees.
///
/// Used, e.g., to determine the input requirements when a user specifies a `pyproject.toml`

View file

@ -3,7 +3,6 @@ use std::path::{Path, PathBuf};
use console::Term;
use uv_fs::Simplified;
use uv_normalize::ExtraName;
use uv_warnings::warn_user;
use crate::confirm;
@ -154,37 +153,3 @@ impl std::fmt::Display for RequirementsSource {
}
}
}
#[derive(Debug, Default, Clone)]
pub enum ExtrasSpecification {
#[default]
None,
All,
Some(Vec<ExtraName>),
}
impl ExtrasSpecification {
/// Determine the extras specification to use based on the command-line arguments.
pub fn from_args(all_extras: bool, extra: Vec<ExtraName>) -> Self {
if all_extras {
ExtrasSpecification::All
} else if extra.is_empty() {
ExtrasSpecification::None
} else {
ExtrasSpecification::Some(extra)
}
}
/// Returns true if a name is included in the extra specification.
pub fn contains(&self, name: &ExtraName) -> bool {
match self {
ExtrasSpecification::All => true,
ExtrasSpecification::None => false,
ExtrasSpecification::Some(extras) => extras.contains(name),
}
}
pub fn is_empty(&self) -> bool {
matches!(self, ExtrasSpecification::None)
}
}

View file

@ -47,13 +47,13 @@ use requirements_txt::{
EditableRequirement, FindLink, RequirementEntry, RequirementsTxt, RequirementsTxtRequirement,
};
use uv_client::BaseClientBuilder;
use uv_configuration::{NoBinary, NoBuild, PreviewMode};
use uv_configuration::{ExtrasSpecification, NoBinary, NoBuild, PreviewMode};
use uv_fs::Simplified;
use uv_normalize::{ExtraName, PackageName};
use crate::pyproject::{Pep621Metadata, PyProjectToml};
use crate::ProjectWorkspace;
use crate::{ExtrasSpecification, RequirementsSource, Workspace, WorkspaceError};
use crate::{RequirementsSource, Workspace, WorkspaceError};
#[derive(Debug, Default)]
pub struct RequirementsSpecification {