Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #330 from SELab-2/develop
Browse files Browse the repository at this point in the history
Release milestone 2
  • Loading branch information
stijndcl authored Apr 28, 2022
2 parents 5777d68 + 57d684d commit a055d7f
Show file tree
Hide file tree
Showing 361 changed files with 15,646 additions and 1,596 deletions.
53 changes: 27 additions & 26 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
name: Backend CI
on:
pull_request:
push:
paths:
- ".github/workflows/backend.yml"
- "backend/**"
- "!**.md"
branches:
- master
- develop

defaults:
run:
working-directory: backend

jobs:
Dependencies:
runs-on: self-hosted
container: python:3.10.2-alpine
runs-on: ubuntu-latest
container: python:3.10.2-slim-bullseye
steps:
- run: apk add --no-cache tar
- uses: actions/checkout@v2
- uses: actions/cache@v2
id: cache
with:
path: /usr/local/lib/python3.10/site-packages
key: ${{ runner.os }}-site-packages-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
key: venv-${{ runner.os }}-bullseye-3.10.2-v2-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-site-packages-
venv-${{ runner.os }}-bullseye-3.10.2-v2
- if: steps.cache.outputs.cache-hit != 'true'
run: apk add gcc musl-dev build-base mariadb-dev libffi-dev
run: apt update

- if: steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements.txt
run: apt install -y build-essential libmariadb-dev

- if: steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements-dev.txt
run: pip install -U pip poetry

- if: steps.cache.outputs.cache-hit != 'true'
run: |
python -m poetry export --dev --format requirements.txt --output requirements.txt --without-hashes
pip install -r requirements.txt
Test:
needs: [Dependencies]
runs-on: self-hosted
container: python:3.10.2-alpine
runs-on: ubuntu-latest
container: python:3.10.2-slim-bullseye
steps:
- run: apk add --no-cache tar
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: /usr/local/lib/python3.10/site-packages
key: ${{ runner.os }}-site-packages-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
key: venv-${{ runner.os }}-bullseye-3.10.2-v2-${{ hashFiles('**/poetry.lock') }}

- run: python -m pytest

Lint:
needs: [Test]
runs-on: self-hosted
container: python:3.10.2-alpine
runs-on: ubuntu-latest
container: python:3.10.2-slim-bullseye
steps:
- run: apk add --no-cache tar
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: /usr/local/lib/python3.10/site-packages
key: ${{ runner.os }}-site-packages-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
key: venv-${{ runner.os }}-bullseye-3.10.2-v2-${{ hashFiles('**/poetry.lock') }}

- run: python -m pylint src tests
- run: python -m pylint src

Type:
needs: [Test]
runs-on: self-hosted
container: python:3.10.2-alpine
runs-on: ubuntu-latest
container: python:3.10.2-slim-bullseye
steps:
- run: apk add --no-cache tar
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: /usr/local/lib/python3.10/site-packages
key: ${{ runner.os }}-site-packages-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
key: venv-${{ runner.os }}-bullseye-3.10.2-v2-${{ hashFiles('**/poetry.lock') }}

- run: python -m mypy src tests
- run: python -m mypy src
38 changes: 14 additions & 24 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
name: Frontend CI
on:
pull_request:
push:
paths:
- ".github/workflows/frontend.yml"
- "frontend/**"
- "!**.md"
branches:
- master
- develop

defaults:
run:
working-directory: frontend

jobs:
Dependencies:
runs-on: self-hosted
container: node:16.14.0-alpine
runs-on: ubuntu-latest
container: node:16.14.0-bullseye-slim
steps:
- run: apk add --no-cache tar
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -35,12 +33,10 @@ jobs:

Test:
needs: [Dependencies]
runs-on: self-hosted
container: node:16.14.0-alpine
runs-on: ubuntu-latest
container: node:16.14.0-bullseye-slim
steps:
- run: apk add --no-cache tar
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -55,12 +51,10 @@ jobs:

Lint:
needs: [Test]
runs-on: self-hosted
container: node:16.14.0-alpine
runs-on: ubuntu-latest
container: node:16.14.0-bullseye-slim
steps:
- run: apk add --no-cache tar
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -75,12 +69,10 @@ jobs:

Style:
needs: [Test]
runs-on: self-hosted
container: node:16.14.0-alpine
runs-on: ubuntu-latest
container: node:16.14.0-bullseye-slim
steps:
- run: apk add --no-cache tar
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -95,12 +87,10 @@ jobs:

Build:
needs: [Style, Lint]
runs-on: self-hosted
container: node:16.14.0-alpine
runs-on: ubuntu-latest
container: node:16.14.0-bullseye-slim
steps:
- run: apk add --no-cache tar
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand Down
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ Below are the instructions on how to set up the frontend and backend. Instructio

- Create a `Virtual Environment` (`python3 -m venv venv`)

- Install the dependencies (`pip3 install -r requirements.txt -r requirements-dev.txt`)
- Install `Poetry` (`pip3 install poetry`)

