Skip to content

setuptools ignores order attribute of entrypoints inf finalize_distribution_options group #1993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
con-f-use opened this issue Feb 14, 2020 · 0 comments · Fixed by #1994
Closed

Comments

@con-f-use
Copy link
Contributor

Issue

I tried this entry point definition in my setup.py

# ./setup.py
[setuptools.finalize_distribution_options]
testfin = mypackage.integration:finalize

where finalize is a function with an order attribute defined, essentially like this:

# ./mypackage/integration.py
def finalize(dist):
  # do something with dist
finalize.order = 99

The order stays at the default of 0.

Cause

The relevant code in dist.py says:

def finalize_options(self):
    hook_key = 'setuptools.finalize_distribution_options'

    def by_order(hook):
        return getattr(hook, 'order', 0)
    eps = pkg_resources.iter_entry_points(hook_key)
    for ep in sorted(eps, key=by_order):
        ep.load()(self)

So, by_order() looks at the entry point object for the order attribute instead of the actual underlying object.

Mitigation

The following change would fix the problem, but is not elegant because load() would end up being called twice.

def by_order(hook):
    return getattr(hook.load(), 'order', 0)

I will make a PR today to try and fix that in a better way.


Note that @jaraco random shuffle rational from #1877 is still valid, as they did not explicitly use the order attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant