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

Remove unconstrained version error from requirements #3443

Merged
merged 1 commit into from
May 8, 2024
Merged
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
39 changes: 7 additions & 32 deletions crates/uv-requirements/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use thiserror::Error;
use url::Url;

use distribution_types::{ParsedUrlError, Requirement, RequirementSource, Requirements};
use pep440_rs::VersionSpecifiers;
use pep508_rs::{VerbatimUrl, VersionOrUrl};
use uv_configuration::PreviewMode;
use uv_fs::Simplified;
Expand Down Expand Up @@ -50,8 +51,6 @@ pub enum LoweringError {
PathToUrl(PathBuf),
#[error("Package is not included as workspace package in `tool.uv.workspace`")]
UndeclaredWorkspacePackage,
#[error("Must specify a version constraint")]
UnconstrainedVersion,
#[error("Can only specify one of rev, tag, or branch")]
MoreThanOneGitRef,
#[error("Unable to combine options in `tool.uv.sources`")]
Expand Down Expand Up @@ -283,7 +282,6 @@ impl Pep621Metadata {
let requirements = lower_requirements(
&project.dependencies.unwrap_or_default(),
&project.optional_dependencies.unwrap_or_default(),
&project.name,
project_dir,
&project_sources.unwrap_or_default(),
workspace_sources,
Expand Down Expand Up @@ -322,7 +320,6 @@ impl Pep621Metadata {
pub(crate) fn lower_requirements(
dependencies: &[String],
optional_dependencies: &IndexMap<ExtraName, Vec<String>>,
project_name: &PackageName,
project_dir: &Path,
project_sources: &HashMap<PackageName, Source>,
workspace_sources: &HashMap<PackageName, Source>,
Expand All @@ -336,7 +333,6 @@ pub(crate) fn lower_requirements(
let name = requirement.name.clone();
lower_requirement(
requirement,
project_name,
project_dir,
project_sources,
workspace_sources,
Expand All @@ -356,7 +352,6 @@ pub(crate) fn lower_requirements(
let name = requirement.name.clone();
lower_requirement(
requirement,
project_name,
project_dir,
project_sources,
workspace_sources,
Expand All @@ -378,7 +373,6 @@ pub(crate) fn lower_requirements(
/// Combine `project.dependencies` or `project.optional-dependencies` with `tool.uv.sources`.
pub(crate) fn lower_requirement(
requirement: pep508_rs::Requirement,
project_name: &PackageName,
project_dir: &Path,
project_sources: &HashMap<PackageName, Source>,
workspace_sources: &HashMap<PackageName, Source>,
Expand All @@ -389,6 +383,7 @@ pub(crate) fn lower_requirement(
.get(&requirement.name)
.or(workspace_sources.get(&requirement.name))
.cloned();

if !matches!(
source,
Some(Source::Workspace {
Expand All @@ -403,12 +398,7 @@ pub(crate) fn lower_requirement(

let Some(source) = source else {
// Support recursive editable inclusions.
// TODO(konsti): This is a workspace feature.
return if requirement.version_or_url.is_none() && &requirement.name != project_name {
Err(LoweringError::UnconstrainedVersion)
} else {
Ok(Requirement::from_pep508(requirement)?)
};
return Ok(Requirement::from_pep508(requirement)?);
};

if preview.is_disabled() {
Expand Down Expand Up @@ -488,7 +478,10 @@ pub(crate) fn lower_requirement(
path_source(path, project_dir, editable)?
}
Source::Registry { index } => match requirement.version_or_url {
None => return Err(LoweringError::UnconstrainedVersion),
None => RequirementSource::Registry {
specifier: VersionSpecifiers::empty(),
index: Some(index),
},
Some(VersionOrUrl::VersionSpecifier(version)) => RequirementSource::Registry {
specifier: version,
index: Some(index),
Expand Down Expand Up @@ -765,24 +758,6 @@ mod test {
"###);
}

#[test]
fn missing_constraint() {
let input = indoc! {r#"
[project]
name = "foo"
version = "0.0.0"
dependencies = [
"tqdm",
]
"#};

assert_snapshot!(format_err(input), @r###"
error: Failed to parse `pyproject.toml`
Caused by: Failed to parse entry for: `tqdm`
Caused by: Must specify a version constraint
"###);
}

#[test]
fn invalid_syntax() {
let input = indoc! {r#"
Expand Down
Loading