Allow package-data for stubs packages#248
Conversation
|
/CC @abravalheri |
|
Sorry for the delay. I think that this is very reasonable. Can we somehow re-use the existing definition?
Sure, it may take a little bit however, I want to wait for the situation to stabilise. |
|
Sorry for the late reply. I somehow lost track of it.
Unless I'm missing something, it isn't really possible unfortunately. While the package name itself is normalized by setuptools, I don't think the name in the |
|
@abravalheri Did you had a chance to look at this again? |
|
Hi @cdce8p, sorry for the delay in getting back to this.
I am not sure I follow. I tested the following snippet for "anyOf": [
{ "$ref": "#/definitions/package-name" },
{ "const": "*" }
]Note that As for the Personally, I’d prefer keeping this logic in the JSON Schema itself rather than introducing another format function. If you’re okay with that, I can push my local copy with these changes. Footnotes
|
Not quite, the point I'm worried about is that the package name itself is normalized by setuptools, however the [project]
name = "some-project"
[tool.setuptools.package-data]
"some-project" = ["*.yaml"]Files stored in |
|
Any update? |
|
Sorry for the delay,
So if I understand correctly, the error you are concerned about is when the person writes This is a tricky one... but since both variations are allowed to coexist and they are both individually considered valid packages, I don't think we can enforce that distinction. This was a feature request from the setuptools issue tracker (if I am not wrong), previously only Now both |
Correct.
I think of it differently. On is the project name itself whereas the other references the directory. So I think the distinction does make sense. Unless I'm missing something, there are basically two options now
Personally, I'd recommend option 1. If there is a desire for package-data normalization, this could be added separately later. |
|
Thanks for the clarification. I think we have some partial alignment, but I would like to refine one point for accuracy (and comment on its consequences):
This statement seem to imply that "setuptools enforces the name to match the directory", which would not be entirely precise. What setuptools actually does is: if the directory name matches the package name in the configuration (exactly, without normalisation), then the files are included. If they don't match, setuptools simply doesn't include them. It doesn't actively enforce the match beyond that behaviour. It's also worth noting that setuptools allows two distinct package names that differ only by This flexibility was introduced because of a feature request from setuptools: previously, Here's a quick demo showing Python treating them as distinct: # docker run --rm -it python:3.12-bookworm /bin/bash
mkdir -p /tmp/pkg/pip_run
echo "print('1: this is pip_run')" > /tmp/pkg/pip_run/__main__.py
mkdir -p /tmp/pkg/pip-run
echo "print('2: this is pip-run')" > /tmp/pkg/pip-run/__main__.py
cd /tmp/pkg
python -m pip_run
# 1: this is pip_run
python -c 'print(__import__("importlib").import_module("pip_run"))'
# <module 'pip_run' (namespace) from ['/tmp/pkg/pip_run']>
python -m pip-run
# 2: this is pip-run
python -c 'print(__import__("importlib").import_module("pip-run"))'
# <module 'pip-run' (namespace) from ['/tmp/pkg/pip-run']>(not saying that this is a good or bad thing, just illustrating existing behaviour). (Sorry for leaning on So, let's assume a hypothetical package wants to offer a "normal" API access. It would likely have If the same package also want to have a convenient CLI shortcut via At the end of the day allowing |
|
Thanks for the detailed explanation! It seems I've got some things messed up along the way. If I understand you correctly, your suggestion is to reuse the Just pushed a new commit for it. |
|
@abravalheri Any update? |
|
Sure, sorry for the delay :P (it does not apply immediately to setuptools until we update the code there) |
I'm currently working on moving the
stubs_uploaderfromsetup.pytopyproject.toml. It's used to build and upload the typeshed stubs packages automatically. While doing so I noticed thatsetuptoolsrejects stub package names likerequests-stubsforpackage-data. I know that.pyiandpy.typedfiles are auto-included. Each stubs package also contains aMETADATA.tomlfile which should be included in the distribution. Do to the nature of the project, it would be desirable to useinclude-package-data = falseand instead specify the wanted files directly.This PR slightly modifies the schema to allow for that. If accepted, it would be great if a new version could be released so I include these changes in setuptools.
https://github.com/typeshed-internal/stub_uploader/blob/cbdc0b85972e476b4dedbd626cd12dadf7dd60a9/stub_uploader/build_wheel.py#L51-L84