I have a project structured like this:
<project-root>
├── pyproject.toml
└── src
└── a_namespace
└── a_module.py
With Poetry, I can install and package this project using the following settings:
[tool.poetry]
packages = [
{ include = "a_namespace/a_module.py", from = "src" },
]
However, I can’t get this to work with uv. According to the documentation, I need to do this:
[tool.uv.build-backend]
module-name = "a_namespace.a_module"
But this results in the following error:
× Failed to build ... @ file:///...`
╰─▶ Expected a Python module at: src/a_namespace/a_module/__init__.py
Adding .py doesn't solve the problem.
[tool.uv.build-backend]
module-name = "a_namespace.a_module.py"
× Failed to build ... @ file:///...`
╰─▶ Expected a Python module at: src/a_namespace/a_module/py/__init__.py
import-names and import-namespaces don't seem to work either.
[project]
import-namespaces = ["a_namespace"]
import-names = ["a_namespace.a_module"]
I just successfully installed the project with the following settings:
[tool.uv.build-backend]
module-name = "a_library.a_module"
namespace = true
I’ve been aware of this namespace option the whole time, but I’d been avoiding it because the documentation scared me with this warning:
Using
namespace = truedisables safety checks. Using an explicit list of module names is strongly recommended outside of legacy projects.
Edit: While I succeeded in the installation, packaging failed. I gave up on the non-__init__.py structure, and ended up with the following one.
<project-root>
├── pyproject.toml
└── src
└── a_namespace
└── a_module
└── __init__.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With