A pyramid app for case interview
Make sure you have python>3.5.1 and git installed, so they are available from the command line.
# clone code from git
git clone https://github.com/VanOord/pyramid-app-caseinterview.git
cd pyramid-app-caseinterview
# upgrade pip
pip install -U pip
pip install -U setuptools
# install requirements
pip install -r requirements.txt
# install this package
pip install -e .
Note that, for development, it is advised to manually checkout and install the requirements listed in requirements-git.txt
.
Keep *.ini files under version control, but do not store passwords in version control. Therefore the parameters for the database connection should be defined as environmental variables.
Precedence of the defined parameters for database access is as follows:
- sqlalchemy.url set in *.ini (use this form:
sqlalchemy.url = postgresql://user:password@host:port/dbname
) PG_USER
,PG_PASSWORD
,PG_HOST
,PG_PORT
andPG_DBNAME
set in *.iniPG_USER
,PG_PASSWORD
,PG_HOST
,PG_PORT
andPG_DBNAME
environmental variables- Default values
(Temporarily) set correct database settings in *.ini or environmental variables. When using the *.ini file, make sure not to commit this file to GitHub.
The default settings and how to set them as environmental variables are listed below. This differs for windows and linux.
export PG_PASSWORD=
export PG_USER=postgres
export PG_HOST=localhost
export PG_PORT=5432
export PG_DBNAME=test
Add variables to /etc/environment
to persist them, see here
SET PG_PASSWORD=
SET PG_USER=postgres
SET PG_HOST=localhost
SET PG_PORT=5432
SET PG_DBNAME=test
Use SETX
instead to persist the variables, see here
SETX PG_PASSWORD
SETX PG_USER postgres
SETX PG_HOST localhost
SETX PG_PORT 5432
SETX PG_DBNAME test
Optionally initialize the email SMTP settings:
SET EMAIL_SMTP_URL=smtp.office365.com:587
SET EMAIL_SMTP_USER=openearth@vanoord.com
SET EMAIL_SMTP_PASSWORD=
Again, use SETX
instead to persist the variables
When the application is installed (with pip install ...
), several executable-scripts are made
available on your PATH. This might require a reload of the command prompt / shell environment.
These scripts are made available as executables (.exe on Windows) rather than as python scripts,
so you can run them from anywhere without starting a python instance yourselves (in Anaconda3\Scripts\ on Windows).
With these executable-scripts, the database can be initialised as follows:
pyramid_app_caseinterview_initialize_db development.ini
Serve with
pserve development.ini
or for debugging
pserve development.ini --reload
Browse to http://localhost:6543
Set environmental variables if necessary (see above) and run
pytest
Make sure you have docker and docker-compose installed.
Build the image:
docker build -t pyramid_app_caseinterview .
Create and run the docker-compose.yml file:
docker-compose up
Start a terminal inside the application container:
docker exec -it pyramid_app_caseinterview_app /bin/bash
Install the environment:
pip install -e .
Initialize and synchronize the database:
pyramid_app_caseinterview_initialize_db development-docker.ini
Run the application:
pserve development-docker.ini --reload