Skip to content

Commit

Permalink
add pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
FireFading committed Apr 14, 2023
1 parent 013d856 commit 8f946f7
Show file tree
Hide file tree
Showing 34 changed files with 179 additions and 64 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/nox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Formatting, Linting, Type Checking, Testing

on: [push]

jobs:
nox:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run nox
run: |
pip install nox
nox
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ RUN python -m pip install --upgrade pip
RUN python -m pip install -r requirements.txt

COPY . /code/
RUN python manage.py collectstatic --no-input

EXPOSE 8000

CMD ["gunicorn", "-c", "./gunicorn/conf.py", "--bind", ":8000", "--chdir", "scraping", "scraping.wsgi:application"]
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions core/admin.py → app/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib import admin
from core.models import News
from django.contrib import admin

admin.site.register(News)
admin.site.register(News)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 4.1.7 on 2023-03-26 21:34

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="news",
name="created_at",
field=models.DateTimeField(auto_now_add=True, verbose_name="Parsed/created at"),
),
migrations.AlterField(
model_name="news",
name="link",
field=models.CharField(default="", max_length=2083, verbose_name="Link"),
),
migrations.AlterField(
model_name="news",
name="published",
field=models.DateTimeField(verbose_name="Published at"),
),
migrations.AlterField(
model_name="news",
name="source",
field=models.CharField(blank=True, default="", max_length=30, null=True, verbose_name="Source"),
),
migrations.AlterField(
model_name="news",
name="title",
field=models.CharField(max_length=200, verbose_name="Title"),
),
migrations.AlterField(
model_name="news",
name="updated_at",
field=models.DateTimeField(auto_now=True, verbose_name="Updated at"),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@


class Migration(migrations.Migration):

dependencies = [
('core', '0002_alter_news_created_at_alter_news_link_and_more'),
("core", "0002_alter_news_created_at_alter_news_link_and_more"),
]

operations = [
migrations.AlterModelOptions(
name='news',
options={'verbose_name': 'News', 'verbose_name_plural': 'News'},
name="news",
options={"verbose_name": "News", "verbose_name_plural": "News"},
),
]
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion core/tasks.py → app/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import requests
from bs4 import BeautifulSoup
from celery import shared_task

from core.models import News


Expand Down
3 changes: 1 addition & 2 deletions core/urls.py → app/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.urls import path

from core.views import HomePageView
from django.urls import path

app_name = "core"

Expand Down
File renamed without changes.
File renamed without changes.
Empty file added app/scraping/__init__.py
Empty file.
File renamed without changes.
7 changes: 3 additions & 4 deletions scraping/celery.py → app/scraping/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
from celery.schedules import crontab
from django.conf import settings


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "scraping.settings")
app = Celery("scraping", broker=settings.CELERY_BROKER_URL)
app.conf.timezone = "UTC"
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()

app.conf.beat_schedule = {
'add-every-monday-morning': {
'task': 'hackernews_rss',
'schedule': crontab(minute=0, hour=0),
"add-every-monday-morning": {
"task": "hackernews_rss",
"schedule": crontab(minute="0", hour="0"),
},
}
5 changes: 2 additions & 3 deletions scraping/settings.py → app/scraping/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
environ.Env.read_env(os.path.join(BASE_DIR, ".env"))

SECRET_KEY = env("SECRET_KEY")

DEBUG = env("DEBUG")

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["*"]


INSTALLED_APPS = [
Expand All @@ -24,7 +24,6 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",

"core",
]

Expand Down
1 change: 0 additions & 1 deletion scraping/urls.py → app/scraping/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib import admin
from django.urls import include, path


urlpatterns = [
path("", include("core.urls", namespace="core")),
path("admin/", admin.site.urls),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions configs/.black.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 120
double-quote = true
7 changes: 7 additions & 0 deletions configs/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
count = true
max-line-length = 120
max-complexity = 30
exclude = .git, __pycache__, .idea/
select = F,W,E,C,N,B,A,S,T,H,JS,CCR,SIM,PEA,NU,D200,D201,D202,D209,D210
ignore = W503,B011,SIM102,SIM106,SIM111,SIM118,I,JS101,JS102,C408,T002,T003,E203,E501
9 changes: 9 additions & 0 deletions configs/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[settings]
line_length = 120
profile = black
py_version = 310
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
5 changes: 5 additions & 0 deletions configs/.mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[mypy]
ignore_missing_imports = True
strict_optional = True
warn_unused_ignores = True
disable_error_code = union-attr, import, var-annotated
42 changes: 42 additions & 0 deletions configs/.ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Exclude a variety of commonly ignored directories and comments.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = ["E", "F"]


# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F"]
unfixable = []

per-file-ignores = {}

# Same as Black.
line-length = 120

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.10.
target-version = "py311"

This file was deleted.

Binary file removed core/migrations/__pycache__/0001_initial.cpython-39.pyc
Binary file not shown.
Binary file removed core/migrations/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ services:
app:
container_name: app
build: .
command: >
sh -c "python app/manage.py migrate && gunicorn -c /code/gunicorn/conf.py --bind :8000 --chdir /code/app scraping.wsgi:application"
ports:
- 8000:8000
working_dir: /code
Expand Down Expand Up @@ -30,7 +32,7 @@ services:
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf:/etc/nginx/conf.d
- ./static:/static
- ./app/static:/static
ports:
- 80:80
depends_on:
Expand Down
32 changes: 32 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import nox
from dotenv import load_dotenv


@nox.session
def format(session: nox.Session) -> None:
session.install("ufmt", "black", "isort")
session.run("ufmt", "format", "app")
session.run("black", "--config=configs/.black.toml", "app")
session.run(
"isort",
"--sp=configs/.isort.cfg",
"app",
)


@nox.session
def lint(session: nox.Session) -> None:
session.install("ruff", "flake8", "mypy")
session.run(
"ruff",
"check",
"--config=configs/.ruff.toml",
"--fix",
"app",
)
session.run("flake8", "--config=configs/.flake8", "app")
session.run(
"mypy",
"--config-file=configs/.mypy.ini",
"app"
)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ beautifulsoup4
Django
django_environ
gunicorn
requests
celery
requests
psycopg2-binary

0 comments on commit 8f946f7

Please sign in to comment.