I am currently working on a research project (my bachelors thesis) for handwriting recognition. I wrote a lot of Python scripts so far and I would like to make them useful for other people. So I created a project on PyPI: https://pypi.python.org/pypi/hwrt/
Currently, only 2 executable scripts are there: backup.py
and view.py
. When it is installed via pip
I can call them, so that works:
$ backup.py --help
usage: backup.py [-h] [-d FOLDER] [-s] [-o]
Download raw data from online server and back it up (e.g. on dropbox)
handwriting_datasets.pickle.
optional arguments:
-h, --help show this help message and exit
-d FOLDER, --destination FOLDER
where do write the handwriting_dataset.pickle
(default: /home/moose/Downloads/write-math/archive
/raw-datasets)
-s, --small should only a small dataset (with all capital letters)
be created? (default: False)
-o, --onlydropbox don't download new files; only upload to dropbox
(default: False)
$ view.py --help
usage: view.py [-h] [-i ID] [--mysql MYSQL] [-m FOLDER]
Display a raw_data_id.
optional arguments:
-h, --help show this help message and exit
-i ID, --id ID which RAW_DATA_ID do you want?
--mysql MYSQL which mysql configuration should be used?
-m FOLDER, --model FOLDER
where is the model folder (with a info.yml)?
I got this via scripts
in setup.py
:
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
config = {
'name': 'hwrt',
'version': '0.1.19',
'author': 'Martin Thoma',
'author_email': 'info@martin-thoma.de',
'packages': ['hwrt'],
'scripts': ['bin/backup.py', 'bin/view.py'],
'url': 'https://github.com/MartinThoma/hwrt',
'license': 'MIT',
'description': 'Handwriting Recognition Tools',
'long_description': """A tookit for handwriting recognition. It was
developed as part of the bachelors thesis of Martin Thoma.""",
'install_requires': [
"argparse",
"theano",
"nose",
],
'keywords': ['HWRT', 'recognition', 'handwriting', 'on-line'],
'download_url': 'https://github.com/MartinThoma/hwrt',
}
setup(**config)
However, I would rather want them to be called like this:
$ hwrt backup --help
(just what came before for 'backup.py --help')
$ hwrt view --help
(just what came before for 'view.py --help')
$ hwrt --help
(a list of all sub-commands)
I know that this can be done with sub-commands and argparse. However, this would mean I had to create a new script where I bundle all commands for argparse. But I also would like the scripts to work independently. It just feels more logically for me to adjust command line parameters that are only important for backup.py
only in backup.py
and not in another file.
Is there a way to adjust my scripts so that they "discover" the scripts in the bin folder and add all of them as sub-commands?