astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
24.91k stars 721 forks source link

Overwrite pyproject when workspaces have same normalized name #8702

Open juan-abia opened 1 day ago

juan-abia commented 1 day ago

I have the following folder structure:

/private/tmp/super-project git:[main]
tree
.
├── README.md
├── pyproject.toml
├── super_project
│   ├── README.md
│   └── pyproject.toml
└── uv.lock

This is a common use case in my company. The repo name is super-project and the name of the python package we publish is super_project.

This is the content of the root pyproject.toml:

[project]
name = "super-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "super_project"
]

[tool.uv.workspace]
members = ["super_project"]

[tool.uv.sources]
super_project = { workspace = true }

[group-dependencies]
dev = [
    "pytest >=7.2.2",
]

This is the pyproject of the package:

[project]
name = "super_project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "matplotlib"
]

When I run uv run pytest y get the next error:

error: Failed to spawn: `pytest`
  Caused by: No such file or directory (os error 2

And worse. If I try to do uv add pytest, my root pyproject gets overwriten with the pyproject of the package.

I guess the issue is related to https://github.com/astral-sh/uv/issues/8591

CarlosRicGuerrero commented 1 day ago

I got the same issue too.

alex47ST3 commented 1 day ago

same problem here as well

zanieb commented 1 day ago

I don't think you can have an outer and inner pyproject.toml with the same name — those names must be unique when normalized and we must normalize them for comparison per the Python standards.

zanieb commented 1 day ago

Can you explain more about how it's overwritten? And why you're using this structure in the first place?

charliermarsh commented 1 day ago

Yeah that's not a valid structure. It's like saying you want two packages on PyPI called foo_bar and foo-bar, and you want to be able to use them distinctly.

juan-abia commented 1 day ago

So for this example:

/private/tmp/super-project git:[main]
tree
.
├── super_project
│   ├── README.md
│   └── pyproject.toml
├── super_project_2
│   ├── README.md
│   └── pyproject.toml
├── README.md
├── pyproject.toml
└── uv.lock

I want only two packages published to Pypi: super-project and super-project-2.

I'd like the two folders to be uv workspaces. When I'm developing locally I'd like to install dependencies of both packages. Is there any way I can do this with uv?

juan-abia commented 1 day ago

Can you explain more about how it's overwritten?

With this structure, if I do uv add --dev pytest for example. The pyproject of the root folder gets completely overwritten by:

pyproject of super_project (with underscore, the package) + dev group dependency with pytest