-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Description
Hi,
We use such setup:
from setuptools import setup, find_packages
setup(
name='ap',
version='1.0',
packages=find_packages(),
include_package_data=True,
install_requires=[
'Click'
],
entry_points='''
[console_scripts]
ap=main:cli
'''
)
with the dynamic sub-commands located in the [root]/scripts/commands and dynamic loading in the main.py:
COMMANDS_FOLDER = os.path.join(os.path.dirname(__file__), 'scripts', 'commands')
class ApCli(click.MultiCommand):
def list_commands(self, ctx):
"""Provides names of all commands by searching the commands folder"""
rv = []
for filename in os.listdir(COMMANDS_FOLDER):
# find py files, ignore the ones that start with __ (f.e. __init__.py)
if filename.endswith('.py') and not filename.startswith('__'):
rv.append(filename[:-3])
rv.sort()
return rv
def get_command(self, ctx, name):
"""Returns compiled command for given name, expects that command has a function same as its name"""
ns = {}
fn = os.path.join(COMMANDS_FOLDER, name + '.py')
if os.path.isfile(fn):
with open(fn) as f:
code = compile(f.read(), fn, 'exec')
eval(code, ns, ns)
else:
return
if ns.get(name) is not None:
return ns[name]
@click.command(cls=ApCli)
@click.option('-v', '--verbose', is_flag=True, default=False, help='Enables verbose mode.')
@click.version_option()
@ap.pass_context
def cli(context, verbose):
"""Main entry point for the CLI"""
context.logger.isVerbose = verbose
However manual get generated only for our main entry point and for nothing else.. Any idea how can we fix this?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels