astral-sh / uv

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

When I use `uv add <path>` to add a local package, no errors appear, but the installation is not successful. #7570

Open vvandk opened 1 hour ago

vvandk commented 1 hour ago

When I use uv add <path> to add a local package, no errors appear, but the installation is not successful.

$ uv --version
uv 0.4.13 (Homebrew 2024-09-19)
$ uv venv
Using Python 3.10.9 interpreter at: /Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
$ uv add ../kinit-config  
Resolved 21 packages in 1ms
Audited 17 packages in 0.12ms
$ uv run config_ex.py 
Traceback (most recent call last):
  File "/Users/ktianc/programming/ktianc/project/kinit_v2/kinit_runtime/config_ex.py", line 1, in <module>
    from kinit_config import settings
ModuleNotFoundError: No module named 'kinit_config'

Below is my kinit-config and pyproject.toml configuration:

[project]
name = "kinit-config"
version = "0.0.1"
description = "kinit config"
license = { file = "LICENSE" }
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
    "pydantic-settings>=2.5.2",
    "pydantic>=2.9.2",
]

[tool.setuptools]
packages = ["kinit_config"]

Here is the pyproject.toml configuration after I executed the uv add ../kinit-config/ command

[project]
name = "kinit_runtime"
version = "0.0.1"
description = "kinit runtime"
license = { file = "LICENSE" }
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
    "fastapi>=0.115.0",
    "kinit-config",
    "loguru>=0.7.2",
    "pydantic-settings>=2.5.2",
    "rich>=13.8.1",
]

[tool.uv.sources]
kinit-config = { path = "../kinit-config" }

[tool.setuptools]
packages = ["kinit_runtime"]
zanieb commented 1 hour ago

Thanks for the report! Can you try uv sync --reinstall --refresh-package kinit-config?

vvandk commented 1 hour ago
$ uv pip list
Package           Version
----------------- -------
annotated-types   0.7.0
anyio             4.4.0
exceptiongroup    1.2.2
fastapi           0.115.0
idna              3.10
loguru            0.7.2
markdown-it-py    3.0.0
mdurl             0.1.2
pydantic          2.9.2
pydantic-core     2.23.4
pydantic-settings 2.5.2
pygments          2.18.0
python-dotenv     1.0.1
rich              13.8.1
sniffio           1.3.1
starlette         0.38.5
typing-extensions 4.12.2

The kinit-config was not found.

charliermarsh commented 1 hour ago

I think you need to add a [build-system] to kinit-config/pyproject.toml.

charliermarsh commented 1 hour ago

For example:

[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"

Otherwise, we treat the project as a non-packed project. See https://docs.astral.sh/uv/concepts/projects/#creating-projects.

zanieb commented 1 hour ago

I thought we just did that for workspace members. Do we do that for path dependencies too? Or is this a workspace member and I'm missing it?

Anyway, we might want to sniff for [tool.setuptools] and warn if we don't have a build-system and aren't going to package the project.