Skip to content
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

Implement metadata validation (not used) #2817

Merged
merged 7 commits into from
Jan 29, 2022
Merged

Conversation

pganssle
Copy link
Member

@pganssle pganssle commented Oct 15, 2021

Summary of changes

Change to the Distribution class to require that some metadata exists before actually doing anything.

This is just a draft. It still needs test, presumably linting and formatting, and I'm not even confident that this is conceptually the right place for this logic, but I thought I'd throw this approach out there as an option for discussion.

Closes #2799, #2329

Pull Request Checklist

This needs tests and probably formatting stuff.
@webknjaz
Copy link
Member

This is just a draft.

Mind converting it to a draft, then? So that it's visually distinctive in the PR list..

Comment on lines 477 to 485
if missing:
if len(missing) == 1:
message = "%s attribute" % missing[0]
else:
message = "%s and %s attributes" % (", ".join(missing[:-1]),
missing[-1])
raise DistutilsSetupError(
"Required package metadata is missing: please supply the %s." % message
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use a guard expression to dedent this.

Suggested change
if missing:
if len(missing) == 1:
message = "%s attribute" % missing[0]
else:
message = "%s and %s attributes" % (", ".join(missing[:-1]),
missing[-1])
raise DistutilsSetupError(
"Required package metadata is missing: please supply the %s." % message
)
if not missing:
return
if len(missing) == 1:
message = "%s attribute" % missing[0]
else:
message = "%s and %s attributes" % (", ".join(missing[:-1]),
missing[-1])
raise DistutilsSetupError(
"Required package metadata is missing: please supply the %s." % message
)

@webknjaz
Copy link
Member

I'm not even confident that this is conceptually the right place for this logic, but I thought I'd throw this approach out there as an option for discussion.

Validating the user input early sounds like a good idea. The implementation seems a bit overengineered, though.

Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some ideas I'll add to the issue.

@@ -17,6 +17,7 @@ def test_bdist_rpm_warning(distutils_cmd):
script_name='setup.py',
script_args=['bdist_rpm'],
name='foo',
version='1.0',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that without this change, the tests still pass. I suspect you originally intended to require both name and version in _validate_metadata.

This additional code (the need for a version='1.0' in every test, even when irrelevant to the test) feels a bit like noise.

@jaraco
Copy link
Member

jaraco commented Jan 29, 2022

I spent some more time looking at this today with the expectation that I'd merge it without the version requirement, but as I looked into it more, I'm far from confident that overriding run_commands is the right hook point. I suspect it should happen late in Distribution.finalize_options or perhaps explicitly between construction and running the commands, something like:

diff --git a/setuptools/_distutils/core.py b/setuptools/_distutils/core.py
index d603d4a45..5ab4bbddf 100644
--- a/setuptools/_distutils/core.py
+++ b/setuptools/_distutils/core.py
@@ -142,6 +142,8 @@ def setup (**attrs):
     if _setup_stop_after == "commandline":
         return dist
 
+    getattr(dist, '_validate_metadata', lambda: None)()
+
     # And finally, run all the commands found on the command line.
     if ok:
         try:

But I'm not even sure that's early enough. In theory, additional commands could alter the metadata (e.g. setup.py name_from_folder egg_info install). Of course, such a usage is deprecated, but that doesn't mean it isn't a supported configuration now, and it would be invalidated be the proposed change.

I'd like to avoid adding more interactions between distutils and Setuptools classes (Distribution in this case).

So for now, I'd like to keep the _validate_metadata method, and defer the method of integration.

@jaraco jaraco changed the title WIP: Reject packages without required metadata Implement metadata validation (not used) Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] setuptools.build_meta proceeds with no setup.py or setup.cfg
3 participants