Skip to content

Instantly share code, notes, and snippets.

@cdriehuys
Last active November 6, 2018 01:03
Show Gist options
  • Select an option

  • Save cdriehuys/70870f18e3aca8ebb562ca0345494440 to your computer and use it in GitHub Desktop.

Select an option

Save cdriehuys/70870f18e3aca8ebb562ca0345494440 to your computer and use it in GitHub Desktop.
A script to make creating python projects easier.
#! /bin/bash
ENV_NAME='env'
PYTHON_NAME='python3'
project_name=$1
function configure_sublime() {
env_dir=$(readlink -f $project_name/$ENV_NAME)
python_bin="$env_dir/bin/python"
site_packages=`"$python_bin" -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())"`
cat > "$project_name/$project_name.sublime-project" <<EOF
{
"codeintel_settings": {
"codeintel_language_settings": {
"Python": {
"python": "$python_bin",
"pythonExtraPaths": [
"$site_packages"
]
}
}
},
"folders": [
{
"path": "."
}
]
}
EOF
}
function make_env() {
virtualenv --python="$PYTHON_NAME" "$project_name/$ENV_NAME"
}
if [ -z $project_name ]; then
echo "Usage: pyproject project-name"
exit 1
else
echo "Creating project '$project_name'"
fi
if [ ! -d $project_name ]; then
mkdir $project_name
fi
make_env
configure_sublime
cd $project_name
source $ENV_NAME/bin/activate
alias pyproject="source create-py-project"

Installation

Place create-py-project somewhere on your PATH. Then add the alias in .bash_aliases to the rest of your aliases (Usually found in ~/.bash_aliases). Finally, configure your shell again by either running source ~/.bashrc or by closing and reopening your shell window.

Usage

$ pyproject my-project-name

This will create a new directory for your project, create a virtualenv inside that directory, move into that directory, and activate the virtualenv. It also creates a sublime text project file that is preconfigured for Sublime Code Intel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment