Skip to content

Instantly share code, notes, and snippets.

@boseji
Last active January 9, 2020 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boseji/d8aa685a0907286a6380970dd26d7317 to your computer and use it in GitHub Desktop.
Save boseji/d8aa685a0907286a6380970dd26d7317 to your computer and use it in GitHub Desktop.
Python Project Initialize script inspired by "Learn Python the Hard Way by Zed A Shaw"
#!/bin/sh
###########################################
### Workspace Startup File
###
### @brief Creates the Required files and configuration needed
### to begin working with Python projects
### This work has been inspired by:
### Learn Python the Hard Way by Zed A Shaw
### - Great book on python and other topics
### - Visit: https://learnpythonthehardway.org/
###
### @note This project setup depends on nose2 and coverage refer
### their respective documentation:
### - https://docs.nose2.io/en/latest/
### - https://coverage.readthedocs.io/
###
### @version 1.0 - First Revision with `nose2 and Coverage`
###
### @author Abhijit Bose <salearj@hotmail.com>
###
### @license : Released into Public Domain
### This program is part of the Python learning efforts
### by the Author.
###
###########################################
## Exit on Error
set -e
## Obtain all Parameters
export PROJECT=$1
export CWD=`pwd`
## Accept the Name of Project
if [ -z "$PROJECT" ];then
export PROJECT="NAME"
fi
## Begin Creation
echo
echo "----------------------------------------------------------"
echo " Creating $PROJECT in : $CWD"
echo
echo " ~ Inspired by 'Learn Python the Hard Way by Zed A. Shaw"
echo "----------------------------------------------------------"
echo
echo " - Creating directories: bin, $PROJECT, tests, docs"
mkdir -p bin $PROJECT tests docs
echo
echo " - Here is how the directory looks like:"
echo
ls -al
echo
echo " - Creating the required files"
echo " + Init Files: $PROJECT/__init__.py, tests/__init__.py"
touch $PROJECT/__init__.py
touch tests/__init__.py
echo " + Setup File: setup.py"
echo '#!/usr/bin/python
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
config = [
"description": "My Project",
"author": "My Name",
"url": "URL to get it at.",
"download_url": "Where to download it.",
"author_email": "My Email",
"version": "0.1",
"install_requires": ["nose2","coverage"],
"packages": ["$PROJECT"],
"scripts": [],
"name": "$PROJECT"
]
setup(**config)
' > setup.py
echo " + Basic Test Cases: tests/test_$PROJECT.py"
echo '#!/usr/bin/python
import unittest
class TestSet(unittest.TestCase):
def setUp(self):
print("Setup for Tests")
def tearDown(self):
print("Teardown for Tests")
def test_basic(self):
print(" Basic Test Case Ran!")
if __name__ == "__main__":
unittest.main()
' > tests/test_$PROJECT.py
echo " + GitIgnore File: .gitignore"
echo '# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Libre Office
.~lock.*.*
' > .gitignore
echo
echo " - Here is how the directory looks like:"
echo
ls -alR
echo
echo "----------------------------------------------------------"
echo " Done ! - good luck with your project ;-)"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment