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 07f588f + 682b002 commit 59c68c2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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''.
31 changes: 30 additions & 1 deletion setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ def fetch_build_eggs(self, requires):
pkg_resources.working_set.add(dist, replace=True)
return resolved_dists

optsFinalizationRemap = None # set later
shouldCallFinHookCheckers = {
'dist': lambda dist, fdohac, ep: hasattr(dist, ep.name),
'toml': lambda dist, fdohac, ep: bool(fdohac.pyProjectToml) and ep.name in fdohac.pyProjectToml,
Expand Down Expand Up @@ -827,6 +828,23 @@ def by_order(hook):

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 @@ -844,7 +862,18 @@ def by_order(hook):
continue

try:
f(self)
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)

try:
f(*args)
except BaseException as ex:
if not isFatal:
warnings.warn("Error when executing entry point:" + str(ex))
Expand Down

0 comments on commit 59c68c2

Please sign in to comment.