From 7fdbffa528c69973fd64aad7b2c67dd3838528bf Mon Sep 17 00:00:00 2001 From: Todd Birchard Date: Fri, 16 Oct 2020 02:45:41 -0400 Subject: [PATCH] Easy deploy via Makefile. --- Makefile | 58 +++++++++++++++++++++++++++++++++ deploy.sh | 14 ++++++++ flask_assets_tutorial/assets.py | 2 +- poetry.lock | 42 ++++++++---------------- requirements.txt | 8 +++++ 5 files changed, 95 insertions(+), 29 deletions(-) create mode 100644 Makefile create mode 100644 deploy.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ce889d3 --- /dev/null +++ b/Makefile @@ -0,0 +1,58 @@ +SRCPATH := $(CURDIR) +PROJECTNAME := $(shell basename $(CURDIR)) + +define HELP +Manage $(PROJECTNAME). Usage: + +make run - Run $(PROJECTNAME). +make deploy - Install requirements and run app for the first time. +make update - Update pip dependencies via Python Poetry. +make format - Format code with Python's `Black` library. +make clean - Remove cached files and lock files. +endef +export HELP + +.PHONY: run deploy update format clean help + + +requirements: .requirements.txt + + +.requirements.txt: requirements.txt + $(shell . .venv/bin/activate && pip install -r requirements.txt) + + +all help: + @echo "$$HELP" + + +.PHONY: run +run: + $(shell . .venv/bin/activate && python3 wsgi.py) + + +.PHONY: deploy +deploy: + $(shell . ./deploy.sh) + + +.PHONY: update +update: + poetry shell && poetry update + pip freeze > requirements.txt + exit + + +.PHONY: format +format: requirements + $(shell . .venv/bin/activate) + $(shell isort -rc ./) + $(shell black ./) + + +.PHONY: clean +clean: + find . -name '*.pyc' -delete + find . -name '__pycache__' -delete + find . -name 'poetry.lock' -delete + find . -name 'Pipefile.lock' -delete \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..038a8aa --- /dev/null +++ b/deploy.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ -d ".venv" ] +then + source .venv/bin/activate + pip install -r requirements.txt + python3 wsgi.py +else + python3 -m venv .venv + source .venv/bin/activate + python3 -m pip install --upgrade pip + pip install -r requirements.txt + python3 wsgi.py +fi diff --git a/flask_assets_tutorial/assets.py b/flask_assets_tutorial/assets.py index 801846f..35db170 100644 --- a/flask_assets_tutorial/assets.py +++ b/flask_assets_tutorial/assets.py @@ -27,7 +27,7 @@ def compile_static_assets(assets): assets.register('main_styles', main_style_bundle) assets.register('main_js', main_js_bundle) assets.register('admin_styles', admin_style_bundle) - if app.config['FLASK_ENV'] == 'development': + if app.config['FLASK_ENV'] != 'production': main_style_bundle.build() main_js_bundle.build() admin_style_bundle.build() diff --git a/poetry.lock b/poetry.lock index e1e621f..ccb3f50 100644 --- a/poetry.lock +++ b/poetry.lock @@ -13,13 +13,13 @@ description = "Classes Without Boilerplate" name = "attrs" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "19.3.0" +version = "20.2.0" [package.extras] -azure-pipelines = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface", "pytest-azurepipelines"] -dev = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface", "sphinx", "pre-commit"] -docs = ["sphinx", "zope.interface"] -tests = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface"] +dev = ["coverage (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface", "sphinx", "sphinx-rtd-theme", "pre-commit"] +docs = ["sphinx", "sphinx-rtd-theme", "zope.interface"] +tests = ["coverage (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface"] +tests_no_zope = ["coverage (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six"] [[package]] category = "main" @@ -36,7 +36,7 @@ marker = "sys_platform == \"win32\"" name = "colorama" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" -version = "0.4.3" +version = "0.4.4" [[package]] category = "main" @@ -83,7 +83,7 @@ description = "iniconfig: brain-dead simple config-ini parsing" name = "iniconfig" optional = false python-versions = "*" -version = "1.0.0" +version = "1.1.1" [[package]] category = "main" @@ -135,14 +135,6 @@ optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" version = "1.1.1" -[[package]] -category = "dev" -description = "More routines for operating on iterables, beyond itertools" -name = "more-itertools" -optional = false -python-versions = ">=3.5" -version = "8.4.0" - [[package]] category = "dev" description = "Core utilities for Python packages" @@ -196,14 +188,13 @@ description = "pytest: simple powerful testing with Python" name = "pytest" optional = false python-versions = ">=3.5" -version = "6.0.0" +version = "6.1.1" [package.dependencies] atomicwrites = ">=1.0" attrs = ">=17.4.0" colorama = "*" iniconfig = "*" -more-itertools = ">=4.0.0" packaging = "*" pluggy = ">=0.12,<1.0" py = ">=1.8.2" @@ -270,16 +261,15 @@ atomicwrites = [ {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, ] attrs = [ - {file = "attrs-19.3.0-py2.py3-none-any.whl", hash = "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c"}, - {file = "attrs-19.3.0.tar.gz", hash = "sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72"}, + {file = "attrs-20.2.0-py2.py3-none-any.whl", hash = "sha256:fce7fc47dfc976152e82d53ff92fa0407700c21acd20886a13777a0d20e655dc"}, + {file = "attrs-20.2.0.tar.gz", hash = "sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594"}, ] click = [ {file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"}, {file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"}, ] colorama = [ - {file = "colorama-0.4.3-py2.py3-none-any.whl", hash = "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff"}, - {file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"}, + {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, ] cssmin = [ {file = "cssmin-0.2.0.tar.gz", hash = "sha256:e012f0cc8401efcf2620332339011564738ae32be8c84b2e43ce8beaec1067b6"}, @@ -293,7 +283,7 @@ flask-assets = [ {file = "Flask_Assets-2.0-py3-none-any.whl", hash = "sha256:2845bd3b479be9db8556801e7ebc2746ce2d9edb4e7b64a1c786ecbfc1e5867b"}, ] iniconfig = [ - {file = "iniconfig-1.0.0.tar.gz", hash = "sha256:aa0b40f50a00e72323cb5d41302f9c6165728fd764ac8822aa3fff00a40d56b4"}, + {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, ] itsdangerous = [ {file = "itsdangerous-1.1.0-py2.py3-none-any.whl", hash = "sha256:b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749"}, @@ -345,10 +335,6 @@ markupsafe = [ {file = "MarkupSafe-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be"}, {file = "MarkupSafe-1.1.1.tar.gz", hash = "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b"}, ] -more-itertools = [ - {file = "more-itertools-8.4.0.tar.gz", hash = "sha256:68c70cc7167bdf5c7c9d8f6954a7837089c6a36bf565383919bb595efb8a17e5"}, - {file = "more_itertools-8.4.0-py3-none-any.whl", hash = "sha256:b78134b2063dd214000685165d81c154522c3ee0a1c0d4d113c80361c234c5a2"}, -] packaging = [ {file = "packaging-20.4-py2.py3-none-any.whl", hash = "sha256:998416ba6962ae7fbd6596850b80e17859a5753ba17c32284f67bfff33784181"}, {file = "packaging-20.4.tar.gz", hash = "sha256:4357f74f47b9c12db93624a82154e9b120fa8293699949152b22065d556079f8"}, @@ -370,8 +356,8 @@ pyparsing = [ {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, ] pytest = [ - {file = "pytest-6.0.0-py3-none-any.whl", hash = "sha256:869ec27f9b89964ccfe4fbdd5ccb8d3f285aaa3e9aa16a8491b9c8829148c230"}, - {file = "pytest-6.0.0.tar.gz", hash = "sha256:a64d8fb4c15cdc70dae047352e980a197d855747cc885eb332cb73ddcc769168"}, + {file = "pytest-6.1.1-py3-none-any.whl", hash = "sha256:7a8190790c17d79a11f847fba0b004ee9a8122582ebff4729a082c109e81a4c9"}, + {file = "pytest-6.1.1.tar.gz", hash = "sha256:8f593023c1a0f916110285b6efd7f99db07d59546e3d8c36fc60e2ab05d3be92"}, ] python-dotenv = [ {file = "python-dotenv-0.14.0.tar.gz", hash = "sha256:8c10c99a1b25d9a68058a1ad6f90381a62ba68230ca93966882a4dbc3bc9c33d"}, diff --git a/requirements.txt b/requirements.txt index 082cce5..08732b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,22 @@ +attrs==20.2.0 click==7.1.2 cssmin==0.2.0 Flask==1.1.2 Flask-Assets==2.0 +iniconfig==1.1.1 itsdangerous==1.1.0 Jinja2==2.11.2 jsmin==2.2.2 lesscpy==0.14.0 MarkupSafe==1.1.1 +packaging==20.4 +pluggy==0.13.1 ply==3.11 +py==1.9.0 +pyparsing==2.4.7 +pytest==6.1.1 python-dotenv==0.14.0 six==1.15.0 +toml==0.10.1 webassets==2.0 Werkzeug==1.0.1