Skip to content

Commit

Permalink
Allow self-depedencies in the dev section
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Oct 6, 2024
1 parent 80e76f6 commit 3f5a671
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
7 changes: 2 additions & 5 deletions crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,13 @@ pub(crate) async fn add(
};

// If any of the requirements are self-dependencies, bail.
if matches!(
dependency_type,
DependencyType::Production | DependencyType::Dev
) {
if matches!(dependency_type, DependencyType::Production) {
if let Target::Project(project, _) = &target {
if let Some(project_name) = project.project_name() {
for requirement in &requirements {
if requirement.name == *project_name {
bail!(
"Requirement name `{}` matches project name `{}`, but self-dependencies are not permitted. If your project name (`{}`) is shadowing that of a third-party dependency, consider renaming the project.",
"Requirement name `{}` matches project name `{}`, but self-dependencies are not permitted without the `--dev` or `--optional` flags. If your project name (`{}`) is shadowing that of a third-party dependency, consider renaming the project.",
requirement.name.cyan(),
project_name.cyan(),
project_name.cyan(),
Expand Down
17 changes: 13 additions & 4 deletions crates/uv/tests/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4959,7 +4959,7 @@ fn add_self() -> Result<()> {
----- stdout -----
----- stderr -----
error: Requirement name `anyio` matches project name `anyio`, but self-dependencies are not permitted. If your project name (`anyio`) is shadowing that of a third-party dependency, consider renaming the project.
error: Requirement name `anyio` matches project name `anyio`, but self-dependencies are not permitted without the `--dev` or `--optional` flags. If your project name (`anyio`) is shadowing that of a third-party dependency, consider renaming the project.
"###);

let pyproject_toml = context.temp_dir.child("pyproject.toml");
Expand Down Expand Up @@ -5023,12 +5023,16 @@ fn add_self() -> Result<()> {

// And recursive development dependencies
uv_snapshot!(context.filters(), context.add().arg("anyio[types]").arg("--dev"), @r###"
success: false
exit_code: 2
success: true
exit_code: 0
----- stdout -----
----- stderr -----
error: Requirement name `anyio` matches project name `anyio`, but self-dependencies are not permitted. If your project name (`anyio`) is shadowing that of a third-party dependency, consider renaming the project.
Resolved 2 packages in [TIME]
Prepared 1 package in [TIME]
Uninstalled 1 package in [TIME]
Installed 1 package in [TIME]
~ anyio==0.1.0 (from file://[TEMP_DIR]/)
"###);

let pyproject_toml = context.read("pyproject.toml");
Expand All @@ -5054,6 +5058,11 @@ fn add_self() -> Result<()> {
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
[tool.uv]
dev-dependencies = [
"anyio[types]",
]
[tool.uv.sources]
anyio = { workspace = true }
"###
Expand Down

0 comments on commit 3f5a671

Please sign in to comment.