Answer King Python App
-
- Uses
pyproject.tomlto build a virtual environment and installs all necessary packages - Follow installation documentation to configure Poetry for Windows https://python-poetry.org/docs/
- Uses
-
- Required by
pyrightpackage to detect and verify correct types have been used in the codebase
- Required by
-
- Used to set up a disposable local MySQL database quickly.
- Install Docker following the docs here.
- Used to set up a disposable local MySQL database quickly.
-
- dependencies: python3.10 git curl libmysqlclient-dev build-essential python3.10-dev
- Open root folder and run command
poetry install - This will install a virtual environment to a path that looks like this
C:\Users\Username\AppData\Local\pypoetry\Cache\virtualenvs. Alternatively, run commandpoetry env infoorpoetry show -vin the folder containingpyproject.tomland this will display where the virtual environment was installed
- Add the required environment variables. The easiest ways to do this is with a .env file which can be provided by another member of the team.
- Install the required MySQL container using
docker compose up -d - Migrate the database using
poetry run python manage.py migrate
- Run program using
poetry run python manage.py runserver
- Test program using
poetry run python manage.py test
Commands for maintaining consistency and PEP8 standards across codebase, as well as checking code coverage.
-
poetry run pyright
-
- Run in root folder
poetry run black .- To follow PEP8 guidelines for line length
poetry run black --line-length=79 .
- To follow PEP8 guidelines for line length
- Run in root folder
-
- Run in root folder
poetry run pycodestyle .- To ignore
E501 line too longerror as this will be handled byblack. Runpoetry run pycodestyle --ignore=E501 .
- To ignore
- Run in root folder
-
- Test using coverage
poetry run coverage run manage.py test- View coverage report in the terminal
poetry run coverage report - Generate interactive coverage file to view in a browser
poetry run coverage html, then openhtmlcov/index.html
- View coverage report in the terminal
- Test using coverage
To view the python backend application we can spin up the app on docker. To do this ensure docker is installed then:
- create a .env.production file containing (filling out the database password with your chosen password):
DATABASE_NAME=answerking_app
DATABASE_HOST=host.docker.internal
DATABASE_PORT=3306
DATABASE_USER=root
DATABASE_PASS=
SECRET_KEY="django-insecure-x977=v5a2q-e%_5$b9ge@jzk%s_nhk2l8_use&h@*m$w33dopr"
DJANGO_SETTINGS_MODULE=answerking.settings.base
DATABASE_ENGINE="django.db.backends.mysql"
-
run in git bash :
docker compose builddocker compose --env-file .env.production up(This runs your built image with the .env.production variables)
-
send HTTP requests to 127.0.0.1:8000
To view the AnswerKing Python API documentation in Swagger as per OpenAPI specification, visit the following URL while your local server is running: http://127.0.0.1:8000/api/schema/swagger-ui/