hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Include pattern

Open pycaw opened this issue 1 month ago • 4 comments

/tests does not include directory tests under root (besides pyproject.toml) as hinted here: https://hatch.pypa.io/1.9/config/build/#patterns

Is this a documentation issue?

This won't do it,

[tool.hatch.build.targets.sdist]
include = [
  "mypackage",
  "/tests"
]

While this does,

[tool.hatch.build.targets.sdist.force-include]
"tests"` = "mypackage/tests"

I have been using the latter one but I had just come across the docs while wanting to explore how to exclude some files under an included directory.

pycaw avatar Nov 14 '25 21:11 pycaw

We can update the documentation as it is misleading.

[tool.hatch.build.targets.sdist]
include = [
  "mypackage",
  "/tests"
]

should actually be

[tool.hatch.build.targets.sdist]
include = [
  "mypackage",
  "/tests/"
]

or

[tool.hatch.build.targets.sdist]
include = [
  "mypackage",
  "tests/**"
]

cjames23 avatar Nov 17 '25 19:11 cjames23

Well, now with my latest tests any of these work fine for me...

On another note, I wonder if it's possible to remap directories with build.targets.sdist. Who would want his "tests" dir exposed under "site-packages"?... Only targets.sdist.force-include can do it ("tests" = "mypackage/tests")?

pycaw avatar Nov 21 '25 18:11 pycaw

  1. Like you just mentioned, any of the patterns discussed so far should have been working.
  2. The contents of the source distribution does not directly influence what goes into site-packages. Source distributions are used exclusively for creating wheels and only their contents are unpacked directly into site-packages.

ofek avatar Nov 21 '25 21:11 ofek

  1. Like you just mentioned, any of the patterns discussed so far should have been working.

    1. The contents of the source distribution does not directly influence what goes into site-packages. Source distributions are used exclusively for creating wheels and only their contents are unpacked directly into site-packages.

Regarding 2, well, yes, in any case, problem remains: you can't use build.targets.sdist if you want to remap things so they won't go directly under site-packages (or, indeed, conversely, to wheel's/sdist's root). You are forced to use targets.sdist.force-include and then you can't apply any exclusion logic on top of that.

pycaw avatar Nov 22 '25 15:11 pycaw