Shell script to create a Python project
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 - | |
#=============================================================================== | |
# | |
# FILE: createPythonProject.sh | |
# | |
# USAGE: ./createPythonProject.sh | |
# | |
# DESCRIPTION: Create a new Python project | |
# | |
# VERSION: 1.3 | |
# REQUIREMENTS: --- | |
# BUGS: --- | |
# NOTES: --- | |
# AUTHOR: @niftycode | |
# ORGANIZATION: | |
# CREATED: December 10th, 2021 | |
# REVISION: March 18th, 2023 | |
#=============================================================================== | |
set -o nounset # Treat unset variables as an error | |
echo "Enter a project name:" | |
read name | |
mkdir $name | |
cd $name | |
# Create the subfolders 'docs' and 'tests' | |
mkdir docs | |
mkdir tests | |
# Create init file in the 'tests' folder | |
cd tests | |
touch __init__.py | |
cd .. | |
cat > setup.py << EOF | |
import setuptools | |
setuptools.setup() | |
EOF | |
cat > setup.cfg << EOF | |
[metadata] | |
name = | |
version = | |
author = | |
author_email = | |
url = | |
description = | |
long_description = file: README.md | |
long_description_content_type = text/markdown | |
license = MIT | |
license_file = LICENSE | |
requires_python = >=3.9 | |
classifiers = | |
License :: OSI Approved :: MIT License | |
Operating System :: OS Independent | |
Programming Language :: Python :: 3 | |
Programming Language :: Python :: 3.8 | |
Programming Language :: Python :: 3.9 | |
Programming Language :: Python :: 3.10 | |
Programming Language :: Python :: 3.11 | |
Programming Language :: Python :: Implementation :: CPython | |
EOF | |
touch requirements.txt | |
touch requirements-dev.txt | |
touch Changelog.md | |
touch CONTRIBUTING.md | |
cat > README.md << EOF | |
# $name | |
EOF | |
# Create subfolder with then name of the project and | |
# create init and main file | |
mkdir $name | |
cd $name | |
touch __init__.py | |
cat > main.py << EOF | |
#!/usr/bin/env python3 | |
""" | |
Description goes here... | |
Version: 1.0 | |
Python 3.9+ | |
Date created: June 5th, 2023 | |
Date modified: - | |
""" | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
logger = logging.getLogger() | |
def main(): | |
pass | |
if __name__ == '__main__': | |
main() | |
EOF | |
echo | |
read -p "Do you need a pytest.ini file? (Y/n)" pytest | |
pytest=${pytest:-Y} | |
if [ $pytest = "Y" ] | |
then | |
cd .. | |
touch pytest.ini | |
echo "[+] Created pytest.ini file!" | |
else | |
echo "[-] pytest.ini will not be created" | |
fi | |
if test -f "pytest.ini"; then | |
echo "[pytest]" >> pytest.ini | |
echo "norecursedirs = .* src *.egg dist build" >> pytest.ini | |
echo "addopts = -rsxX -l --tb=short --strict-markers" >> pytest.ini | |
fi | |
# Create virtual environment | |
echo | |
read -p "Do you need a virtual environment? (y/N)" venv | |
venv=${venv:-N} | |
if [ $venv = "y" ] | |
then | |
echo "[+] Creating a virtual environment..." | |
python3 -m venv .venv | |
echo | |
echo "Done!" | |
echo "Start the virtual environment using 'source .venv/bin/activate'." | |
else | |
echo "[-] A virtual environment will not be created!" | |
fi | |
echo | |
echo "-----------------------" | |
echo "All done! Exit program." | |
echo "-----------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment