Example Python CLI project
Install (follow instructions below) and run the example CLI:
list-buckets --help
Using homebrew, install pyenv
:
brew install pyenv
Then use pyenv
to install the most Python 3.7.x
version (currently 3.7.6
):
pyenv install 3.7.6
And switch to using this version by default whenever you use pyenv
:
pyenv global 3.7.6
Install virtualenvwrapper globally so you can use it to manage isolated Python virtualenvs by name:
$(pyenv which pip) install virtualenv virtualenvwrapper
Update your ~/.bash_profile
so that when you use virtualenvwrapper
to create a virtualenv
,
it uses the version of Python you installed above with pyenv
:
export VIRTUALENVWRAPPER_PYTHON=$(pyenv which python)
export VIRTUALENVWRAPPER_VIRTUALENV=$(pyenv which virtualenv)
source $(pyenv which virtualenvwrapper.sh)
Load these new settings:
source ~/.bash_profile
Once you've installed virtualenvwrapper
, you should change your environment to prevent installation
of Python packages outside of a virtualenv
.
To do so, update your ~/.bash_profile
to contain:
export PIP_REQUIRE_VIRTUALENV=true
Note that you will need to temporarily unset this variable need to (re)install any global packages, such
as virtualenvwrapper
.
Using virtualenvwrapper
, create a named virtualenv
for this project:
mkvirtualenv sandbox
Upon running this command, you will automatically be "inside" of the virtualenv
.
You can leave the virtualenv
by running:
deactivate
You can return to the virtualenv
by running:
workon sandbox
You can delete the virtualenv
by running:
rmvirtualenv sandbox
From inside the virtualenv
, instal dependencies in editable mode.
pip install -e .[lint,test,typehinting]
To run the linter:
flake8 sandbox
To run unit tests:
pytest sandbox
To run unit the type checker:
mypy sandbox