Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to install a namespace package with hatch?

in The context of the sphinxcontrib organisation the package are supposed to all live in a sphinxcontrib namespace package like "sphinxcontrib.icon" or "sphinxcontrib.badge".

The file have the following structure:

sphinxcontrib-icon/
├── sphinxcontrib/
│   └── icon/
│       └── __init__.py
└── pytproject.toml 

In a setuptools based pyproject.toml file I would do the following:

# pyproject.toml

[build-system]
requires = ["setuptools>=61.2", "wheel", "pynpm>=0.2.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
include-package-data = false
packages = ["sphinxcontrib.icon"]

Now I would like to migrate to hatchings but I don't manage to reprduce this behaviour. In my parameters I do:

# pyproject.toml

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["sphinxcontrib/skeleton"]

In the "site-packages" folder my lib is not under in "sphincontrib/icon" as I would expect.

How should I adapt my code to make it work ?

I have a example sitting here: https://github.com/sphinx-contrib/sphinxcontrib-skeleton/tree/test Building the docs with nox -s docs is failing because the package is not really installed.

like image 908
Pierrick Rambaud Avatar asked Oct 31 '25 10:10

Pierrick Rambaud


1 Answers

copying here the answer given by the hatchling repository maintainers:

The packages option is for the case where your code lives under a directory like src/ and will collapse until the last path component. So if your namespace package lived under such a directory then you could set that to src/sphinxcontrib but since it's not you case

So I could simply do:

[tool.hatch.build.targets.wheel]
only-include = ["sphinxcontrib"]

Note that you could also use the regular include option there but that would still have to recurse other directories, so just a performance hack.

like image 193
Pierrick Rambaud Avatar answered Nov 02 '25 02:11

Pierrick Rambaud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!