Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pyroma/projectdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import pathlib
import re
from importlib.metadata import metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth importing this under an alias, rather than having both metadata the import and metadata the variable in the same file?

Copy link
Author

Choose a reason for hiding this comment

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

Sure - or we can rename some of the variables to avoid the collision.

Copy link
Owner

Choose a reason for hiding this comment

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

I'm fine with calling the variable just "md", that's what we use for metadata at my work anyway. :-)


from setuptools.config.setupcfg import read_configuration
from distutils.errors import DistutilsFileError
Expand Down Expand Up @@ -47,6 +48,10 @@ def build_metadata(path, isolated=None):
# metadata from PyPI, we just couldn't get the additional build data.
return {"_wheel_build_failed": True}

return normalize_metadata(metadata)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm right, this would be a bug that exists in master, but... isn't metadata not set here? Because the assignment earlier in the function raised an exception?

Copy link
Author

Choose a reason for hiding this comment

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

If the call on L43 succeeds, then data metadata will be set on L51; if it fails, the return on L49 prevents L51 from being executed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, right, sorry, I was thinking backwards.



def normalize_metadata(metadata):
# As far as I can tell, we can't trust that the builders normalize the keys,
# so we do it here. Definitely most builders do not lower case them, which
# Core Metadata Specs recommend.
Expand All @@ -72,6 +77,11 @@ def build_metadata(path, isolated=None):
return data


def installed_metadata(name):
"""Retrieve the metadata for an package that is installed in the environment."""
return normalize_metadata(metadata(name))


def get_build_data(path, isolated=None):
metadata = build_metadata(path, isolated=isolated)
# Check if there is a pyproject_toml
Expand Down
34 changes: 34 additions & 0 deletions pyroma/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,40 @@ def test_complete(self):
del data["_path"] # This changes, so I just ignore it
self.assertEqual(data, COMPLETE)

def test_installed(self):
# pyroma must be installed in the test environment.
data = projectdata.installed_metadata("pyroma")

# Verify some key metadata
self.assertEqual(data["name"], "pyroma")
self.assertEqual(data["summary"], "Test your project's packaging friendliness")
self.assertEqual(data["classifier"], [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
])
self.assertEqual(data["keywords"], "pypi,quality,testing")
self.assertEqual(data["author"], "Lennart Regebro")
self.assertEqual(data["author-email"], "[email protected]")
self.assertEqual(data["home-page"], "https://github.com/regebro/pyroma")
self.assertEqual(data["license"], "MIT")
self.assertEqual(data["license-file"], "LICENSE.txt")
self.assertEqual(data["project-url"], "Source Code, https://github.com/regebro/pyroma")
self.assertEqual(data["provides-extra"], "test")
self.assertEqual(data["requires-python"], "3.9")


class DistroDataTest(unittest.TestCase):
maxDiff = None
Expand Down
Loading