Skip to content

Commit

Permalink
Merge branch 'finalize_distribution_options_various_data' into finali…
Browse files Browse the repository at this point in the history
…ze_distribution_options_improvements
  • Loading branch information
KOLANICH committed Mar 19, 2020
2 parents 1c49e87 + 682b002 commit 033d886
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
4 changes: 4 additions & 0 deletions changelog.d/2034.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Now ''setuptools.finalize_distribution_options'' hook allows the implementers to ast setuptools to provide them various information by adding a parameter with a certain name into the function signature.
Old behavior is also supported.

For the list of args names see ''DistributionoptionsFinalizationRemap'' in ''dist.py''.
38 changes: 28 additions & 10 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,7 @@ def fetch_build_eggs(self, requires):
pkg_resources.working_set.add(dist, replace=True)
return resolved_dists

shouldCallFinHookCheckers = {
'dist': lambda dist, fdohac, ep: hasattr(dist, ep.name),
'toml': lambda dist, fdohac, ep: bool(fdohac.pyProjectToml) and ep.name in fdohac.pyProjectToml,
}
optsFinalizationRemap = None # set later

def isFinHookFailureFatal(self, ep, fdohac):
"""Returns either a bool, or None. The semantics is following
Expand Down Expand Up @@ -830,6 +827,24 @@ def by_order(hook):
return default_order_value

fdohac = FinalizeDistributionOptionsHookArgsCache()

def constructArgsForAFunc(f, ep, fdohac):
if sys.version_info.major >= 3:
p = inspect.getfullargspec(f).args
else:
p = inspect.getargspec(f)[0]

if len(p) == 1:
firstParam = p[0]
if firstParam not in self.optsFinalizationRemap:
return [self]

args = []
for parN in p:
a = self.optsFinalizationRemap[parN](self, ep, fdohac, parN)
args.append(a)
return args

eps = pkg_resources.iter_entry_points(hook_key)

for ep in sorted(eps, key=by_order):
Expand All @@ -847,12 +862,15 @@ def by_order(hook):
continue

try:
f(self)
except BaseException as ex:
if not isFatal:
warnings.warn("Error when executing entry point:" + str(ex))
continue
raise
args = constructArgsForAFunc(f, ep, fdohac)
except Exception as ex:
warnings.warn(
repr(ep) + " is incompatible to the current"
" version of setuptools: " + str(ex)
)
continue

f(*args)

@staticmethod
def _finalize_setup_keywords(dist):
Expand Down

0 comments on commit 033d886

Please sign in to comment.