-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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, orimportable.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:mainwould create a commandmycmdlaunching a script like this:import sys from mymod import main sys.exit(main())
Because of the way the import-from statement works:
The
fromform uses a slightly more complex process:
- find the module specified in the from clause, loading and initializing it if necessary;
- for each of the identifiers specified in the import clauses:
- check if the imported module has an attribute by that name
- 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.