hatch icon indicating copy to clipboard operation
hatch copied to clipboard

distribute local dependencies with hatch build

Open pvardanis opened this issue 1 year ago • 7 comments

I have specified a local dependency in pyproject.toml as follows:

[build-system]
requires = ["hatchling>=1.9.0", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "foo"
dependencies = [
"bar @ file://{root:uri}/<relative-path-to-bar>"
]

that is a local dependency including its own pyproject.toml file that uses poetry as the backend.

I want to build my foo project and distribute the wheel on PyPI however I realize that if I try to install the wheel on another OS it raises the following error:

ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory

Is there any way I can include bar in the foo distribution so that when an external user does a pip install it can automatically resolve the relative path and use the one included in my distribution instead? I've tried using something like:

[tool.hatch.build.force-include]
<relative-path-to-bar> = "foo/bar"

or

[tool.hatch.build.targets.wheel.force-include]
<relative-path-to-bar> = "bar"

and changing the dependency to "bar @ file://bar", but neither worked.

pvardanis avatar Feb 14 '24 11:02 pvardanis

There is no built-in support for vendoring. If that other project is not on PyPI is it possible to simply move that into the main project?

ofek avatar Feb 14 '24 14:02 ofek

@ofek I'd want to avoid that because both foo and bar are part of a mono repo.

pvardanis avatar Feb 14 '24 14:02 pvardanis

Then you can try the forced inclusion again but use the path to the actual package e.g. foo/src/foo.

ofek avatar Feb 14 '24 15:02 ofek

@ofek you mean the src code for bar or the whole folder with its pyproject.toml included? And with [tool.hatch.build.force-include] or [tool.hatch.build.targets.wheel.force-include]? Also, what requirement path should I use for bar then? An example code would be definitely useful. Thanks for the help :)

pvardanis avatar Feb 14 '24 15:02 pvardanis

[tool.hatch.build.targets.wheel.force-include]
"bar/src/bar" = "foo/bar"

ofek avatar Feb 14 '24 19:02 ofek

do I still need to specify bar as a dependency though? I don't want to only include the source code of bar but also install the dependencies of bar when I install the wheel for foo

pvardanis avatar Feb 14 '24 20:02 pvardanis

You will need to manually duplicate its dependencies, this is not supported yet.

ofek avatar Feb 14 '24 21:02 ofek