Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hugorodgerbrown authored Nov 21, 2023
0 parents commit cf26706
Show file tree
Hide file tree
Showing 35 changed files with 1,518 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
branch = True
omit = tests/*
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yaml]
indent_size = 2
97 changes: 97 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Python / Django

on:
push:
branches:
- master

pull_request:
types: [opened, synchronize, reopened]

jobs:
format:
name: Check formatting
runs-on: ubuntu-latest
strategy:
matrix:
toxenv: [fmt, lint, mypy]
env:
TOXENV: ${{ matrix.toxenv }}

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

- name: Set up Python (3.11)
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install and run tox
run: |
pip install tox
tox
checks:
name: Run Django checks
runs-on: ubuntu-latest
strategy:
matrix:
toxenv: ["django-checks"]
env:
TOXENV: ${{ matrix.toxenv }}

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

- name: Set up Python (3.11)
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install and run tox
run: |
pip install tox
tox
test:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# build LTS version, next version, HEAD
django: ["32", "42", "50", "main"]
exclude:
- python: "3.8"
django: "50"
- python: "3.8"
django: "main"
- python: "3.9"
django: "50"
- python: "3.9"
django: "main"
- python: "3.10"
django: "main"
- python: "3.11"
django: "32"
- python: "3.12"
django: "32"

env:
TOXENV: django${{ matrix.django }}-py${{ matrix.python }}

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

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Install and run tox
run: |
pip install tox
tox
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.pyc
*.egg-info
*.bak
*.db
.coverage
.tox
.venv
node_modules
poetry.lock
test.db
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
# python code formatting - will amend files
- repo: https://github.com/ambv/black
rev: 23.10.1
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.1.5"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

# python static type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
hooks:
- id: mypy
args:
- --disallow-untyped-defs
- --disallow-incomplete-defs
- --check-untyped-defs
- --no-implicit-optional
- --ignore-missing-imports
- --follow-imports=silent
20 changes: 20 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"proseWrap": "always",
"endOfLine": "auto",
"overrides": [
{
"files": ["*.yml", "*.yaml"],
"options": {
"tabWidth": 2
}
}
]
}
66 changes: 66 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
line-length = 88
ignore = [
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D106", # Missing docstring in public nested class
"D107", # Missing docstring in __init__
"D203", # 1 blank line required before class docstring
"D212", # Multi-line docstring summary should start at the first line
"D213", # Multi-line docstring summary should start at the second line
"D404", # First word of the docstring should not be "This"
"D405", # Section name should be properly capitalized
"D406", # Section name should end with a newline
"D407", # Missing dashed underline after section
"D410", # Missing blank line after section
"D411", # Missing blank line before section
"D412", # No blank lines allowed between a section header and its content
"D416", # Section name should end with a colon
"D417",
"D417", # Missing argument description in the docstring
]
select = [
"A", # flake8 builtins
"C9", # mcabe
"D", # pydocstyle
"E", # pycodestyle (errors)
"F", # Pyflakes
"I", # isort
"S", # flake8-bandit
"T2", # flake8-print
"W", # pycodestype (warnings)
]

[isort]
combine-as-imports = true

[mccabe]
max-complexity = 8

[per-file-ignores]
"*tests/*" = [
"D205", # 1 blank line required between summary line and description
"D400", # First line should end with a period
"D401", # First line should be in imperative mood
"D415", # First line should end with a period, question mark, or exclamation point
"E501", # Line too long
"E731", # Do not assign a lambda expression, use a def
"S101", # Use of assert detected
"S105", # Possible hardcoded password
"S106", # Possible hardcoded password
"S113", # Probable use of requests call with timeout set to {value}
]
"*/migrations/*" = [
"E501", # Line too long
]
"*/settings.py" = [
"F403", # from {name} import * used; unable to detect undefined names
"F405", # {name} may be undefined, or defined from star imports:
]
"*/settings/*" = [
"F403", # from {name} import * used; unable to detect undefined names
"F405", # {name} may be undefined, or defined from star imports:
]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 yunojuno

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: ./heroku/release
web: gunicorn heroku.wsgi:application --bind=0.0.0.0:$PORT
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Poetry Template

Django app template, using `poetry-python` as dependency manager.

This project is a template that can be cloned and re-used for redistributable apps.

It includes the following:

- `poetry` for dependency management
- `ruff`, `black` for linting / format
- `pre-commit` to run linting
- `mypy` for type checking
- `tox` and Github Actions for builds and CI

There are default config files for the linting and mypy.

## Principles

The motivation for this project is to provide a consistent set of standards across all YunoJuno
public Python/Django projects. The principles we want to encourage are:

- Simple for developers to get up-and-running
- Consistent style (`black`, `ruff`)
- Full type hinting (`mypy`)

## Versioning

We currently support Python 3.7+, and Django 3.2+. We will aggressively upgrade Django versions, and
we won't introduce hacks to support breaking changes - if Django 4 introduces something that 2.2
doesn't support we'll drop it.

## Tests

#### Tests package

The package tests themselves are _outside_ of the main library code, in a package that is itself a
Django app (it contains `models`, `settings`, and any other artifacts required to run the tests
(e.g. `urls`).) Where appropriate, this test app may be runnable as a Django project - so that
developers can spin up the test app and see what admin screens look like, test migrations, etc.

#### Running tests

The tests themselves use `pytest` as the test runner. If you have installed the `poetry` evironment,
you can run them thus:

```
$ poetry run pytest
```

or

```
$ poetry shell
(my_app) $ pytest
```

The full suite is controlled by `tox`, which contains a set of environments that will format, lint,
and test against all support Python + Django version combinations.

```
$ tox
...
______________________ summary __________________________
fmt: commands succeeded
lint: commands succeeded
mypy: commands succeeded
py37-django22: commands succeeded
py37-django32: commands succeeded
py37-djangomain: commands succeeded
py38-django22: commands succeeded
py38-django32: commands succeeded
py38-djangomain: commands succeeded
py39-django22: commands succeeded
py39-django32: commands succeeded
py39-djangomain: commands succeeded
```

#### CI

There is a `.github/workflows/tox.yml` file that can be used as a baseline to run all of the tests
on Github. This file runs the oldest (2.2), newest (3.2), and head of the main Django branch.
37 changes: 37 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "Heroku + Poetry + Django",
"description": "An empty Django app to test Heroku deployment issues.",
"repository": "https://github.com/yunojuno/poetry-template-heroku",
"scripts": {
"postdeploy": "python manage.py migrate"
},
"env": {
"DJANGO_SETTINGS_MODULE": {
"description": "Location of the settings (fixed)",
"value": "heroku.settings",
"required": true
},
"DJANGO_SECRET_KEY": {
"generator": "secret"
},
"POETRY_EXPORT_PARAMS": {
"description": "Used by Poetry buildpack (fixed)",
"value": "--with heroku",
"required": true
}
},
"addons": [
{
"plan": "heroku-postgresql:hobby-dev",
"as": "DATABASE"
}
],
"buildpacks": [
{
"url": "https://github.com/yunojuno/python-poetry-buildpack.git"
},
{
"url": "https://github.com/heroku/heroku-buildpack-python"
}
]
}
Empty file added demo/__init__.py
Empty file.
Loading

0 comments on commit cf26706

Please sign in to comment.