summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2023-01-03 13:12:46 +0000
committerStephen Finucane <sfinucan@redhat.com>2023-01-06 13:22:51 +0000
commit61c6a4bcb305cd14cd913fc88ade4b1c0d21eb8c (patch)
treefacadabc3adc2f5426a9eddf578e9d0af11cdf85
parent491ce1ab095b122b442de1ce662ebc2e29d27de3 (diff)
downloadpbr-61c6a4bcb305cd14cd913fc88ade4b1c0d21eb8c.tar.gz
Tie recursion calls to Dist object, not module
In change I1f2b4d34e587389f7e11b99d000e14477cf5091b, we attempted to resolve an issue whereby using PBR as a PEP-517 backend could result in recursion. We did this by setting 'dist.pbr' to 'None' but later discovered this introduced a regression that prevented us from writing the 'pbr.json' file into generated sdists. The fix for the regression, change I407ae88ab8de4b61f94034b3d79a2ca7f7d79d16, stopped setting 'dist.pbr' to 'None' and instead set a global flag to indicate whether we had already been called or not. Unfortunately it seems this fix is also insufficent. As discussed in tox#2712 [1], tox v4 has implemented its own implementation of PEP-517 - 'pyproject-api' [2] - and unlike 'build' this implementation optionally allows re-use of the backend process for multiple PEP-517 commands. tox's 'Pep517VirtualEnvFrontend' does just this. This means if we run multiple commands that require generation of a 'Distribution' object - say, 'prepare_metadata_for_build_wheel' followed by 'build_sdist' - anything but the first step will not result in proper population of said 'Distribution' objects. The solution to this issue is simple: per $subject, instead of setting our recursion-detection canary at the module level, set it at the Distribution level. [1] https://github.com/tox-dev/tox/issues/2712 [2] github.com/tox-dev/pyproject-api/ Change-Id: I67909d732a74550fbcd7c06a9e2f4ac88c063444 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
-rw-r--r--pbr/core.py10
1 files changed, 2 insertions, 8 deletions
diff --git a/pbr/core.py b/pbr/core.py
index a801737..fb592f8 100644
--- a/pbr/core.py
+++ b/pbr/core.py
@@ -61,11 +61,6 @@ 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.
@@ -91,10 +86,9 @@ def pbr(dist, attr, value):
# 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:
+ if hasattr(dist, '_pbr_initialized'):
return
- in_use = True
+ dist._pbr_initialized = True
if not value:
return