-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fail on package data include package data combination #1887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail on package data include package data combination #1887
Conversation
Thanks for this @vanschelven! Can you please add a test for this? I'm also wondering if maybe this should be a warning rather than an error, at least at first? This isn't really something where the build is necessarily broken if you do it, and it may cause unnecessary headaches for people to find that their builds are suddenly broken when they used to "work" just fine. Of course, most people don't ever see warnings, especially not in |
Reading through the diff, it seems it has always been the intention that the union of the two options is honored (pganssle's preferred option in the issue). I don't think we want to adopt this proposed behavior, as I suspect it will be likely to cause problems for legitimate use-cases. |
@jaraco I think I decided in that ticket that my preferred option was infeasible because it would subtly change what gets included in your packages, and if we were to change it we might get packages including different things based on what version of That said, it is almost certainly true that no one is deliberately counting on I still like the idea of phasing out |
Regarding warning-before-error: I initially imagined that the error would almost exclusively be raised on the machine of original package-developers, and hence would be easy to solve. That's why I skipped on Warnings altogether. I now realise that there are quite a few scenarios in which this is not so. Namely: all scenarios in which packages are not installed as wheels, but built locally. On the other hand: I seriously doubt it will make a difference in practice: it's not like this warning will be displayed on its own; it's somewhere in there with the whole output of setup.py. Regarding the backwards incompatability: I would agree that people would not generally deliberately depend on Anyways... if you guys are willing to go ahead with the present solution, I'll gladly add some tests. |
An important aspect of Most importantly, whatever solution is devised, it must be possible to do what is possible now - to configure a project such that files added in the SCM are automatically included in the package and to do that in a generic way that needs no details about the particular project. I should note too that this change is likely to break projects that rely on file-finders and happen to define package_data (even though it's being ignored). This is the type of change that needs to have a deprecation period (and possibly a very long one, because setuptools aims to be able to build previous-published projects). |
Yeah, this is a major problem with It seems to me that we should either use some sort of function that generates an input to To me the important thing is that right now |
Anything I could do to get this out of analysis-paralysis? I was thinking of reducing the scope of the solution somewhat, by changing the error into a warning. That would avoid breakage, and the documentation-changes already present in the PR would help avoid future confusion. If this is something we can all agree on, I'll gladly proceed accordingly and will add those tests that were requested. |
By the way, to think that the combination of parameters has some useful behaviour appears to be a common error: |
I think a warning is the least we can do here and seems uncontroversial, so let's start with that. |
8112c2f
to
44f8fac
Compare
I updated my implementation accordingly approximately one month ago. Anything I can do to push this forward? |
I'll try to get to merging this within a week. Don't hesitate to ping me if I haven't addressed it by the coming Monday. |
@@ -602,3 +605,27 @@ def test_prune(self): | |||
file_list.sort() | |||
assert file_list.files == ['a.py', ml('f/f.py')] | |||
self.assertWarnings() | |||
|
|||
def test_warning_on_meaningless_parameter_combination(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want a test for this behavior. Tests are mainly for behavior we wish to enforce. This particular behavior, that a warning is issued, is incidental to the intention. I'm not sure it quite captures what we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying we shouldn't add a test for the warning at all, or that this particular test doesn't correctly cover the use case?
I personally think we should be testing that a warning is raised in the right conditions (and, preferably, asserting that no warning is raised under the wrong conditions as well, though I think #1823 should cover us in that situation, since any uncaptured warning would be considered a failure).
In general I don't love the idea of exact matches on the warning message, though. To me the user-facing behavior we want to enforce is, "A warning will be issued in this situation that describes the problem," so the precise wording of 'Distutils 'package_data'...
. Normally I would avoid false positives by checking the warning type, but I do think it's common to use the self.warn
mechanism here instead of the warnings module.
I think maybe we can do something a bit looser, use a assert_called_once
and then check that the message includes package_data
and include_package_data
, possibly with a comment like, "This is a heuristic to detect whether the correct warning was raised; the exact warning message is not guaranteed to be stable."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. This test does provide some value. In fact, it enabled me to readily confirm my suspicions that the behavior wasn't quite what was intended.
My main concern with this test (and its phrasing) is that it seems to indicate that supplying these two parameters is intended to be incompatible, which contradicts the previously-documented intention that these parameters should be compatible. Assuming we find an acceptable implementation, I'll tweak the phrasing and maybe add a docstring to the test to explain how this test is describing behavior and not prescribing behavior.
setuptools/command/sdist.py
Outdated
if not self.distribution.include_package_data: | ||
|
||
if self.distribution.include_package_data: | ||
self.warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like this warning may be issued unconditionally, even if package_data was not indicated. That's going to cause a lot of spurious warnings for use-cases that don't use package_data but use include_package_data. I'll test to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. Making this change to the tests, the tests still pass:
diff --git a/setuptools/tests/test_manifest.py b/setuptools/tests/test_manifest.py
index 25e65ce5..a1d90aad 100644
--- a/setuptools/tests/test_manifest.py
+++ b/setuptools/tests/test_manifest.py
@@ -611,7 +611,6 @@ class TestFileListTest(TempDirTestCase):
self.make_files([ml('app/__init__.py'), ml('app/e.py')])
setup_attrs = {
- "package_data": {"some": ["data"]},
"include_package_data": True,
'packages': ['app'],
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was really intending to merge this change tonight, but unfortunately, it's not suitable as drafted, as it adds the warning even if package_data
is not specified.
c08d07b
to
edaf1b5
Compare
I've pushed 3910bbb to setuptools master... and rebased the above commits on that as the pr-1887-rebase branch. I suggest force-pushing those commits to your branch. |
Thanks for the serious review, and sorry for introducing the mistake. I don't have time looking at this in the coming weeks, so feel free to take it from here on my branch. |
Disallow the combination of include_package_data=True and explicit package_data
As per @pganssle 's suggestion number 2 on the issue.
Closes #1461
Pull Request Checklist