pypa / pypa/packaging.python.org

Clarify entry point's object reference specification

Open
#1,993 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
1.7k
Avg merge
3d 12h
Merged PRs (30d)
4

Description

Issue Description

In the entry point specification, section data model,

The object reference points to a Python object. It is either in the form importable.module, or importable.module:object.attr. Each of the parts delimited by dots and the colon is a valid Python identifier. It is intended to be looked up like this:

import importlib
modname, qualname_separator, qualname = object_ref.partition(':')
obj = importlib.import_module(modname)
if qualname_separator:
    for attr in qualname.split('.'):
        obj = getattr(obj, attr)

First, I propose to disallow the former form importable.module as its invocation is never mentioned.

Second and more importantly, I want to explicitly enforces object on the right of the colon (:) to be an attribute of importable.module on the left. To add the confusion , later in the section use for scripts:

the entry point mycmd = mymod:main would create a command mycmd launching a script like this:

import sys
from mymod import main
sys.exit(main())

Because of the way the import-from statement works:

The from form uses a slightly more complex process:

  1. find the module specified in the from clause, loading and initializing it if necessary;
  2. for each of the identifiers specified in the import clauses:
    1. check if the imported module has an attribute by that name
    2. if not, attempt to import a submodule with that name and then check the imported module again for that attribute
      [...]

package authors may wrongly assume the first identifier object on the right of the colon to possibly be a module as well (exhibit A). While both pkg_resources's and the builtin importlib.metadata's EntryPoint.load would fail on such incorrect entry point, they aren't run on common build processes and the most popular installer pip generates working scripts in a format the same as in the mycmd = mymod:main example.

It would be nice if the specification is more explicit over what is and is not allowed instead of a reference implementation ([an object reference] is intended to be looked up like this). In Guix we got entry point script generation (hopefully) right on the third try and it shouldn't be like this for other projects.

Code of Conduct
  • I am aware that participants in this repository must follow the PSF Code of Conduct.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the entry point specification's data model and use for scripts sections, then compare their object-reference wording with the linked Python import semantics and EntryPoint behavior. Clarify which object-reference forms and lookup rules the specification permits, including the script example, and ensure the resulting text is consistent across both sections.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.