Skip to content

Commit

Permalink
Merge pull request #2817 from pganssle/missing_metadata
Browse files Browse the repository at this point in the history
Implement metadata validation (not used)
  • Loading branch information
jaraco authored Jan 29, 2022
2 parents 4156c0d + 9ce6e03 commit 62d0e14
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 9 deletions.
13 changes: 13 additions & 0 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,19 @@ def __init__(self, attrs=None):
)
self._finalize_requires()

def _validate_metadata(self):
required = {"name"}
provided = {
key
for key in vars(self.metadata)
if getattr(self.metadata, key, None) is not None
}
missing = required - provided

if missing:
msg = f"Required package metadata is missing: {missing}"
raise DistutilsSetupError(msg)

def _set_metadata_defaults(self, attrs):
"""
Fill-in missing metadata fields not supported by distutils.
Expand Down
3 changes: 1 addition & 2 deletions setuptools/tests/test_bdist_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SETUP_PY = """\
from setuptools import setup
setup(name='foo', py_modules=['hi'])
setup(py_modules=['hi'])
"""


Expand Down Expand Up @@ -52,7 +52,6 @@ def test_exclude_source_files(self, setup_context, user_override):
dist = Distribution(dict(
script_name='setup.py',
script_args=['bdist_egg', '--exclude-source-files'],
name='foo',
py_modules=['hi'],
))
with contexts.quiet():
Expand Down
3 changes: 0 additions & 3 deletions setuptools/tests/test_build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_directories_in_package_data_glob(tmpdir_cwd):
script_name='setup.py',
script_args=['build_py'],
packages=[''],
name='foo',
package_data={'': ['path/*']},
))
os.makedirs('path/subpath')
Expand All @@ -40,7 +39,6 @@ def test_read_only(tmpdir_cwd):
script_args=['build_py'],
packages=['pkg'],
package_data={'pkg': ['data.dat']},
name='pkg',
))
os.makedirs('pkg')
open('pkg/__init__.py', 'w').close()
Expand Down Expand Up @@ -70,7 +68,6 @@ def test_executable_data(tmpdir_cwd):
script_args=['build_py'],
packages=['pkg'],
package_data={'pkg': ['run-me']},
name='pkg',
))
os.makedirs('pkg')
open('pkg/__init__.py', 'w').close()
Expand Down
5 changes: 5 additions & 0 deletions setuptools/tests/test_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,8 @@ def test_check_specifier():
)
def test_rfc822_unescape(content, result):
assert (result or content) == rfc822_unescape(rfc822_escape(content))


def test_metadata_name():
with pytest.raises(DistutilsSetupError, match='missing.*name'):
Distribution()._validate_metadata()
2 changes: 1 addition & 1 deletion setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def as_requirement(self):
SETUP_PY = DALS("""
from setuptools import setup
setup(name='foo')
setup()
""")


Expand Down
1 change: 0 additions & 1 deletion setuptools/tests/test_sphinx_upload_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def sphinx_doc_sample_project(tmpdir_cwd):
class TestSphinxUploadDocs:
def test_sphinx_doc(self):
params = dict(
name='foo',
packages=['test'],
)
dist = Distribution(params)
Expand Down
1 change: 0 additions & 1 deletion setuptools/tests/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@pytest.mark.usefixtures('tmpdir_cwd')
def test_tests_are_run_once(capfd):
params = dict(
name='foo',
packages=['dummy'],
)
files = {
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_upload_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def sample_project(tmpdir_cwd):
'setup.py': DALS("""
from setuptools import setup
setup(name='foo')
setup()
"""),
'build': {
'index.html': 'Hello world.',
Expand Down

0 comments on commit 62d0e14

Please sign in to comment.