I have a Python package called tdsm
that I have converted for the first time to a command-line interface using Armin Ronacher's Click package. I have set my scripts up within this directory structure:
Also I have created a setup.py
file:
from setuptools import setup
setup(
name='tdsm',
version='0.1',
py_modules=['tdsm.scripts.data_manager',
'tdsm.scripts.visuals'],
include_package_data=True,
install_requires=[
'click',
'numpy',
'scipy',
'pandas',
'wand',
'matplotlib',
],
entry_points='''
[console_scripts]
tdsm=tdsm.main:cli
''',
)
After a pip install --editable .
, I get it working, up to a point:
# tdsm --help
Now emits:
Usage: tdsm-script.py [OPTIONS] COMMAND [ARGS]...
TDSM standard workflow -- typical sequence of commands:
`init <path>` or `open <path>`: to set up the project or to open
a new session on an existing project.
`plot`: framework for setting up plots, display layers, and styling.
Options:
--help Show this message and exit.
Commands:
init Set up a project from scratch.
plot Initialize a plotting session.
Note the usage statement says Usage: tdsm-script.py [OPTIONS] COMMAND [ARGS]... and not Usage: tdsm [OPTIONS] COMMAND [ARGS]... as I believe it should. Since I am expecting this to be used by non-programmers, I don't want users delving through the system looking for a non-existent file...
Poring through the docs I can see how to change every aspect of the help text but not this initial reference to tdsm-script.py
. Any pointers on what I am doing wrong?
The issue was resolved in the GitHub bug discussion thread by Markus Unterwaditzer. I reproduce it here for the record.
One just calls the command (or group, in my case) with an explicit prog_name
argument, thus:
import click
@click.group()
def cli():
pass
@cli.command(short_help='Set up a project from scratch.')
def init():
pass
@cli.command(short_help='Initialise a plotting session.')
def plot():
pass
cli(prog_name='tdsm') # Call with explicit `prog_name`
On installing the package, the right Usage is reported:
# tdsm --help
Usage: tdsm [OPTIONS] COMMAND [ARGS]...
You're not the only one with this problem. Judging from your screenshot it looks like you're on Windows, and it's an open bug with Click.
The problem is that Click appears to be autodetecting the program's name from argv[0]
. See the code in core.py that does this.
The bug report link above suggests some hackish ways of getting around this, including monkey-patching. Unfortunately the last comment on the bug is from July 28 -- perhaps mention on that thread that you're also having this issue. Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With