Available for hire

Could not find any match !

Python -

Shell script to initialize a python project


!/bin/bash

#
# Change into the project directory and run this script!
# Allows to provide an alternative project name as the first argument. 
# Otherwise the folder name will be used.
#
# DISCLAIMER: USE THIS AT YOUR OWN RISK
# 

export PROJECTDIR=$(readlink -f $(dirname .))
export PROJECTNAME=$(basename $(readlink -f .))
export USERNAME=$(git config user.name)
export EMAIL=$(git config user.email)
export VERSION="0.1.0"
export LICENSE="MIT"

if [ -n "$1" ]; then
    export PROJECTNAME="$1"
fi 


mkdir -p "${PROJECTDIR}/src/main" "${PROJECTDIR}/src/test" "${PROJECTDIR}/bin"

# Generate setup.py
export SETUP_PY="${PROJECTDIR}/setup.py"
echo "from setuptools import setup, find_packages" >"${SETUP_PY}"
echo "" >>"${SETUP_PY}"
echo "setup(" >>"${SETUP_PY}"
echo "    name='${PROJECTNAME}'," >>"${SETUP_PY}"
echo "    version='${VERSION}'," >>"${SETUP_PY}"
echo "    url=''," >>"${SETUP_PY}"
echo "    license='${LICENSE}'," >>"${SETUP_PY}"
echo "    author='${USERNAME}'," >>"${SETUP_PY}"
echo "    author_email='${EMAIL}'," >>"${SETUP_PY}"
echo "    description=''," >>"${SETUP_PY}"
echo "    package_dir={\"\": \"src/main\"}," >>"${SETUP_PY}"
echo "    packages=find_packages(\"src/main\")," >>"${SETUP_PY}"
echo ")" >>"${SETUP_PY}"

# Initialize virtualenv
virtualenv "${PROJECTDIR}/venv"
source "${PROJECTDIR}/venv/bin/activate"

pip3 install setuptools pytest pex
pip3 freeze >"${PROJECTDIR}/requirements.txt"


# Create the pex build script
export SCRIPT="${PROJECTDIR}/bin/pexbuild.sh"

echo "#!/bin/bash" >"${SCRIPT}"
echo "export PROJECTDIR=\$(readlink -f \$(dirname .))" >>"${SCRIPT}"
echo "source \"\${PROJECTDIR}/venv/bin/activate\"" >>"${SCRIPT}"
echo "pex \"\${PROJECTDIR}\" -D src/main -r \"\${PROJECTDIR}/requirements.txt\" -e \${1} -o \"\${PROJECTDIR}/app.pex\"" >>"${SCRIPT}"
chmod +x "${SCRIPT}"