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

rebuild project structure from scratch / move to poetry #567

Merged
merged 117 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 116 commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
3693f35
post gen project sh done
hnthh Nov 27, 2023
c97c10d
lots of
hnthh Nov 28, 2023
ad7537c
remove staged `~`-files
hnthh Nov 28, 2023
13ff22d
lots of
hnthh Nov 28, 2023
4a0ffbf
simplify
hnthh Nov 29, 2023
c17676c
do not compile messages for tests
hnthh Nov 29, 2023
bec4e7d
refactor makefile, add xdist
hnthh Nov 29, 2023
bb07cd4
return/apply black, isort
hnthh Nov 29, 2023
2b8dc43
refactor pyproject
hnthh Nov 29, 2023
8d26610
lots of
hnthh Nov 30, 2023
b272a47
fix gitignore
hnthh Nov 30, 2023
2872826
fix copy without render list
hnthh Nov 30, 2023
f78cb87
parent project ci
hnthh Dec 1, 2023
f4e0b5f
run circleci
hnthh Dec 3, 2023
208c0c8
fix indentation
hnthh Dec 3, 2023
b91afff
ya ci fix
hnthh Dec 3, 2023
c0cb074
ya ci fix
hnthh Dec 3, 2023
8f68153
ya ci fix
hnthh Dec 3, 2023
108bc9a
ya ci fix
hnthh Dec 3, 2023
4d4b65b
ya ci fix
hnthh Dec 3, 2023
5115443
ya ci fix
hnthh Dec 3, 2023
7823e99
fix dockerfile
hnthh Dec 3, 2023
5a485b5
rewrite child project ci
hnthh Dec 3, 2023
1ec2820
add pymarkdownlnt, fix child proj readme
hnthh Dec 3, 2023
6c85aaa
add pymarkdownlnt to parent proj, fix parent readme
hnthh Dec 3, 2023
f15ef0d
circle config fix indentation
hnthh Dec 3, 2023
eca84d8
fix config
hnthh Dec 3, 2023
30a9b60
circle config fix indentation
hnthh Dec 3, 2023
d66af0e
remove migrations file from app template
hnthh Dec 3, 2023
26b001d
use cookiecutter variables in child pyproject
hnthh Dec 4, 2023
95fd044
remove circleci dir
hnthh Dec 5, 2023
3aef0d1
add github actions ci
hnthh Dec 5, 2023
4cf8276
add runs-on property
hnthh Dec 5, 2023
f23a85d
move actions dir
hnthh Dec 5, 2023
37fa2d0
use single quotes
hnthh Dec 5, 2023
3d71abc
fix syntax
hnthh Dec 5, 2023
35387db
cleanup `.gitignore`
hnthh Dec 5, 2023
9bc50d1
fix app tamplate
hnthh Dec 5, 2023
425bb82
add whitespaces to project template folder name
hnthh Dec 5, 2023
927715d
bump child proj ci postgres, redis versions
hnthh Dec 5, 2023
991f539
fix template proj name in dependabot ci
hnthh Dec 5, 2023
3a6902b
test child project ci run from parent ci
hnthh Dec 5, 2023
1548fa7
child ci
hnthh Dec 5, 2023
1c4ab38
child ci
hnthh Dec 5, 2023
3886c0f
child ci
hnthh Dec 5, 2023
f7d39de
child ci
hnthh Dec 5, 2023
fc8af5c
child ci
hnthh Dec 5, 2023
7a1d920
child ci
hnthh Dec 5, 2023
1603f88
child ci
hnthh Dec 5, 2023
4751ec4
child ci
hnthh Dec 5, 2023
14d2ecb
child ci
hnthh Dec 5, 2023
4007f87
child ci
hnthh Dec 5, 2023
c8b2e72
child ci
hnthh Dec 5, 2023
44815e0
child ci
hnthh Dec 5, 2023
1ac030f
remove child ci
hnthh Dec 5, 2023
0a13a34
uppercase numprocesses env
hnthh Dec 25, 2023
456faf0
drop makefile `mr` cmd
hnthh Dec 25, 2023
43715fe
remove `asgi.py`
hnthh Dec 25, 2023
611893d
`DEFAULT_FILE_STORAGE` → `FILE_STORAGE`
hnthh Dec 25, 2023
b8ef843
merge branch 'master' into poetry
hnthh Dec 25, 2023
5fd6967
fix imports in merged files
hnthh Dec 25, 2023
1d0a7b8
remove poetry caching from parent proj ci
hnthh Dec 25, 2023
7f2bece
add before push instructions to readme
hnthh Dec 25, 2023
c5784c0
rename makefile `checks` cmd
hnthh Dec 27, 2023
263f09d
fix links in readmes
hnthh Dec 27, 2023
02b1553
remove optional next steps from readme
hnthh Dec 27, 2023
b61fc65
remove random ascii string error FAQ from readme
hnthh Dec 27, 2023
1f78d6b
bump uwsgi ver
hnthh Dec 27, 2023
dcdb5cb
remove checks cmd from parent proj and cis
hnthh Dec 27, 2023
54b40e5
remove depends on check job from parent ci
hnthh Dec 27, 2023
598222e
remove build from `.gitignore`
hnthh Dec 27, 2023
66f069e
add docker image build ci job
hnthh Dec 27, 2023
0bf844f
add qemu, buildx setup steps
hnthh Dec 27, 2023
c0666f2
update .gitignore
hnthh Dec 27, 2023
9ce90c4
make bootstrap cmd works locally with postgres
hnthh Dec 28, 2023
c8a0b1c
fix readmes
hnthh Dec 28, 2023
c79ebab
add postgres to parent ci except lint
hnthh Dec 28, 2023
b4e5d2c
remove services from parent ci
hnthh Dec 28, 2023
65d19b1
make numprocesses auto
hnthh Dec 28, 2023
9db3d01
rename numprocesses env
hnthh Dec 28, 2023
2a92a49
rename makefile build cmd
hnthh Dec 28, 2023
0a3f2bf
add build docker image job to child ci and down cmd to pre-hook
hnthh Dec 28, 2023
25b9870
remove `core` from installed apps
hnthh Jan 10, 2024
9100835
back to prev project architecture
hnthh Jan 11, 2024
5122cfd
add if cond to child github ci push
hnthh Jan 11, 2024
2652407
remove old users migration, create new one in post gen hook
hnthh Jan 11, 2024
c47b912
change numprocesses to 4, add random ascii string generation to env
hnthh Jan 11, 2024
e73a783
remove db.sqlite from gitignore
hnthh Jan 11, 2024
fc3fc73
change core to app in app template
hnthh Jan 11, 2024
49072e6
replace factories, fixtures from tests dir to app
hnthh Jan 11, 2024
3da188a
fix child ci syntax
hnthh Jan 11, 2024
a0ceb84
back to push: false in child ci
hnthh Jan 11, 2024
e490dcc
upgrade cache ci action
hnthh Mar 15, 2024
e94d2cf
remove unused dockerfile var
hnthh Mar 15, 2024
1ac0529
try to fix gh inline quotes parser
hnthh Mar 15, 2024
1968fe4
add all to admin, models
hnthh Mar 15, 2024
c1b8f19
rm `makemessages` from dockerfile, replace pip upgrade cmd
hnthh Mar 16, 2024
51c3839
return `makemessages`, upgrade `uwsgi`
hnthh Mar 16, 2024
8e60cd3
add comment to ci docker image push
hnthh Mar 16, 2024
6617ecb
hash `poetry.lock` instead of `pyproject.toml` in ci
hnthh Mar 16, 2024
53b8069
add locale dir with gitkeep
hnthh Mar 16, 2024
0b0af16
rm `makemessages`
hnthh Mar 16, 2024
e65bf1e
add remove-prev-geterated-project-if-exists makefile cmd
hnthh Mar 16, 2024
32b4141
add empty last blank line to tpl file
hnthh Mar 16, 2024
ac4fb76
remove space in .env.ci
hnthh Mar 16, 2024
b314131
upgrade setup-python action to v5
hnthh Mar 16, 2024
499eb3b
upgrade checkout action to v4
hnthh Mar 17, 2024
215a5b9
upgrade setup-qemu-action to v3
hnthh Mar 17, 2024
2c91acb
upgrade setup-buildx-action to v3
hnthh Mar 17, 2024
a25efc5
upgrade build-push-action to v5
hnthh Mar 17, 2024
b4ae7ad
generate dockerfile maintainer label dynamically
hnthh Mar 17, 2024
3e90953
squashed commit
hnthh Mar 17, 2024
6a56b1e
remove docker from makefile
hnthh Apr 12, 2024
56ecce1
add fmt to makefile
hnthh Apr 12, 2024
c7e98f0
add postgres to parent ci
hnthh Apr 12, 2024
c6983f4
add postgres to build-docker-image job too
hnthh Apr 12, 2024
a2dbdfc
squashed commit
hnthh Apr 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 0 additions & 78 deletions .circleci/config.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: build

