-
Notifications
You must be signed in to change notification settings - Fork 2
Cheatsheet | Virtual Environment and Build Flow
Lenny edited this page Apr 12, 2019
·
2 revisions
This page was created to explain the build process in detail and to shed light on the environment setup. During session #1, you:
- Cloned the repository to get access to the code
- Added several aliases to the .bashrc to get access to some new commands on your Git Bash terminal
- Downloaded Python 3.7 and an Integrated Development Environment (IDE) for writing code
- Ran the build environment script
- Downloaded Slack and got on GitHub
The following sections serve as Q/A to clarify any questions that came up during session 1.
- What does it mean to clone a repository?
- You are downloading a copy of some source code and linking your code to the remote code that is hosted on GitHub.
- You also needed to be added to the NiaStemGroup so that you would have permission to push code back up to the repository
- What is a .bashrc file?
- It is a script that is run every time that you open your interactive terminal (e.g. Git Bash). More details: https://unix.stackexchange.com/questions/129143/what-is-the-purpose-of-bashrc-and-how-does-it-work
- Why did we make one?
- So that you get some commands already available to you by default on your Git Bash command line to make it easier to work with PyStockAnalyze.
- Why did I have to specifically download Python 3.7.2?
- Because Lennard sucks at provisioning virtual environments--I setup the virtual environment to have overly specific requirements, which broke down if the user had lower versions of Python. In future runs of our Python sessions this will be addressed.
- What did the buildenv command do?
- It called a script inside of your repository, tools/buildenv.sh, which did the following:
- Setup environment variables to provide ease of use aliases:
- activate - Enables the built virtual environment, called only after environment has been built
- manage - Shortcut for running "python manage.py"; For instance python manage.py runserver is replaced with manage runserver
- gits - Shortcut for running "git flow feature start"
- gite - Shortcut for running "git flow feature finish"
- The first time that it is run for a repository:
- Creates virtual environment in build/pydjango-build-env
- Activates the virtual environment
- Upgrades pip, the python package manager
- Installs the list of library dependencies specified in the tools/requirements.txt files
- Setup environment variables to provide ease of use aliases:
- It called a script inside of your repository, tools/buildenv.sh, which did the following:
#!/bin/bash -e
echo "[build] Creating project environment variables"
PROJ_ROOT_DIR=$(git rev-parse --show-toplevel) # Finds repository root directory
PROJ_BUILD_PATH=$PROJ_ROOT_DIR/build # Path to build folder
PROJ_SRC_PATH=$PROJ_ROOT_DIR/src # Path to source folder
PROJ_TOOL_PATH=$PROJ_ROOT_DIR/tools # Path to tools folder
PROJ_VENV_NAME='pydjango-build-env' # Name of virtual environment
PROJ_VENV_PATH=$PROJ_BUILD_PATH/$PROJ_VENV_NAME # Path to virtual environment
PROJ_ACTENV_PATH=$PROJ_VENV_PATH/Scripts/activate # Path to the activate script
# Pointer to manage python script
PROJ_DJNAME='pysdjango' # Django project folder name
PROJ_DJANGO_PATH=$PROJ_SRC_PATH/$PROJ_DJNAME # Path to django project
PROJ_MANAGE_PATH=$PROJ_DJANGO_PATH/manage.py # Path to the Django manage.py script
alias manage='python $PROJ_MANAGE_PATH' # Shortcut to run python manage.py <command>
# Local environment (not-to-be-commited) directory
PROJ_LOC_PATH=$PROJ_DJANGO_PATH/$PROJ_DJNAME/localenv
# Create activate script pointer
alias activate='source $PROJ_ACTENV_PATH' # Alias to make it possible to run activate from any folder from within the project
# Section only ran if the build environment hasn't been run
# if there are any environment changes, the user must run cleanenv followed by rerunning buildenv
if [ ! -d $PROJ_VENV_PATH ]; then
if [ ! -d $PROJ_BUILD_PATH ]; then
mkdir $PROJ_BUILD_PATH # Create build folder if it doesn't exist
fi
echo "[build] Creating python virtual environment"
python -m venv "$PROJ_VENV_PATH" # Create virtual environment (Python 3.x+ only)
# Install dependencies into environment
echo "[build] Activate virtual environment"
activate # Jump into the virtual environment so that packages can be installed there
echo "[build] Upgrading pip installation"
python -m pip install --upgrade pip $PROXY_OPT # Upgrade pip
echo "[build] Instsalling dependencies"
pip install -r $PROJ_TOOL_PATH/requirements.txt $PROXY_OPT # Install all files listed in the requirements.txt file
else
echo "[build] Python virtual environment already exists"
fi
alias gits='git flow feature start'
alias gite='git flow feature finish'
NIA STEM Club (c) 2019