Entry Points in setup.py

两盒软妹~` 提交于 2019-12-11 01:38:58

问题


I am making a CLI in python using Click. This is my entry point script:

entry_points='''
    [console_scripts]
    noo=noo.noodle:downloader
''',

I have made a Package, I have added import noodle in the __init__.py file so that it could import the file noodle which contains the function downloader() - which needs to be executed by the entry_point script. But when I install the setup.py, I get an Error: ImportError: No module named noo.noodle when I run noodle --help in terminal?


回答1:


Directly from the documentation on click.pocoo.org:

yourscript.py:

import click

@click.command()
def cli():
    """Example script."""
    click.echo('Hello World!')

setup.py:

from setuptools import setup

setup(
    name='yourscript',
    version='0.1',
    py_modules=['yourscript'],
    install_requires=[
        'Click',
    ],
    entry_points='''
        [console_scripts]
        yourscript=yourscript:cli
    ''',
)

While if you have multiple commands in your CLI application, I usually create a click group like this:

init.py:

import click

@click.group()
@click.option('--debug/--no-debug', default=False, help='My test option.')
def cli(debug):
    """Add some initialisation code to log accordingly for debugging purposes or no"""
    pass  

@cli.command()
def configure():
    """Configure the application"""
    pass

And the setup.py file looks exactly the same as the one in the click documentation.



来源:https://stackoverflow.com/questions/23949425/entry-points-in-setup-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!