runs:
using: composite

steps:
- name: install poetry
uses: snok/install-poetry@v1
with:
version: 1.8.2

- name: install python
id: setup-python
uses: actions/setup-python@v5
with:
cache: poetry
python-version-file: pyproject.toml

- name: make sure poetry lockfile is up to date
run: poetry check --lock
shell: bash

- name: save python version to the env
run: echo "python-version=${{ steps.setup-python.outputs.python-version }}" >> $GITHUB_ENV
shell: bash

- name: install deps
if: steps.setup-python.outputs.cache-hit != true
run: poetry install --no-interaction --no-root
shell: bash
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/{{cookiecutter.project_slug}}"
directory: "/{{ cookiecutter.name }}"
schedule:
interval: daily
time: "02:00"
Expand Down
97 changes: 83 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,93 @@
---
name: CI
on: push

on:
push:
branches:
- master
pull_request:

jobs:
build:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: checkout
uses: actions/checkout@v4

- name: Install gettext for correct manage.py compilemessages
run: sudo apt-get update && sudo apt-get --no-install-recommends install -y locales-all gettext
- name: build
uses: ./.github/actions/build

- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: lint
run: make lint

bootstrap:
needs: lint
runs-on: ubuntu-latest
services:
postgres:
env:
POSTGRES_PASSWORD: secret
image: postgres:16.2-alpine
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-retries 5
--health-timeout 5s
ports:
- 5432:5432

