Skip to content

Commit

Permalink
[0.3.0] Release from last cookiecutter template
Browse files Browse the repository at this point in the history
  • Loading branch information
sveetch committed Aug 10, 2021
1 parent cb01a13 commit 19e3a03
Show file tree
Hide file tree
Showing 42 changed files with 1,615 additions and 51 deletions.
2 changes: 1 addition & 1 deletion LICENCE.txt
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020, David Thenon
Copyright (c) 2021, David Thenon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
119 changes: 98 additions & 21 deletions Makefile
@@ -1,14 +1,11 @@
PYTHON_INTERPRETER=python3
VENV_PATH=.venv

PYTHON_INTERPRETER=python3
PYTHON_BIN=$(VENV_PATH)/bin/python
PIP=$(VENV_PATH)/bin/pip
TWINE=$(VENV_PATH)/bin/twine
BOUSSOLE=$(VENV_PATH)/bin/boussole
DJANGO_MANAGE=$(VENV_PATH)/bin/python sandbox/manage.py
FLAKE=$(VENV_PATH)/bin/flake8
PYTEST=$(VENV_PATH)/bin/pytest
TWINE=$(VENV_PATH)/bin/twine
SPHINX_RELOAD=$(VENV_PATH)/bin/python sphinx_reload.py

DEMO_DJANGO_SECRET_KEY=samplesecretfordev
Expand All @@ -20,51 +17,69 @@ help:
@echo "Please use \`make <target>' where <target> is one of"
@echo
@echo " install -- to install this project with virtualenv and Pip"
@echo ""
@echo " freeze-dependencies -- to write a frozen.txt file with installed dependencies versions"
@echo
@echo " clean -- to clean EVERYTHING (Warning)"
@echo " clean-var -- to clean data (uploaded medias, database, etc..)"
@echo " clean-doc -- to remove documentation builds"
@echo " clean-install -- to clean Python side installation"
@echo " clean-pycache -- to remove all __pycache__, this is recursive from current directory"
@echo ""
@echo
@echo " run -- to run Django development server"
@echo " migrate -- to apply demo database migrations"
@echo " migrations -- to create new migrations for application after changes"
@echo " superuser -- to create a superuser for Django admin"
@echo ""
@echo
@echo " docs -- to build documentation"
@echo " livedocs -- to run livereload server to rebuild documentation on source changes"
@echo ""
@echo
@echo " flake -- to launch Flake8 checking"
@echo " tests -- to launch base test suite using Pytest"
@echo " test -- to launch base test suite using Pytest"
@echo " test-initial -- to launch tests with pytest and re-initialized database (for after new application or model changes)"
@echo " quality -- to launch Flake8 checking and every tests suites"
@echo ""
@echo
@echo " check-release -- to check package release before uploading it to PyPi"
@echo " release -- to release package for latest version on PyPi (once release has been pushed to repository)"
@echo

clean-pycache:
@echo ""
@echo "==== Clear Python cache ===="
@echo ""
rm -Rf .pytest_cache
find . -type d -name "__pycache__"|xargs rm -Rf
find . -name "*\.pyc"|xargs rm -f
.PHONY: clean-pycache

clean-install:
@echo ""
@echo "==== Clear installation ===="
@echo ""
rm -Rf $(VENV_PATH)
rm -Rf $(PACKAGE_SLUG).egg-info
.PHONY: clean-install

clean-var:
@echo ""
@echo "==== Clear var/ directory ===="
@echo ""
rm -Rf var
.PHONY: clean-var

clean-doc:
@echo ""
@echo "==== Clear documentation ===="
@echo ""
rm -Rf docs/_build
.PHONY: clean-doc

clean: clean-var clean-doc clean-install clean-pycache
.PHONY: clean

venv:
@echo ""
@echo "==== Install virtual environment ===="
@echo ""
virtualenv -p $(PYTHON_INTERPRETER) $(VENV_PATH)
# This is required for those ones using old distribution
$(PIP) install --upgrade pip
Expand All @@ -79,54 +94,116 @@ create-var-dirs:
@mkdir -p sandbox/static/css
.PHONY: create-var-dirs

install: venv create-var-dirs
@echo ""
@echo "==== Install everything for development ===="
@echo ""
$(PIP) install -e .[dev]
${MAKE} migrate
.PHONY: install

migrations:
@echo ""
@echo "==== Making application migrations ===="
@echo ""
@DJANGO_SECRET_KEY=$(DEMO_DJANGO_SECRET_KEY) \
$(DJANGO_MANAGE) makemigrations $(APPLICATION_NAME)
.PHONY: migrations

migrate:
@echo ""
@echo "==== Apply pending migrations ===="
@echo ""
@DJANGO_SECRET_KEY=$(DEMO_DJANGO_SECRET_KEY) \
$(DJANGO_MANAGE) migrate
.PHONY: migrate

superuser:
@echo ""
@echo "==== Create new superuser ===="
@echo ""
@DJANGO_SECRET_KEY=$(DEMO_DJANGO_SECRET_KEY) \
$(DJANGO_MANAGE) createsuperuser
.PHONY: superuser

install: venv create-var-dirs
$(PIP) install -e .[dev]
${MAKE} migrate
.PHONY: install

run:
@echo ""
@echo "==== Running development server ===="
@echo ""
@DJANGO_SECRET_KEY=$(DEMO_DJANGO_SECRET_KEY) \
$(DJANGO_MANAGE) runserver 0.0.0.0:8001
.PHONY: run

docs:
@echo ""
@echo "==== Build documentation ===="
@echo ""
cd docs && make html
.PHONY: docs

livedocs:
@echo ""
@echo "==== Watching documentation sources ===="
@echo ""
$(SPHINX_RELOAD)
.PHONY: livedocs

flake:
@echo ""
@echo "==== Flake ===="
@echo ""
$(FLAKE) --show-source $(APPLICATION_NAME)
$(FLAKE) --show-source tests
.PHONY: flake

tests:
$(PYTEST) -vv tests/
test:
@echo ""
@echo "==== Tests ===="
@echo ""
$(PYTEST) -vv --reuse-db tests/
rm -Rf var/media-tests/
.PHONY: tests
.PHONY: test

quality: tests flake
.PHONY: quality
test-initial:
@echo ""
@echo "==== Tests from zero ===="
@echo ""
$(PYTEST) -vv --reuse-db --create-db tests/
rm -Rf var/media-tests/
.PHONY: test-initial

freeze-dependencies:
@echo ""
@echo "==== Freeze dependencies versions ===="
@echo ""
$(VENV_PATH)/bin/python freezer.py
.PHONY: freeze-dependencies

release:
build-package:
@echo ""
@echo "==== Build package ===="
@echo ""
rm -Rf dist
$(VENV_PATH)/bin/python setup.py sdist
.PHONY: build-package

release: build-package
@echo ""
@echo "==== Release ===="
@echo ""
$(TWINE) upload dist/*
.PHONY: release

check-release: build-package
@echo ""
@echo "==== Check package ===="
@echo ""
$(TWINE) check dist/*
.PHONY: check-release


quality: test-initial flake docs freeze-dependencies check-release
@echo ""
@echo "♥ ♥ Everything should be fine ♥ ♥"
@echo ""
.PHONY: quality
4 changes: 3 additions & 1 deletion README.rst
@@ -1,5 +1,6 @@
.. _Python: https://www.python.org/
.. _Django: https://www.djangoproject.com/
.. _Django REST framework: https://www.django-rest-framework.org/

=========================
Sveetch Django app sample
Expand All @@ -12,7 +13,8 @@ Dependancies
************

* `Python`_>=3.6;
* `Django`_>=2.1;
* `Django`_>=2.2;
* `Django REST framework`_>=3.12.0;

Links
*****
Expand Down
7 changes: 7 additions & 0 deletions djangoapp_sample/apps.py
@@ -0,0 +1,7 @@
from django.apps import AppConfig


class djangoapp_sampleConfig(AppConfig):
name = "djangoapp_sample"
verbose_name = "Sveetch Django app sample"
default_auto_field = "django.db.models.AutoField"
4 changes: 3 additions & 1 deletion djangoapp_sample/factories/__init__.py
@@ -1,8 +1,10 @@
from .blog import BlogFactory
from .article import ArticleFactory
from .user import UserFactory


__all__ = [
"BlogFactory",
"ArticleFactory",
"BlogFactory",
"UserFactory",
]
12 changes: 12 additions & 0 deletions djangoapp_sample/factories/article.py
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from django.utils import timezone

import factory

from ..models import Article
Expand All @@ -16,3 +18,13 @@ class ArticleFactory(factory.django.DjangoModelFactory):

class Meta:
model = Article

@factory.lazy_attribute
def publish_start(self):
"""
Return current date.
Returns:
datetime.datetime: Current time.
"""
return timezone.now()
69 changes: 69 additions & 0 deletions djangoapp_sample/factories/user.py
@@ -0,0 +1,69 @@
"""
============
User factory
============
"""
import factory

from django.apps import apps
from django.conf import settings
from django.db.models.signals import post_save


def safe_get_user_model():
"""
Safe loading of the User model, customized or not.
"""
user_app, user_model = settings.AUTH_USER_MODEL.split('.')
return apps.get_registered_model(user_app, user_model)


@factory.django.mute_signals(post_save)
class UserFactory(factory.django.DjangoModelFactory):
"""
Factory to create an User object.
"""
first_name = factory.Faker("first_name")
last_name = factory.Faker("last_name")
username = factory.Sequence(lambda n: "demo-user-%d" % n)
is_active = True
is_staff = False
is_superuser = False
password = "secret"

class Meta:
model = safe_get_user_model()

class Params:
"""
Declare traits that add relevant parameters for admin and superuser
"""
flag_is_admin = factory.Trait(
is_superuser=False,
is_staff=True,
username=factory.Sequence(lambda n: "admin-%d" % n),
)
flag_is_superuser = factory.Trait(
is_superuser=True,
is_staff=True,
username=factory.Sequence(lambda n: "superuser-%d" % n),
)

@factory.lazy_attribute
def email(self):
"""
Email is automatically build from username
"""
return "%s@test.com" % self.username

@classmethod
def _create(cls, model_class, *args, **kwargs):
"""
Ensure the raw password gets set after the initial save
"""
password = kwargs.pop("password", None)
obj = super(UserFactory, cls)._create(model_class, *args, **kwargs)
obj.set_password(password)
obj.save()
return obj
43 changes: 43 additions & 0 deletions djangoapp_sample/migrations/0001_initial.py
@@ -0,0 +1,43 @@
# Generated by Django 3.1.13 on 2021-08-10 20:54

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Blog',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(default='', max_length=55, unique=True, verbose_name='title')),
],
options={
'verbose_name': 'Blog',
'verbose_name_plural': 'Blogs',
'ordering': ['title'],
},
),
migrations.CreateModel(
name='Article',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(default='', max_length=150, verbose_name='title')),
('content', models.TextField(blank=True, default='', verbose_name='content')),
('publish_start', models.DateTimeField(db_index=True, default=django.utils.timezone.now, verbose_name='publication start')),
('blog', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='djangoapp_sample.blog', verbose_name='Related blog')),
],
options={
'verbose_name': 'Article',
'verbose_name_plural': 'Articles',
'ordering': ['-publish_start'],
},
),
]

0 comments on commit 19e3a03

Please sign in to comment.