Skip to content

Instantly share code, notes, and snippets.

@chrisengelsma
Created April 5, 2017 16:03
Show Gist options
  • Save chrisengelsma/b03afb3ff4c5de1f6c9b1528ab79980a to your computer and use it in GitHub Desktop.
Save chrisengelsma/b03afb3ff4c5de1f6c9b1528ab79980a to your computer and use it in GitHub Desktop.
Python module skeleton generator
#!/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