Avoid recursive calls into SetupTools entrypoint

Add a check in pbr.core.pbr() to make sure it hasn't already run,
and return immediately if it has. This replaces the earlier attempt
at loop-busting by setting the entrypoint to None in the dist, in
order to support PEP 517 builds without setup_requires.

Also test that pbr.json is now included in the dist tree, in order
to avoid future regressions.

Change-Id: I407ae88ab8de4b61f94034b3d79a2ca7f7d79d16
This commit is contained in:
Jeremy Stanley 2022-02-04 18:36:27 +00:00
parent 397b6fcdf9
commit 949c47c979
2 changed files with 21 additions and 8 deletions

View File

@ -61,6 +61,11 @@ else:
integer_types = (int, long) # noqa
# We use this canary to detect whether the module has already been called,
# in order to avoid recursion
in_use = False
def pbr(dist, attr, value):
"""Implements the actual pbr setup() keyword.
@ -81,6 +86,16 @@ def pbr(dist, attr, value):
not work well with distributions that do use a `Distribution` subclass.
"""
# Distribution.finalize_options() is what calls this method. That means
# there is potential for recursion here. Recursion seems to be an issue
# particularly when using PEP517 build-system configs without
# setup_requires in setup.py. We can avoid the recursion by setting
# this canary so we don't repeat ourselves.
global in_use
if in_use:
return
in_use = True
if not value:
return
if isinstance(value, string_type):
@ -130,14 +145,6 @@ def pbr(dist, attr, value):
msg = 'Unknown distribution option: %s' % repr(key)
warnings.warn(msg)
# Distribution.finalize_options() is what calls this method. That means
# there is potential for recursion here. Recursion seems to be an issue
# particularly when using PEP517 build-system configs without
# setup_requires in setup.py. We can avoid the recursion by setting
# dist.pbr to a None value as the corresponding entrypoint (this function)
# will only be called on a non None value.
setattr(dist, "pbr", None)
# Re-finalize the underlying Distribution
try:
super(dist.__class__, dist).finalize_options()

View File

@ -381,6 +381,12 @@ class TestPackagingWheels(base.BaseTestCase):
wheel_file.extractall(self.extracted_wheel_dir)
wheel_file.close()
def test_metadata_directory_has_pbr_json(self):
# Build the path to the scripts directory
pbr_json = os.path.join(
self.extracted_wheel_dir, 'pbr_testpackage-0.0.dist-info/pbr.json')
self.assertTrue(os.path.exists(pbr_json))
def test_data_directory_has_wsgi_scripts(self):
# Build the path to the scripts directory
scripts_dir = os.path.join(