Skip to content

setuptools ignores order attribute of entrypoints inf finalize_distribution_options group #1993

Closed
@con-f-use

Description

@con-f-use

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions