/Services

Django Application for monitoring Bellboy devices

Primary LanguagePythonMIT LicenseMIT

Services

CI Codacy Badge Updates Python 3

Django Application for monitoring Bellboy devices, also provides a frontend for staff to monitor devices and interact with device users

Features

This backend provides the following utilites for use by the Bellboy website and Bellboy devices:

  • Registry for Bellboy devices
  • Authentication for security users

The repository uses the following technology to ensure quality:

  • PyUp.io monitors dependencies to ensure no vulnerabilities are present
  • Github Workflows run pytest to ensure unit tests pass before a build on Heroku
  • Workflows for linting tools ensure the code follows best practices for quality and style:
    • Black enforces code style
    • Flake8 checks for common errors
    • MyPy adds type checking to Python
    • iSort sorts imports to separate imports from stdlib, third party, and local sources
    • An assortment of end-of-file, line-ending, and whitespace checks

Development Instructions

To work on this repository, you'll need to download and install Pycharm and Docker Desktop.

Thanks to a convo with Sein, I've now included a collection of instructions for getting started and troubleshooting.

Generally, to run the development environment, type docker-compose -f development.yml up

Services API docs are hosted at https://bellboy-services.herokuapp.com/swagger/

Setup

These instructions are for Windows 10, which the majority of our team uses. If running on a better OS it is assumed that you are skilled enough to figure all this out by yourself.

  1. Install Docker Desktop from this link. Ensure that you install the WSL2 binaries.
  2. Ensure the WSL integrations are enabled, as seen in the screenshot below: WSL integrations should be enabled in the docker dashboard You do not need to use the Windows Subsystem for Linux (WSL) on GNU/Linux or OSX.
  3. If you have problems with speed or stability in WSL, it's fine to use the Hyper-V backend.
  4. Ensure that everything works by running the following command:
    docker-compose -f development.yml run django pytest
    If all the unit tests pass, you're good to go! Your system should now be ready to do basic development. Any changes you make will be hot-reloaded after running this:
    docker-compose -f development.yml up

Creating a New Branch

git checkout -b <new branch name>
git push --set-upstream origin <new branch name>

Submitting Work

When adding new features, please use the semantic commit labels so versioning is accurate:

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • perf: A code change that improves performance
  • test: Adding missing or correcting existing tests
  • chore: Changes to the build process or auxiliary tools and libraries such as documentation generation

Developing with the Bellboy Services Docker Environment

The database containers can also be accessed externally, allowing you to run manage.py commands from outside the container, but on Windows 10, it may be difficult to successfully install all of the django dependencies, especially psycopg2, and you should probably stick to running commands in the container like so:

docker-compose -f development.yml run django <your cmd here>

Starting a New Django Application

Within the Services project, functionality is organized into apps. For example, there could be an app to manage users, an app to run an endpoint to manage camera data, and an endpoint to continuously process incoming data from successful ultrasonic activations.

The filesystem is organized like so:

Services (root folder)
  - services (application folder)
    - users
    - utils
    - <your app here>

To add a new app, you'll need to do these things:

  1. Know what you want to name your new app.
  2. Right-click the 'services' folder and add a new python package.
  3. Inside the folder, there should exist a file called __init__.py, just make sure it's there.
  4. Create a new python file in the folder called apps.py, and add the following:
    from django.apps import AppConfig
    from django.utils.translation import gettext_lazy as _
    
    class <AppName>Config(AppConfig):
        name = "services.<appname>"
        verbose_name = _("<App Name>")
  5. Now the app needs to be added to the LOCAL_APPS list in config > settings > base.py:
    LOCAL_APPS = [
      "services.users.apps.UsersConfig",
      # Your stuff: custom apps go here
      "services.<appname>.apps.<AppName>Config"
    ]
  6. That's it, your new app will be loaded and run when Django starts.
  7. Enjoy a scoop of ice cream.

Old Instructions

# Install requirements:
# (In admin console on windows)
pip install -r requirements.txt
# (Or on linux/OSX)
python3 -m pip install -r requirements.txt

# Set up pre-commit
pre-commit install

# Launch the Services component with docker
docker-compose -f development.yml up

# Run the unit tests
docker-compose -f development.yml run django pytest

# Branch and start hacking!
git checkout -b my-new-branch-name