2
0
Fork 0

Must use "safe" top-level name for subcommand entry points

This commit is contained in:
Lance Edgar 2023-11-21 14:16:36 -06:00
parent ea9a9ade57
commit 4ff83162e1

View file

@ -161,16 +161,16 @@ class Command:
self.stdout = stdout or sys.stdout self.stdout = stdout or sys.stdout
self.stderr = stderr or sys.stderr self.stderr = stderr or sys.stderr
# nb. default entry point is like 'wutta-poser.subcommands' # nb. default entry point is like 'wutta_poser.subcommands'
self.subcommands = subcommands or load_entry_points(f'{self.name}.subcommands') safe_name = self.name.replace('-', '_')
self.subcommands = subcommands or load_entry_points(f'{safe_name}.subcommands')
if not self.subcommands: if not self.subcommands:
# nb. legacy entry point is like 'wutta_poser.commands' # nb. legacy entry point is like 'wutta_poser.commands'
safe_name = self.name.replace('-', '_')
self.subcommands = load_entry_points(f'{safe_name}.commands') self.subcommands = load_entry_points(f'{safe_name}.commands')
if self.subcommands: if self.subcommands:
msg = (f"entry point group '{safe_name}.commands' uses deprecated name; " msg = (f"entry point group '{safe_name}.commands' uses deprecated name; "
f"please define '{self.name}.subcommands' instead") f"please define '{safe_name}.subcommands' instead")
warnings.warn(msg, DeprecationWarning, stacklevel=2) warnings.warn(msg, DeprecationWarning, stacklevel=2)
log.warning(msg) log.warning(msg)
@ -337,14 +337,16 @@ class Subcommand:
way of another entry point in your ``setup.cfg`` file. way of another entry point in your ``setup.cfg`` file.
As with top-level commands, you can "alias" the same subcommand so As with top-level commands, you can "alias" the same subcommand so
it appears under multiple top-level commands: it appears under multiple top-level commands. Note that if the
top-level command name contains a hyphen, that must be replaced
with underscore for sake of the subcommand entry point:
.. code-block:: ini .. code-block:: ini
[options.entry_points] [options.entry_points]
poser.subcommands = poser.subcommands =
hello = poser.commands:Hello hello = poser.commands:Hello
wutta-poser.subcommands = wutta_poser.subcommands =
hello = poser.commands:Hello hello = poser.commands:Hello
Next time your (``poser``) package is installed, the subcommand Next time your (``poser``) package is installed, the subcommand