Created
April 5, 2017 16:03
-
-
Save chrisengelsma/b03afb3ff4c5de1f6c9b1528ab79980a to your computer and use it in GitHub Desktop.
Python module skeleton generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Description: Creates a new python module skeleton in your project. | |
# Note: will exit if the directory already exists to prevent overwriting. | |
# | |
# usage: pymod MODULE_NAME | |
# example: $ pymod foo | |
# result: foo/ | |
# |_ __init__.py | |
# |_ foo.py | |
# | |
# example: $ pymod /path/to/project/foo | |
# result: /path/to/project/foo/ | |
# |_ __init__.py | |
# |_ foo.py | |
# | |
# Author: Chris Engelsma | |
PYTHON_BIN='/usr/bin/env python' | |
ENCODING='utf-8' | |
MODULE=$(basename $1) | |
if [ -d $1 ]; then | |
echo "$1 already exists, exiting..." | |
exit 1 | |
else | |
mkdir $1 | |
cat <<EOT >> ${1}/__init__.py | |
#!${PYTHON_BIN} | |
# -*- coding: ${ENCODING} -*- | |
from .${MODULE} import * | |
EOT | |
cat <<EOT >> ${1}/${MODULE}.py | |
#!${PYTHON_BIN} | |
# -*- coding: ${ENCODING} -*- | |
EOT | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment