Skip to content

Instantly share code, notes, and snippets.

@fbidu
Last active May 3, 2019 14:19
Show Gist options
  • Save fbidu/7b7b8a857a898770ade474928f66e8c2 to your computer and use it in GitHub Desktop.
Save fbidu/7b7b8a857a898770ade474928f66e8c2 to your computer and use it in GitHub Desktop.
A simple shell script that bootstraps a basic Python project

Bootstrapping a Python project

Just give me the script!

From inside a new folder run:

pipenv --three
pipenv install --dev --pre pylint black pytest
touch README.md
mkdir tests
touch main.py
wget https://www.gitignore.io/api/vim%2Clinux%2Cpython%2Cvscode -O .gitignore
git init
git add .
git commit -m 'Initial commit'

The Problem

Everytime I start a new Python project, I do the same things over and over:

  1. Initialize a Pipenv environment
  2. Install black, pylint, and pytest
  3. Create a tests folder
  4. Download a .gitignore from gitignore.io
  5. Initialize a git repo
  6. Make a first commit called "Initial commit"

There are tons of ways to organize your project ― create a second folder with the name of your project? Create the tests folder inside that new one? Use a src folder? Create a __init__.py file? A __main__.py file? create both?! ― and even I don't the same structure for every project, but those 6 steps are included in all of them.

The Solution

A bash script ― or even an alias! ― that does all of the steps. The general idea is:

pipenv --three
pipenv install --dev --pre pylint black pytest
touch README.md
mkdir tests
touch main.py
wget https://www.gitignore.io/api/vim%2Clinux%2Cpython%2Cvscode -O .gitignore
git init
git add .
git commit -m 'Initial commit'

As you can see, all the steps are performed in an orderly manner. You can edit it in anyway you want. If you use bash, add it as an alias in you .bashrc file. I call it "pyay":

alias pyay="pipenv --three; pipenv install --dev --pre pylint black pytest; touch README.md; mkdir -p src/tests; touch src/main.py;  wget https://www.gitignore.io/api/vim%2Clinux%2Cpython%2Cvscode -O .gitignore; git init; git add .; git commit -m 'Initial commit'"

If you use xonsh ― and if you're a Python developer you really should check it out! ― just add the alias to your .xonshrc.

Alternatives

This file was created in the context of this Reddit thread I created to ask other fellow developers about their workflow regarding that sort of issue.

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