steps:
- name: checkout
uses: actions/checkout@v4

- name: build
uses: ./.github/actions/build

- name: bootstrap
run: make bootstrap
env:
DATABASE_URL: postgres://postgres:secret@localhost:5432/postgres

- name: Install cookiecutter
run: pip install cookiecutter
build-docker-image:
needs: bootstrap
runs-on: ubuntu-latest
services:
postgres:
env:
POSTGRES_PASSWORD: secret
image: postgres:16.2-alpine
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-retries 5
--health-timeout 5s
ports:
- 5432:5432

steps:
- name: checkout
uses: actions/checkout@v4

- name: build
uses: ./.github/actions/build

- name: Bootstrap the project
run: make test
- name: bootstrap
run: make bootstrap
env:
DATABASE_URL: postgres://postgres:secret@localhost:5432/postgres

- name: setup qemu
uses: docker/setup-qemu-action@v2

- name: setup buildx
uses: docker/setup-buildx-action@v3

- name: make sure docker image is buildable
uses: docker/build-push-action@v5
with:
build-args: |
PYTHON_VERSION=${{ env.python-version }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: testproject
push: false
f213 marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
venv
testproject
.vscode
.git
.idea
.venv
.vscode

**/.DS_Store

{{ cookiecutter.name }}/poetry.lock

testproject
19 changes: 8 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
VENV=cd testproject/django/src && ../venv/bin/python
bootstrap:
rm -rf testproject

test: bootstrap
$(VENV) ./manage.py makemigrations --check
$(VENV) ./manage.py startapp test_app
poetry run cookiecutter --no-input ./

bootstrap:
rm -Rf testproject
mkdir -p testproject
cd testproject && cookiecutter --no-input ../
fmt:
poetry run toml-sort pyproject.toml

coverage:
$(VENV) -m pip install pytest-cov
$(VENV) -m pytest --cov-report=xml --cov=app --cov=users --cov=a12n --cov=sepulkas
lint:
poetry run toml-sort pyproject.toml --check
poetry run pymarkdown scan README.md
48 changes: 19 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
# My personal (very) opinionated django template
# fands.dev django template

![Shields.io](https://img.shields.io/github/last-commit/fandsdev/django?style=flat-square) [![Maintainability](https://api.codeclimate.com/v1/badges/2b9800b10414a4ad2622/maintainability)](https://codeclimate.com/github/f213/django/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/2b9800b10414a4ad2622/test_coverage)](https://codeclimate.com/github/f213/django/test_coverage)
![Shields.io](https://img.shields.io/github/last-commit/fandsdev/django?style=flat-square)

![Easy peasy](https://user-images.githubusercontent.com/1592663/79918184-93bca100-8434-11ea-9902-0ff726a864a3.gif)


## What is in the box

* API-only django (checkout [this post](https://t.me/pmdaily/257) in Russian) based on Django REST Framework with JWT support
* [pip-tools](https://github.com/jazzband/pip-tools) with separate development-time dependencies
* Strict type checking with mypy, [django-stubs](https://github.com/typeddjango/django-stubs) and [djangorestframework-stubs](https://github.com/typeddjango/djangorestframework-stubs)
* flake8 with ton of plugins (contact me if you know more)
* [black](https://github.com/psf/black) as uncompromising code formatter
* Starter CI configuration on GitHub Actions
* pytest with useful stuff like freezegun, pytest-mock and super convinient [DRF test client](https://github.com/f213/django/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/src/app/tests/tests_health.py#L9)
* Custom [user model](https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#specifying-a-custom-user-model)
* [drf-spectacular](https://github.com/tfranzel/drf-spectacular) for API Schema generation
* [django-axes](https://github.com/jazzband/django-axes) for additional security
* [Whitenoise](http://whitenoise.evans.io) for effortless static files hosting
* cloudflare-ready with [django-ipware](https://github.com/un33k/django-ipware)
* API-only django (checkout [this post](https://t.me/pmdaily/257) in Russian) based on Django REST Framework with JWT support.
* [poetry](https://python-poetry.org) with separate development-time dependencies.
* Strict type checking with mypy, [django-stubs](https://github.com/typeddjango/django-stubs) and [djangorestframework-stubs](https://github.com/typeddjango/djangorestframework-stubs).
* tons of linters and formatters (contact me if something interesting not included, see `Makefile` `fmt`, `lint` commands).
* Starter CI configuration on GitHub Actions.
* `pytest` with useful stuff like `freezegun`, `pytest-mock` and super convinient [DRF test client](https://github.com/fandsdev/django/blob/master/%7B%7Bcookiecutter.name%7D%7D/src/app/tests_health.py#L9)
* Custom [user model](https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#specifying-a-custom-user-model).
* [drf-spectacular](https://github.com/tfranzel/drf-spectacular) for API Schema generation.
* [django-axes](https://github.com/jazzband/django-axes) for additional security.
* [Whitenoise](http://whitenoise.evans.io) for effortless static files hosting.
* cloudflare-ready with [django-ipware](https://github.com/un33k/django-ipware).
* Sentry. Set `SENTRY_DSN` env var if you need it.
* Postgres ready. Set `DATABASE_URL` env var to something like `DATABASE_URL=postgres://postgres@localhost:5432/postgres`

* Postgres.

## Optional next steps
You definetely should consider this steps after installation:
* Install [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) if you plan to grow beyond 500 unittests
* If you are into docker, check out this [docker-compose.yml](https://github.com/f213/django/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/docker-compose.yml) to run on your machine
## Installation

First, make sure you have `PostgreSQL` up and running (check the `{{ cookiecutter.name }}/src/app/.env.ci` `DATABASE_URL` and `{{ cookiecutter.name }}/docker-compose.yml` for configuration). After that:

## Installation
```bash
poetry install

```
$ pip install --upgrade cookiecutter
$ cookiecutter gh:fandsdev/django
poetry run cookiecutter gh:fandsdev/django
```

## FAQ

### I have got an error «'random_ascii_string' is undefined»

You should upgrade cookiecutter to the latest version: `pip install --upgrade cookiecutter`

### I wanna hack this!

Thank you so much! Check out our [build pipeline](https://github.com/fandsdev/django/blob/master/Makefile) and pick any free [issue](https://github.com/fandsdev/django/issues).
12 changes: 7 additions & 5 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"project_slug": "django",
"email": "",
"project_version": "0.0.0-dev",
"author": "Fedor Borshev",
"description": "",
"email": "[email protected]",
"name": "testproject",
"_copy_without_render": [
"*.py-tpl",
".github/workflows/ci.yml"
".github/actions/build/action.yml",
".github/workflows/ci.yml",
"src/.django-app-template"
]
}
hnthh marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 8 additions & 26 deletions hooks/post_gen_project.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
#!/bin/bash -e

echo -ne "Running with "
cp src/app/.env.ci src/app/.env

python --version
poetry install

echo Creating and populating virtualenv..
poetry run python src/manage.py collectstatic
poetry run python src/manage.py startapp some_app
poetry run python src/manage.py makemigrations -n "initial"

python -m venv venv
. venv/bin/activate
poetry run isort src/users/migrations/0001_initial.py
f213 marked this conversation as resolved.
Show resolved Hide resolved

pip install --upgrade pip pip-tools wheel
make
poetry run python src/manage.py migrate

cd src

echo Collecting static assets...
./manage.py collectstatic

echo Running initial migrations...
./manage.py migrate

cd ../
echo Apply formatting..
make fmt

echo Running flake8..
make lint

echo Running pytest...
make test

echo Done
make fmt lint test
Loading
Loading