Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: restructure app #2573

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 19 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -12,11 +14,12 @@ jobs:
POSTGRES_DB: pythonorg
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Install platform dependencies
run: |
sudo apt -y update
Expand All @@ -25,38 +28,49 @@ jobs:
texlive-latex-recommended \
texlive-plain-generic \
lmodern

- name: Install pandoc
run: |
wget https://github.com/jgm/pandoc/releases/download/2.17.1.1/pandoc-2.17.1.1-1-amd64.deb
sudo dpkg -i pandoc-2.17.1.1-1-amd64.deb

- uses: actions/setup-python@v5
with:
python-version-file: '.python-version'

- name: Cache Python dependencies
uses: actions/cache@v4
env:
cache-name: pythondotorg-cache-pip
with:
path: ~/.cache/pip
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('requirements.txt', '*-requirements.txt') }}
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('requirements/requirements.txt', 'requirements/*-requirements.txt') }}
restore-keys: |
${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-
${{ runner.os }}-${{ github.job }}-
${{ runner.os }}-

- name: Install Python dependencies
run: |
pip install -U pip setuptools wheel
pip install -r dev-requirements.txt
pip install -r requirements/dev-requirements.txt

- name: Check for ungenerated database migrations
run: |
python manage.py makemigrations --check --dry-run
export PYTHONPATH=$PYTHONPATH:${{ github.workspace }}/app
cd ${{ github.workspace }}/app
DJANGO_SETTINGS_MODULE=app.pydotorg.settings.dev python manage.py makemigrations --check --dry-run
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/pythonorg

- name: Run Tests
run: |
python -Wd -m coverage run manage.py test -v2
export PYTHONPATH=$PYTHONPATH:${{ github.workspace }}/app
cd ${{ github.workspace }}/app
DJANGO_SETTINGS_MODULE=app.pydotorg.settings.dev python -Wd -m coverage run manage.py test -v2
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/pythonorg

- name: Coverage
run: |
coverage report -m --fail-under=75
15 changes: 11 additions & 4 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
name: Check collectstatic

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version-file: '.python-version'

- name: Cache Python dependencies
uses: actions/cache@v4
env:
cache-name: pythondotorg-cache-pip
with:
path: ~/.cache/pip
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('requirements.txt', '*-requirements.txt') }}
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('requirements/requirements.txt', 'requirements/*-requirements.txt') }}
restore-keys: |
${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-
${{ runner.os }}-${{ github.job }}-
${{ runner.os }}-

- name: Install Python dependencies
run: |
pip install -U pip setuptools wheel
pip install -r requirements.txt -r prod-requirements.txt
- name: Run Tests
pip install -r requirements/requirements.txt -r requirements/prod-requirements.txt

- name: Run collectstatic
run: |
DJANGO_SETTINGS_MODULE=pydotorg.settings.static python manage.py collectstatic --noinput
export PYTHONPATH=$PYTHONPATH:${{ github.workspace }}
DJANGO_SETTINGS_MODULE=app.pydotorg.settings.static python app/manage.py collectstatic --noinput
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

.sass-cache/
docs/build
media/*
app/media/*
static-root/
static/stylesheets/mq.css
static/stylesheets/no-mq.css
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ build:
python: "3"

commands:
- python -m pip install -r docs-requirements.txt
- python -m pip install -r requirements/docs-requirements.txt
- make -C docs html JOBS=$(nproc) BUILDDIR=_readthedocs
- mv docs/_readthedocs _readthedocs
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ RUN case $(uname -m) in \
RUN mkdir /code
WORKDIR /code

COPY dev-requirements.txt /code/
COPY base-requirements.txt /code/
COPY prod-requirements.txt /code/
COPY requirements.txt /code/
COPY requirements/dev-requirements.txt /code/
COPY requirements/base-requirements.txt /code/
COPY requirements/prod-requirements.txt /code/
COPY requirements/requirements.txt /code/

RUN pip --no-cache-dir --disable-pip-version-check install --upgrade pip setuptools wheel

Expand Down
10 changes: 5 additions & 5 deletions Dockerfile.cabotage
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ RUN case $(uname -m) in \
RUN mkdir /code
WORKDIR /code

COPY dev-requirements.txt /code/
COPY base-requirements.txt /code/
COPY prod-requirements.txt /code/
COPY requirements.txt /code/
COPY requirements/dev-requirements.txt /code/
COPY requirements/base-requirements.txt /code/
COPY requirements/prod-requirements.txt /code/
COPY requirements/requirements.txt /code/

RUN pip --no-cache-dir --disable-pip-version-check install --upgrade pip setuptools wheel

Expand All @@ -46,4 +46,4 @@ RUN --mount=type=cache,target=/root/.cache/pip \
install \
-r requirements.txt -r prod-requirements.txt
COPY . /code/
RUN DJANGO_SETTINGS_MODULE=pydotorg.settings.static python manage.py collectstatic --noinput
RUN DJANGO_SETTINGS_MODULE=app.pydotorg.settings.static python app/manage.py collectstatic --noinput
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ default:
@echo
@exit 1

.state/docker-build-web: Dockerfile dev-requirements.txt base-requirements.txt
.state/docker-build-web: Dockerfile requirements/dev-requirements.txt requirements/base-requirements.txt
# Build web container for this project
docker compose build --force-rm web

Expand All @@ -24,7 +24,7 @@ default:

.state/db-initialized: .state/docker-build-web .state/db-migrated
# Load all fixtures
docker compose run --rm web ./manage.py loaddata fixtures/*.json
docker compose run --rm web ./app/manage.py loaddata fixtures/*.json

# Mark the state so we don't rebuild this needlessly.
mkdir -p .state && touch .state/db-initialized
Expand All @@ -34,25 +34,25 @@ serve: .state/db-initialized

migrations: .state/db-initialized
# Run Django makemigrations
docker compose run --rm web ./manage.py makemigrations
docker compose run --rm web ./app/manage.py makemigrations

migrate: .state/docker-build-web
# Run Django migrate
docker compose run --rm web ./manage.py migrate
docker compose run --rm web ./app/manage.py migrate

manage: .state/db-initialized
# Run Django manage to accept arbitrary arguments
docker compose run --rm web ./manage.py $(filter-out $@,$(MAKECMDGOALS))
docker compose run --rm web ./app/manage.py $(filter-out $@,$(MAKECMDGOALS))

shell: .state/db-initialized
docker compose run --rm web ./manage.py shell
docker compose run --rm web ./app/manage.py shell

clean:
docker compose down -v
rm -f .state/docker-build-web .state/db-initialized .state/db-migrated

test: .state/db-initialized
docker compose run --rm web ./manage.py test
docker compose run --rm web ./app/manage.py test

docker_shell: .state/db-initialized
docker compose run --rm web /bin/bash
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
release: python manage.py migrate --noinput
release: python app/manage.py migrate --noinput
web: bin/start-nginx gunicorn -c gunicorn.conf pydotorg.wsgi
worker: celery -A pydotorg worker -l INFO
worker: celery -A app.pydotorg worker -l INFO
worker-beat: celery -A pydotorg beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion banners/admin.py → app/banners/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from banners.models import Banner
from app.banners.models import Banner


@admin.register(Banner)
Expand Down
2 changes: 1 addition & 1 deletion banners/apps.py → app/banners/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class BannersAppConfig(AppConfig):

name = 'banners'
name = 'app.banners'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import template
from django.template.loader import render_to_string

from banners.models import Banner
from app.banners.models import Banner

register = template.Library()

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion blogs/admin.py → app/blogs/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from django.core.management import call_command

from .models import BlogEntry, Feed, FeedAggregate
from app.blogs.models import BlogEntry, Feed, FeedAggregate


@admin.register(BlogEntry)
Expand Down
2 changes: 1 addition & 1 deletion blogs/apps.py → app/blogs/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class BlogsAppConfig(AppConfig):

name = 'blogs'
name = 'app.blogs'
2 changes: 1 addition & 1 deletion blogs/factories.py → app/blogs/factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings

from .models import Feed
from app.blogs.models import Feed


def initial_data():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.core.management.base import BaseCommand
from django.utils.timezone import now

from ...models import BlogEntry, RelatedBlog, Feed
from ...parser import get_all_entries, update_blog_supernav
from app.blogs..models import BlogEntry, RelatedBlog, Feed
from app.blogs..parser import get_all_entries, update_blog_supernav


class Command(BaseCommand):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion blogs/models.py → app/blogs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.db import models

from cms.models import ContentManageable
from app.cms.models import ContentManageable


def tag_visible(element):
Expand Down
4 changes: 2 additions & 2 deletions blogs/parser.py → app/blogs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from django.template.loader import render_to_string
from django.utils.timezone import make_aware

from boxes.models import Box
from .models import BlogEntry, Feed
from app.boxes.models import Box
from app.blogs.models import BlogEntry, Feed


def get_all_entries(feed_url):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import template

from ..models import BlogEntry
from app.blogs.models import BlogEntry

register = template.Library()

Expand Down
File renamed without changes.
Loading
Loading