- Install the dependencies (`poetry install`)

- Required scripts:

Expand Down Expand Up @@ -129,7 +131,7 @@ Below are the instructions on how to set up the frontend and backend. Instructio
```shell
# Install the required Node version
nvm install 16.14.1

# Make your shell use the newly-installed version
nvm use 16
```
Expand Down Expand Up @@ -218,10 +220,24 @@ yarn build
source venv/bin/activate
```
3. Install the regular dependencies and development dependencies
3. Install Poetry and configure it to use the `Virtual Environment` we created in the previous step
```shell
pip3 install poetry
# Use the existing venv instead of creating a new one
poetry config virtualenvs.create false
poetry config virtualenvs.in-project true
```
3. Install the dependencies
```
pip3 install -r requirements.txt -r requirements-dev.txt
# Install all dependencies
poetry install
# Only install production dependencies
poetry install --no-dev
```
For all commands below, make sure your `Virtual Environment` is activated at all times. Otherwise, your Python interpreter won't be able to find the correct package.
Expand Down
8 changes: 0 additions & 8 deletions backend/.coveragerc

This file was deleted.

4 changes: 4 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ DB_PORT=3306
# JWT key (needs to be changed for production)
# Can be generated using "openssl rand -hex 32"
SECRET_KEY=4d16a9cc83d74144322e893c879b5f639088c15dc1606b11226abbd7e97f5ee5
# The ACCESS JWT token should be valid for ...
ACCESS_TOKEN_EXPIRE_M = 5
# The REFRESH JWT token should be valid for ...
REFRESH_TOKEN_EXPIRE_M = 2880

# Frontend
FRONTEND_URL="http://localhost:3000"
11 changes: 0 additions & 11 deletions backend/.pylintrc

This file was deleted.

28 changes: 20 additions & 8 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Backend

## Setting up a venv
## Setting up a venv and installing dependencies

```bash
Create a venv, install Poetry, and then install the dependencies:

```shell
# Navigate to this directory
cd backend

Expand All @@ -13,11 +15,15 @@ python3 -m venv venv
# PyCharm does this automatically, so this is only required if you're using another IDE
source venv/bin/activate

# Install requirements
pip3 install -r requirements.txt
# Install Poetry
pip3 install poetry

# Install all dependencies and dev dependencies
poetry install

# Install dev requirements
pip3 install -r requirements-dev.txt
# Use the existing venv instead of creating a new one
poetry config virtualenvs.create false
poetry config virtualenvs.in-project true
```

Note that, in case your IDE does not do this automatically, you have to run `source venv/bin/activate` every time you want to run the backend, as otherwise your interpreter won't be able to find the packages.
Expand All @@ -34,9 +40,15 @@ This directory contains a `.env.example` file which shows the general structure

## Keeping requirements up to date

Whenever you'd like to install a new package, make sure to **update the `requirements.txt` or `requirements-dev.txt` files** so that everyone has the same packages installed, and our tests can run easily.
Whenever you'd like to install a new package, install it using `Poetry` so that the [`pyproject.toml`](pyproject.toml)-file is always up-to-date. This ensures we always have the same versions of every package.

In case your package installs multiple other dependencies, it's not necessary to install those along with it. The main package you installed (along with the correct version) is satisfactory.
```shell
# Install a regular dependency
poetry add package_name

# Install a dev dependency
poetry add --dev package_name
```

## Type annotations

Expand Down
35 changes: 17 additions & 18 deletions backend/create_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,23 @@ def get_hashed_password() -> str:

def create_admin(name: str, email: str, pw: str):
"""Create a new user in the database"""
session = DBSession()
transaction = session.begin_nested()

try:
user = create_user(session, name, email)
user.admin = True
session.add(user)
session.commit()

# Add an email auth entry
create_auth_email(session, user, pw)
except sqlalchemy.exc.SQLAlchemyError as e:
# Something went wrong: rollback the transaction & print the error
transaction.rollback()

# Print the traceback of the exception
print(traceback.format_exc())
exit(3)
with DBSession.begin() as session:
try:
transaction = session.begin_nested()
user = create_user(session, name, commit=False)
user.admin = True

# Add an email auth entry
create_auth_email(session, user, pw, email, commit=False)
except sqlalchemy.exc.SQLAlchemyError:
# Something went wrong: rollback the transaction & print the error
transaction.rollback()

# Print the traceback of the exception
print(traceback.format_exc())
exit(3)

session.close()


if __name__ == "__main__":
Expand Down
24 changes: 24 additions & 0 deletions backend/migrations/versions/1862d7dea4cc_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""empty message
Revision ID: 1862d7dea4cc
Revises: 8c97ecc58e5f, a4a047b881db
Create Date: 2022-04-08 16:05:01.649808
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1862d7dea4cc'
down_revision = ('8c97ecc58e5f', 'a4a047b881db')
branch_labels = None
depends_on = None


def upgrade():
pass


def downgrade():
pass
Loading

0 comments on commit a055d7f

Please sign in to comment.