Python argparse helper module
Project description
arghelper
arghelper is a Python 3.8+ module providing functions to help with argparse.
Requirements
argparse
module from the Python Standard Librarysys
module from the Python Standard Libraryos
module from the Python Standard Library
Usage
arghelper
provides functions to determine if a file or directory
exists:
extant_file
extant_dir
These can be used as follows:
if __name__ == "__main__":
# Process the arguments
import argparse
import arghelper
parser = argparse.ArgumentParser(
description='Process the TAFFmat CET files')
parser.add_argument(
'config_file',
help='CSV configuration file.',
metavar='FILE', type=arghelper.extant_file)
parser.add_argument(
'input_dir',
help='Directory containing input files.',
metvar='DIR', type=arghelper.extant_dir)
args = parser.parse_args()
A common pattern, for me at least, is to have three positional arguments consisting of:
config_file
--- A configuration fileinput_dir
--- A directory containing input files to be readoutput_dir
--- A directory where the output files should be saved
This pattern has been abstracted to a Facade function called
parse_config_input_output
, which can be used as follows:
if __name__ == "__main__":
# Process the arguments
import arghelper
args = arghelper.parse_config_input_output(sys.argv)
Another common pattern is to just parse the name of a config file:
if __name__ == "__main__":
# Process the arguments
import arghelper
args = arghelper.parse_config(sys.argv)
Contributing
Contributions are welcome! To contribute please:
- Fork the repository
- Create a feature branch
- Add code and tests
- Pass lint and tests
- Submit a pull request
Development Setup
Development Setup Using pyenv
Use the following commands to create a Python 3.9.9 virtualenv using pyenv
and pyenv-virtualenv, install the requirements in the virtualenv named
arghelper
, and list the available [Invoke][] tasks.
$ pyenv virtualenv 3.11 arghelper
$ pyenv activate arghelper
$ pip install --upgrade pip
$ pip install -r requirements.txt
$ inv -l
License
arghelper is released under the MIT license. Please see the LICENSE.txt file for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file arghelper-0.5.2.tar.gz
.
File metadata
- Download URL: arghelper-0.5.2.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b92fa6e13b5df275c45971baf521fb15da4608b4428483c281b3f60e1481cda2 |
|
MD5 | 08a75b8a7bc2f2b466df850406b75334 |
|
BLAKE2b-256 | 942845c312787a09f50fb9123c6a53b5dc445a810da181560fdd3cd8593e7fc9 |
File details
Details for the file arghelper-0.5.2-py3-none-any.whl
.
File metadata
- Download URL: arghelper-0.5.2-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff36b2964fef007d0345b3251ebff234ed0c438ef8a0a8b59343b037dd692db2 |
|
MD5 | ba8661355ca71a7f133d11da1c83ad8e |
|
BLAKE2b-256 | 4761594d797130ed42d50c87a2e4cd2e0a540580fc974aa23fc1c5b4baa12dd1 |
File details
Details for the file arghelper-0.5.2-py2.py3-none-any.whl
.
File metadata
- Download URL: arghelper-0.5.2-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1cc209d7c6bdb0012576153a0391485f05fa6e7c95fcdf4a6bc3cd88c3c3957 |
|
MD5 | 1e0e643e94290a4e38c922cc12c59c32 |
|
BLAKE2b-256 | 1df896fb3204a4f28ef6194d9344793e4ed55229dc5086a06a3793f9f40eb105 |