feat(makefile): mets à jour suivant le cookiecutter
Dans les modifications majeures, `READ_CONFIG_FILE` est supprimée afin de simplifier la définition de `ENV`.pull/124/head
Parent
5eae7e00fe
révision
e0db291e8b
58
Makefile
58
Makefile
|
@ -20,34 +20,17 @@ else
|
|||
PIP := $(shell which pip)
|
||||
endif
|
||||
|
||||
# Détermine si black est présent.
|
||||
USE_BLACK := $(shell $(PYTHON) -c 'import black; print("1")' 2>/dev/null)
|
||||
|
||||
# Détermine s'il faut charger le fichier de configuration.
|
||||
ifneq ($(READ_CONFIG_FILE), 0)
|
||||
READ_CONFIG_FILE := 1
|
||||
else
|
||||
READ_CONFIG_FILE := 0
|
||||
endif
|
||||
|
||||
# Détermine l'environnement à utiliser.
|
||||
DEFAULT_ENV := production
|
||||
ifndef ENV
|
||||
ifeq ($(READ_CONFIG_FILE), 1)
|
||||
# Commence par chercher la dernière valeur de DJANGO_SETTINGS_MODULE,
|
||||
# puis de ENV s'il n'y en a pas, ou utilise l'environnement par défaut.
|
||||
ENV = $(shell \
|
||||
sed -n -e '/^DJANGO_SETTINGS_MODULE/s/[^.]*\.settings\.\([^.]*\)/\1/p' \
|
||||
-e '/^ENV/s/[^=]*=\(.*\)/\1/p' config.env 2> /dev/null \
|
||||
| tail -n 1 | grep -Ee '^..*' || echo "$(DEFAULT_ENV)")
|
||||
ifdef DJANGO_SETTINGS_MODULE
|
||||
ENV = $(shell echo $(DJANGO_SETTINGS_MODULE) | cut -d. -f3)
|
||||
else
|
||||
ifdef DJANGO_SETTINGS_MODULE
|
||||
ENV = $(shell echo $(DJANGO_SETTINGS_MODULE) | cut -d. -f3)
|
||||
else
|
||||
ENV := $(DEFAULT_ENV)
|
||||
endif # ifdef DJANGO_SETTINGS_MODULE
|
||||
endif # ifeq READ_CONFIG_FILE
|
||||
endif # ifndef ENV
|
||||
DEFAULT_ENV := production
|
||||
ENV = $(shell \
|
||||
sed -n '/^ENV/s/[^=]*=\(.*\)/\1/p' config.env 2> /dev/null \
|
||||
| tail -n 1 | grep -Ee '^..*' || echo "$(DEFAULT_ENV)")
|
||||
endif
|
||||
endif
|
||||
|
||||
# Définis EDITOR pour l'édition interactive.
|
||||
ifndef EDITOR
|
||||
|
@ -60,7 +43,7 @@ endif
|
|||
|
||||
# Définition des cibles -------------------------------------------------------
|
||||
|
||||
.PHONY: help clean-build clean-pyc check check-config docs clean-docs test test-wip fix-lint shell pre-commit sql-reset psql-reset
|
||||
.PHONY: help clean-build clean-pyc check check-config docs clean-docs test test-wip fix-lint shell
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
# Commentaire d'une cible : #-> interne ##-> aide production+dev ###-> aide dev
|
||||
|
@ -83,14 +66,13 @@ clean-build:
|
|||
clean-pyc:
|
||||
find chronos/ \( -name '*.pyc' -o -name '*.pyo' -o -name '*~' \) -exec rm -f {} +
|
||||
|
||||
init: create-venv config.env update ## initialise l'environnement et l'application
|
||||
init: create-venv config.env ## initialise l'environnement et l'application
|
||||
@$(MAKE) --no-print-directory update
|
||||
|
||||
config.env:
|
||||
ifeq ($(READ_CONFIG_FILE), 1)
|
||||
cp config.env.example config.env
|
||||
chmod go-rwx config.env
|
||||
$(EDITOR) config.env
|
||||
endif
|
||||
|
||||
update: check-config install-deps migrate static docs ## mets à jour l'application et ses dépendances
|
||||
touch chronos/wsgi.py
|
||||
|
@ -104,7 +86,6 @@ check-config:
|
|||
vous devriez au moins faire : chmod o-rwx config.env"; false; }
|
||||
|
||||
install-deps:
|
||||
$(PIP) install --upgrade pip
|
||||
$(PIP) install --upgrade --requirement requirements/$(ENV).txt
|
||||
|
||||
migrate:
|
||||
|
@ -145,26 +126,19 @@ test: ### lance les tests de l'application
|
|||
test-wip: #### lance les tests marqués 'wip'
|
||||
$(PYTHON) -m pytest -vv -m 'wip' --pdb
|
||||
|
||||
cov: test ### vérifie la couverture de code
|
||||
coverage: test ### vérifie la couverture de code
|
||||
$(PYTHON) -m coverage html
|
||||
@echo open htmlcov/index.html
|
||||
|
||||
lint: ### vérifie la syntaxe et le code python
|
||||
@$(PYTHON) -m flake8 chronos \
|
||||
|| echo "\033[31m[flake8]\033[0m Veuillez corriger les erreurs ci-dessus."
|
||||
@$(PYTHON) -m isort --check chronos \
|
||||
|| echo "\033[31m[isort]\033[0m Veuillez corriger l'ordre des imports avec : make fix-lint"
|
||||
ifdef USE_BLACK
|
||||
@$(PYTHON) -m black --check chronos
|
||||
endif
|
||||
@$(PYTHON) -m flake8 chronos || \
|
||||
{ echo "\033[31mErreur !\033[0m Veuillez corriger la syntaxe avec : make format"; false; }
|
||||
|
||||
fix-lint: ### corrige la syntaxe et ordonne les imports python
|
||||
format: ### formate le code Python
|
||||
$(PYTHON) -m isort chronos
|
||||
ifdef USE_BLACK
|
||||
$(PYTHON) -m black chronos
|
||||
endif
|
||||
|
||||
shell: ### lance un shell python dans l'environnement
|
||||
shell: ### lance un shell Python dans l'environnement
|
||||
ifeq ($(ENV), production)
|
||||
$(PYTHON) manage.py shell
|
||||
else
|
||||
|
|
|
@ -13,8 +13,7 @@ root_dir = environ.Path(__file__) - 2
|
|||
base_dir = env.path('BASE_DIR', default=str(root_dir - 1))
|
||||
|
||||
# Load config.env, OS environment variables will take precedence
|
||||
if env.bool('READ_CONFIG_FILE', default=True):
|
||||
env.read_env(str(base_dir.path('config.env')))
|
||||
env.read_env(str(base_dir.path('config.env')))
|
||||
|
||||
"""The Django settings module's name to use."""
|
||||
DJANGO_SETTINGS_MODULE = env(
|
||||
|
|
|
@ -13,3 +13,13 @@ exclude = '''
|
|||
)/
|
||||
| urls(|_.+|/.+).py
|
||||
'''
|
||||
|
||||
[tool.isort]
|
||||
profile = 'black'
|
||||
line_length = 80
|
||||
known_django = 'django'
|
||||
known_first_party = 'chronos'
|
||||
sections = [
|
||||
'FUTURE', 'STDLIB', 'DJANGO', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER'
|
||||
]
|
||||
skip_glob = '**/migrations/*.py'
|
||||
|
|
|
@ -14,7 +14,9 @@ pytest-django
|
|||
|
||||
# Code quality
|
||||
# ------------------------------------------------------------------------------
|
||||
black; python_version>'3.5'
|
||||
black
|
||||
flake8 >=3.5.0
|
||||
isort
|
||||
flake8-black
|
||||
flake8-isort
|
||||
isort >=5.0
|
||||
pytest-cov
|
||||
|
|
41
setup.cfg
41
setup.cfg
|
@ -6,31 +6,6 @@ testpaths = chronos
|
|||
markers =
|
||||
wip: mark a test as a work in progress
|
||||
|
||||
[flake8]
|
||||
exclude =
|
||||
.git,
|
||||
.tox,
|
||||
venv,
|
||||
*/migrations/*,
|
||||
*/static/*,
|
||||
# assets & compilation
|
||||
assets,
|
||||
build,
|
||||
dist,
|
||||
node_modules
|
||||
max-line-length = 80
|
||||
|
||||
# isort related: https://github.com/timothycrosley/isort/wiki/isort-Settings[
|
||||
[isort]
|
||||
line_length = 79
|
||||
known_first_party = chronos
|
||||
multi_line_output = 3
|
||||
default_section = THIRDPARTY
|
||||
known_django = django
|
||||
sections = FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
|
||||
skip_glob = **/migrations/*.py
|
||||
include_trailing_comma = True
|
||||
|
||||
[coverage:run]
|
||||
branch = True
|
||||
source = chronos/
|
||||
|
@ -40,9 +15,25 @@ omit =
|
|||
chronos/settings/*,
|
||||
chronos/conftest.py
|
||||
chronos/wsgi.py
|
||||
|
||||
[coverage:report]
|
||||
exclude_lines =
|
||||
pragma: no cover
|
||||
if settings.DEBUG:
|
||||
raise NotImplementedError
|
||||
show_missing = True
|
||||
|
||||
[flake8]
|
||||
exclude =
|
||||
.git,
|
||||
.tox,
|
||||
venv,
|
||||
*/migrations/*,
|
||||
*/static/*,
|
||||
assets,
|
||||
build,
|
||||
dist,
|
||||
node_modules
|
||||
per-file-ignores =
|
||||
urls.py: BLK
|
||||
max-line-length = 80
|
||||
|
|
Chargement…
Référencer dans un nouveau ticket