Skip to content

Commit

Permalink
Restructure application to follow Django/Resonant best practices (#438)
Browse files Browse the repository at this point in the history
* Restructure Django app to follow Resonant best practices

* Update references to Django app names

* Update `settings` and `urls` modules

* Update ci.yaml

* Update Dockerfile

* Move celery.py to toplevel rdwatch module

* Updating linting settings

* Fix import

* Update poetry versioning config

* Update django app names

* Missed module rename

* Fix app_label

* Fix INSTALLED_APPS labels

* Fix app name

* Fix urls module

* Fix import statements

* Update tox `check-migrations` command

* Update migration module names

* Override `migrate` command to also rename apps

* Update index names in migrations

These names were generated by `django-admin makemigrations`

* Update model names in lookups.json

* Move custom allauth adapters/middleware to root module

* Update module path of beat task

* Properly conditionalize app renaming operation

* renaming some docker paths to allow local docker compose dev (#439)

* renaming some docker paths to allow local docker compose dev

* remove extra space

* Fix app key names

---------

Co-authored-by: Bryon Lewis <[email protected]>
  • Loading branch information
mvandenburgh and BryonLewis authored Jun 4, 2024
1 parent 9c04440 commit fdcabde
Show file tree
Hide file tree
Showing 165 changed files with 506 additions and 399 deletions.
File renamed without changes.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
env:
# using a dummy secret key
DJANGO_CONFIGURATION: DevelopmentConfiguration
DJANGO_SETTINGS_MODULE: rdwatch.server.settings
DJANGO_SETTINGS_MODULE: rdwatch.settings
RDWATCH_SECRET_KEY: ff07f533a59fed1349a4fc49941d02ff22514f6dbf6086a44ea0c0a8952e8644
RDWATCH_POSTGRESQL_URI: postgresql://rdwatch:ff07f533a59fed1349a4fc49941d02ff22514f6dbf6086a44ea0c0a8952e8644@localhost:5432/rdwatch
RDWATCH_CELERY_BROKER_URL: redis://localhost:6379/
Expand Down Expand Up @@ -117,7 +117,6 @@ jobs:
run: pip install --upgrade poetry tox
- name: Run tests
run: tox -e ${{ matrix.tox-env }}
working-directory: django
test-vue:
name: Test [vue]
runs-on: ubuntu-22.04
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
files: ^(django|scripts)/
files: ^(rdwatch|scripts)/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand All @@ -21,13 +21,13 @@ repos:
rev: 23.12.1
hooks:
- id: black
args: [--config, django/pyproject.toml]
args: [--config, pyproject.toml]

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: [--settings-file, django/pyproject.toml]
args: [--settings-file, pyproject.toml]

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
Expand Down Expand Up @@ -61,4 +61,4 @@ repos:
- flake8-quotes
args:
- --config
- django/.flake8
- .flake8
55 changes: 28 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,37 @@ COPY vue/package.json vue/package-lock.json /app/vue/
RUN npm ci

FROM builder AS django-builder
WORKDIR /app/django
COPY django/pyproject.toml django/poetry.lock /app/django/
RUN mkdir /app/django/src \
&& mkdir /app/django/src/rdwatch \
&& touch /app/django/src/rdwatch/__init__.py \
&& mkdir /app/django/src/rdwatch_scoring \
&& touch /app/django/src/rdwatch_scoring/__init__.py \
&& mkdir /app/django/src/rdwatch_smartflow \
&& touch /app/django/src/rdwatch_smartflow/__init__.py \
&& touch /app/django/README.md \
WORKDIR /app/
COPY pyproject.toml poetry.lock /app/
RUN mkdir /app/rdwatch \
&& mkdir /app/rdwatch/core \
&& touch /app/rdwatch/core/__init__.py \
&& mkdir /app/rdwatch/scoring \
&& touch /app/rdwatch/scoring/__init__.py \
&& mkdir /app/rdwatch/smartflow \
&& touch /app/rdwatch/smartflow/__init__.py \
&& touch /app/README.md \
&& poetry install --only main


# Build stage that also installs dev dependencies.
# For use in a development environment.
FROM builder AS dev
WORKDIR /app/django
COPY django/pyproject.toml django/poetry.lock /app/django/
RUN mkdir /app/django/src \
&& mkdir /app/django/src/rdwatch \
&& touch /app/django/src/rdwatch/__init__.py \
&& mkdir /app/django/src/rdwatch_scoring \
&& touch /app/django/src/rdwatch_scoring/__init__.py \
&& mkdir /app/django/src/rdwatch_smartflow \
&& touch /app/django/src/rdwatch_smartflow/__init__.py \
&& touch /app/django/README.md \
WORKDIR /app/
COPY pyproject.toml poetry.lock /app/
RUN mkdir /app/rdwatch \
&& mkdir /app/rdwatch/core \
&& touch /app/rdwatch/core/__init__.py \
&& mkdir /app/rdwatch/scoring \
&& touch /app/rdwatch/scoring/__init__.py \
&& mkdir /app/rdwatch/smartflow \
&& touch /app/rdwatch/smartflow/__init__.py \
&& touch /app/README.md \
&& poetry install --with dev
# Copy git metadata to enable display of version information
RUN git config --global --add safe.directory /app/django
RUN git config --global --add safe.directory /app/
COPY .git/ /app/.git/
COPY manage.py /app/manage.py


# Built static assets for vue-rdwatch
Expand All @@ -110,11 +111,11 @@ RUN chmod -R u=rX,g=rX,o= /app/vue/dist


# Built virtual environment for django-rdwatch
# editable source is in /app/django/src/rdwatch
# virtual environment is in /app/django/.venv
# editable source is in /app/rdwatch
# virtual environment is in /app/rdwatch/.venv
FROM django-builder AS django-dist
COPY django/src /app/django/src
COPY django/src/manage.py /app/django/src/manage.py
COPY rdwatch/ /app/rdwatch/
COPY manage.py /app/manage.py
RUN chmod -R u=rX,g=rX,o= .


Expand All @@ -128,8 +129,8 @@ COPY --from=django-builder \
# Copy django source code
COPY --from=django-dist \
--chown=rdwatch:rdwatch \
/app/django \
/app/django
/app/ \
/app/
# Copy vue static assets
COPY --from=vue-dist \
--chown=unit:unit \
Expand Down
2 changes: 1 addition & 1 deletion dev/.env.docker-compose
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DJANGO_CONFIGURATION="DevelopmentConfiguration"
DJANGO_SETTINGS_MODULE="rdwatch.server.settings"
DJANGO_SETTINGS_MODULE="rdwatch.settings"
RDWATCH_DJANGO_DEBUG=1
RDWATCH_ACCENTURE_VERSION="3"
RDWATCH_MINIO_STORAGE_ENDPOINT=minio:9000
Expand Down
2 changes: 1 addition & 1 deletion dev/.env.docker-compose-native
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DJANGO_CONFIGURATION="DevelopmentConfiguration"
DJANGO_SETTINGS_MODULE="rdwatch.server.settings"
DJANGO_SETTINGS_MODULE="rdwatch.settings"
RDWATCH_DJANGO_DEBUG=1
RDWATCH_ACCENTURE_VERSION="3"
RDWATCH_MINIO_STORAGE_ENDPOINT=localhost:9000
Expand Down
3 changes: 0 additions & 3 deletions django/src/rdwatch_scoring/__init__.py

This file was deleted.

16 changes: 8 additions & 8 deletions docker-compose.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ services:
target: dev
command: [
"poetry", "run",
"--directory", "/app/django",
"/app/django/src/manage.py",
"--directory", "/app",
"/app/manage.py",
"runserver", "0.0.0.0:8000"
]
env_file:
Expand All @@ -23,8 +23,8 @@ services:
retries: 5

volumes:
- ./django:/app/django
- ./.git:/app/django/.git
- ./rdwatch:/app/rdwatch
- ./.git:/app/rdwatch/.git
ports:
- 8000:8000
depends_on:
Expand All @@ -38,7 +38,7 @@ services:
target: dev
command: [
"poetry", "run",
"--directory", "/app/django",
"--directory", "/app/rdwatch",
"celery",
"--app", "rdwatch.celery",
"worker",
Expand All @@ -53,7 +53,7 @@ services:
RDWATCH_REDIS_URI: "redis://redis:6379"
RDWATCH_CELERY_BROKER_URL: "redis://redis:6379"
volumes:
- ./django:/app/django
- ./rdwatch:/app/rdwatch
- celery-SAM-model:/data/SAM

depends_on:
Expand All @@ -71,7 +71,7 @@ services:
target: dev
command: [
"poetry", "run",
"--directory", "/app/django",
"--directory", "/app/rdwatch",
"celery",
"--app", "rdwatch.celery",
"beat",
Expand All @@ -85,7 +85,7 @@ services:
RDWATCH_REDIS_URI: "redis://redis:6379"
RDWATCH_CELERY_BROKER_URL: "redis://redis:6379"
volumes:
- ./django:/app/django
- ./rdwatch:/app/rdwatch
rdwatch-client:
image: node:20
container_name: rd-watch-client
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
set -e

export DJANGO_SETTINGS_MODULE=rdwatch.server.settings
export DJANGO_SETTINGS_MODULE=rdwatch.settings

# Tail Django logs
touch /tmp/django.log
Expand Down
4 changes: 2 additions & 2 deletions docker/nginx.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
"type": "python 3.11",
"user": "rdwatch",
"group": "rdwatch",
"path": "/app/django/",
"path": "/app/rdwatch/",
"home": "/poetry/venvs/rdwatch/",
"module": "rdwatch.server",
"module": "rdwatch.wsgi",
"threads": 25,
"limits": {
"timeout": 120,
Expand Down
2 changes: 1 addition & 1 deletion django/src/manage.py → manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def main() -> None:
os.environ['DJANGO_SETTINGS_MODULE'] = 'rdwatch.server.settings'
os.environ['DJANGO_SETTINGS_MODULE'] = 'rdwatch.settings'
os.environ.setdefault('DJANGO_CONFIGURATION', 'DevelopmentConfiguration')
configurations.importer.install(check_options=True)

Expand Down
16 changes: 15 additions & 1 deletion django/poetry.lock → poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions django/pyproject.toml → pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ classifiers = [
"Framework :: Django",
]
packages = [
{ include = "rdwatch", from = "src" },
{ include = "rdwatch_scoring", from = "src"},
{ include = "rdwatch_smartflow", from = "src"},
{ include = "rdwatch" },
]

[tool.poetry-dynamic-versioning]
Expand All @@ -31,7 +29,7 @@ vcs = "git"
metadata = true

[tool.poetry-dynamic-versioning.substitution]
files = ["src/rdwatch/__init__.py", "src/rdwatch_scoring/__init__.py", "src/rdwatch_smartflow/__init__.py"]
files = ["rdwatch/__init__.py"]

[tool.poetry.dependencies]
python = ">=3.11.8,<4"
Expand Down Expand Up @@ -62,6 +60,7 @@ apache-airflow-client = "^2.9.0"
beautifulsoup4 = "^4.12.3"
django-allauth = {extras = ["socialaccount"], version = "^0.63.2"}
django-login-required-middleware = "^0.9.0"
django-rename-app = "^0.1.7"

[tool.poetry.group.dev.dependencies]
django-stubs = "^4.2.7"
Expand Down Expand Up @@ -96,7 +95,7 @@ skip-string-normalization = true

[tool.isort]
profile = "black"
known_first_party = ["rdwatch", "rdwatch_scoring", "rdwatch_smartflow"]
known_first_party = ["rdwatch"]
known_django=["django"]
sections=["FUTURE", "STDLIB", "THIRDPARTY", "DJANGO", "FIRSTPARTY", "LOCALFOLDER"]

Expand All @@ -113,7 +112,7 @@ ignore_missing_imports = true


[tool.django-stubs]
django_settings_module = "rdwatch.server.settings"
django_settings_module = "rdwatch.settings"


[tool.flake8]
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion django/src/rdwatch/celery.py → rdwatch/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import configurations.importer
from celery import Celery

os.environ['DJANGO_SETTINGS_MODULE'] = 'rdwatch.server.settings'
os.environ['DJANGO_SETTINGS_MODULE'] = 'rdwatch.settings'
if not os.environ.get('DJANGO_CONFIGURATION'):
raise ValueError('The environment variable "DJANGO_CONFIGURATION" must be set.')
configurations.importer.install()
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion django/src/rdwatch/admin.py → rdwatch/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from rdwatch.models import (
from rdwatch.core.models import (
ModelRun,
Performer,
Region,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion django/src/rdwatch/apps.py → rdwatch/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class RDWatchConfig(AppConfig):
default_auto_field = 'django.db.models.AutoField'
name = 'rdwatch'
name = 'rdwatch.core'
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit fdcabde

Please sign in to comment.