Skip to content

Commit

Permalink
Refactor project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Mar 24, 2024
1 parent 6edcdc1 commit 72fb8c5
Show file tree
Hide file tree
Showing 67 changed files with 61 additions and 252 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
pip install -r requirements/ci.txt
- name: Run Bandit
run: |
bandit -r articles/ -x tests
bandit -r src/articles/ -x tests
bandit -r src/scraper/ -x tests
#
# Tests
#
Expand Down Expand Up @@ -58,9 +59,9 @@ jobs:
DJANGO_ENV: BASE
SECURE_SSL_REDIRECT: False
run: |
pytest articles/tests/unit/
pytest articles/tests/integration/
pytest scraper/tests/
pytest src/articles/tests/unit/
pytest src/articles/tests/integration/
pytest src/scraper/tests/
#
# Migrations
Expand Down
137 changes: 0 additions & 137 deletions articles/static/css/main.css

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions nous_aggregator/asgi.py → config/asgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
ASGI config for nous_aggregator project.
ASGI config for nous-aggregator project.
It exposes the ASGI callable as a module-level variable named ``application``.
Expand All @@ -12,6 +12,6 @@
from django.core.asgi import get_asgi_application
from django.core.handlers.asgi import ASGIHandler

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'nous_aggregator.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application: ASGIHandler = get_asgi_application()
4 changes: 2 additions & 2 deletions nous_aggregator/celery.py → config/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from celery import Celery

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "nous_aggregator.settings.local")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")

app = Celery("nous_aggregator")
app = Celery("config")

app.config_from_object("django.conf:settings", namespace="CELERY")

Expand Down
21 changes: 21 additions & 0 deletions config/scraper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
tasks = {
"magazines": {
"en": {
"schedule": 120,
"titles": [
"Al Jazeera",
"Associated Press",
"Christian Science Monitor",
"Consortium News",
"Current Affairs",
"New York Times",
"NPR",
"Reuters",
"The Atlantic",
"The Intercept",
"UPI",
"Wall Street Journal",
]
},
},
}
File renamed without changes.
16 changes: 10 additions & 6 deletions nous_aggregator/settings/base.py → config/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import os
import sys
from pathlib import Path
from typing import Any, Dict, List, Union
from typing import Any, Dict

from decouple import Csv, config

from scraper import tasks as scraper_tasks
from .. import scraper

# Build paths inside the project like this: BASE_DIR / 'subdir'.
# (modified because settings files are nested one level deeper)
BASE_DIR: Path = Path(__file__).resolve().parent.parent.parent
BASE_DIR = Path(__file__).resolve().parent.parent.parent

# Add "src" to Python path
sys.path.insert(0, os.path.join(BASE_DIR, "src"))

SECRET_KEY = config("SECRET_KEY", default="")

Expand Down Expand Up @@ -62,7 +66,7 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "nous_aggregator.urls"
ROOT_URLCONF = "config.urls"

INTERNAL_IPS = [
"127.0.0.1",
Expand All @@ -84,7 +88,7 @@
},
]

WSGI_APPLICATION = "nous_aggregator.wsgi.application"
WSGI_APPLICATION = "config.wsgi.application"


# Logging
Expand Down Expand Up @@ -188,7 +192,7 @@
CELERY_BEAT_SCHEDULE = {
"get_articles_en": {
"task": "articles.tasks.get_articles",
"schedule": scraper_tasks.magazines["en"]["schedule"],
"schedule": scraper.tasks["magazines"]["en"]["schedule"],
"kwargs": {
"language": "en",
}
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion nous_aggregator/urls.py → config/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""nous_aggregator URL Configuration
"""nous-aggregator URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/topics/http/urls/
Expand Down
4 changes: 2 additions & 2 deletions nous_aggregator/wsgi.py → config/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
WSGI config for nous_aggregator project.
WSGI config for nous-aggregator project.
It exposes the WSGI callable as a module-level variable named ``application``.
Expand All @@ -12,6 +12,6 @@
from django.core.handlers.wsgi import WSGIHandler
from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'nous_aggregator.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application: WSGIHandler = get_wsgi_application()
2 changes: 1 addition & 1 deletion heroku.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ release:
image: web

run:
web: gunicorn nous_aggregator.wsgi
web: gunicorn config.wsgi
worker:
command:
- python manage.py scrape
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main() -> None:
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'nous_aggregator.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
16 changes: 14 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# mypy
[tool.mypy]
python_version = 3.11
plugins = ["mypy_django_plugin.main"]
python_executable="home/pi-sigma/.virtualenvs/nous/bin/python"
ignore_missing_imports=true

[tool.django-stubs]
django_settings_module = "nous_aggregator.settings.local"
django_settings_module = "config.settings.local"

# pytest
[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "config.settings.local"

# pytype
[too.pytype]
python_version = 3.11
inputs = ["src/articles/management", "src/articles/scraper", "src/articles/*.py"]
disable = "import-error"
38 changes: 0 additions & 38 deletions requirements/pyppeteer_deps.txt

This file was deleted.

19 changes: 0 additions & 19 deletions scraper/tasks.py

This file was deleted.

Loading

0 comments on commit 72fb8c5

Please sign in to comment.