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

Automatically detect workspace packages in uv add #4557

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

charliermarsh
Copy link
Member

Summary

If the package isn't marked as workspace = true, locking will fail given:

let workspace_package_declared =
    // We require that when you use a package that's part of the workspace, ...
    !workspace.packages().contains_key(&requirement.name)
    // ... it must be declared as a workspace dependency (`workspace = true`), ...
    || matches!(
        source,
        Some(Source::Workspace {
            // By using toml, we technically support `workspace = false`.
            workspace: true,
            ..
        })
    )
    // ... except for recursive self-inclusion (extras that activate other extras), e.g.
    // `framework[machine_learning]` depends on `framework[cuda]`.
    || &requirement.name == project_name;
if !workspace_package_declared {
    return Err(LoweringError::UndeclaredWorkspacePackage);
}

Closes #4552.

@charliermarsh charliermarsh added the cli Related to the command line interface label Jun 26, 2024
@charliermarsh
Copy link
Member Author

I am wondering why we require that workspace packages are marked as workspace if we enforce it here. Should we just do this automatically?

Copy link
Member

@ibraheemdev ibraheemdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we error if you try to add a requirement with the same name from a different source? e.g. if you have a workspace member foo and run uv add git+https://github.com/bar/foo.

@charliermarsh
Copy link
Member Author

That seems reasonable, yeah.

@charliermarsh
Copy link
Member Author

Ahh, I think we already do that?

@charliermarsh
Copy link
Member Author

I added a test and improved the error messages.

@charliermarsh charliermarsh merged commit 45c271d into main Jun 26, 2024
47 checks passed
@charliermarsh charliermarsh deleted the charlie/add-workspace branch June 26, 2024 18:03
@konstin
Copy link
Member

konstin commented Jun 27, 2024

I am wondering why we require that workspace packages are marked as workspace if we enforce it here. Should we just do this automatically?

It ensures that you can see in a single pyproject.toml what source each requirements has (registry, url or workspace) and prevents accidentally using registry packages. I've copied this from cargo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command line interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uv add should default to --workspace if the package is a workspace member
3 participants