Server
This document describes how to install and run the server.
Installing
You will need to do the following things to install the server:
- Install Visual Studio Code (VS Code).
- Install Python.
- Install pip (should already be installed with python)
- Clone this repository if you haven't done so already.
- Open the project folder in VS Code.
- Open the integrated terminal by pressing
ctrl+ö
. - Type the following commands into your terminal:
- (Production) Install PostgreSQL 13
Windows
# Install virtualenv package. You may need to open as administrator if you get
# permission denied.
pip install virtualenv
# Go into the server folder.
cd server
# Create a python virtual environment. If it can't find Python, try
# python or py -3 instead of py.
py -m venv env
# Prevent unauthorized error when running virtual environment in Windows.
Set-ExecutionPolicy Unrestricted -Scope Process
# Activate the virtual environment.
./env/Scripts/activate
# Install all the required packages into your virtual environment.
pip install -r requirements.txt
Linux(Ubuntu)
# Install pip
sudo apt-get install python-pip
# Install virtualenv package.
sudo apt install python3-venv
# Go into the server folder.
cd server
# Create a python virtual environment. If it can't find python3, try python.
python3 -m venv env
# Activate the virtual environment.
source env/bin/activate
# Install all the required packages into your virtual environment.
# If pip don't work try pip3 instead
pip install -r requirements.txt
The last step is to install all the required packages.
If you are running it in production, run pip install -r requirements.txt
.
But if you are a developer, run pip install -r requirements-dev.txt
.
Common problems
Make sure python +3.8 is running with the python command
(Windows): py --version or py3 --version
(Linux): python --version or python3 --version
(Linux) This guide can help you upgrade python
(Windows) Download python 3.8 here
Make sure pip is running with python 3 and right
pip --version
Should return something similar to (these stats work on my system):
-> pip 19.2.3 from PATH (python 3.8)
If it says python < 3, try:
pip3 --version
This guide can help you upgrade pip
Problem: Failed building wheel for xyz when calling pip
pip install wheel
Problem: psycopg
pip install psycopg2
This guide can help you troubleshoot this problem
Using
After you have done every step described in setup, you are ready to start the server.
To see the tasks described in the following steps, press ctrl+shift+b
.
Populating database
Populate database by running the Populate database
task. (populate.py)
Starting
Start the server by running the Start server
task. (main.py)
Testing
Run the client tests running the Test server
task.
Or run manually with:
pytest --cov-report html --cov app tests/
After it has finished, you can view a coverage report.
This is done by running the Open server coverage
task.
Or run manually with:
start ./htmlcov/index.html
Adding and removing new packages
All of the following snippets assume you are in the server
folder and have activated the virtual environment (see Setup).
Installing new package:
pip install <package>
Uninstalling package:
pip uninstall <package>
If you have added or removed a package from the repository, you will also have to run the following before commiting it to git:
pip freeze > requirements.txt
Whenever a new package is installed, commited and pushed to git, everyone else needs to run pip install -r requirements.txt
after pulling to install it as well.