Skip to content

Commit 94d7e25

Browse files
committed
Added Makefile and updated README.
1 parent 725d273 commit 94d7e25

File tree

7 files changed

+371
-201
lines changed

7 files changed

+371
-201
lines changed

Makefile

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,58 @@
11
SRCPATH := $(CURDIR)
2-
ENTRYPOINT := $(shell find $(SRCPATH) -name '*.ini')
3-
PROJECTNAME := $(shell basename "$PWD")
2+
PROJECTNAME := $(shell basename $(CURDIR))
43

54
define HELP
6-
Manage $(PROJECTNAME).
5+
Manage $(PROJECTNAME). Usage:
76

8-
Usage:
9-
10-
make run - Run uWSGI server for $(PROJECTNAME).
11-
make restart - Purge cache & reinstall modules.
12-
make update - Update npm production dependencies.
13-
make clean - Remove cached files.
7+
make run - Run $(PROJECTNAME).
8+
make deploy - Install requirements and run app for the first time.
9+
make update - Update pip dependencies via Python Poetry.
10+
make format - Format code with Python's `Black` library.
11+
make clean - Remove cached files and lock files.
1412
endef
1513
export HELP
1614

17-
.PHONY: run restart update help
15+
.PHONY: run restart deploy update clean help
16+
17+
18+
requirements: .requirements.txt
19+
20+
21+
.requirements.txt: requirements.txt
22+
$(shell . .venv/bin/activate && pip install -r requirements.txt)
23+
1824

1925
all help:
2026
@echo "$$HELP"
2127

28+
2229
.PHONY: run
2330
run:
24-
nohup uwsgi $(ENTRYPOINT) &
31+
$(shell . .venv/bin/activate && python3 wsgi.py)
32+
33+
34+
.PHONY: deploy
35+
deploy:
36+
$(shell . ./deploy.sh)
2537

26-
.PHONY: restart
27-
restart:
28-
pkill -9 -f $(shell uwsgi $(ENTRYPOINT))
29-
nohup uwsgi $(ENTRYPOINT) &
3038

3139
.PHONY: update
3240
update:
33-
git pull origin master
34-
pkill -9 -f $(shell uwsgi $(ENTRYPOINT))
35-
poetry shell
36-
poetry update
37-
nohup uwsgi $(ENTRYPOINT) &
41+
poetry shell && poetry update
42+
pip freeze > requirements.txt
43+
exit
44+
45+
46+
.PHONY: format
47+
format: requirements
48+
$(shell . .venv/bin/activate)
49+
$(shell isort -rc ./)
50+
$(shell black ./)
51+
3852

3953
.PHONY: clean
4054
clean:
4155
find . -name '*.pyc' -delete
4256
find . -name '__pycache__' -delete
57+
find . -name 'poetry.lock' -delete
58+
find . -name 'Pipefile.lock' -delete

README.md

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Plotly Dash Flask Tutorial
22

3-
43
![Python](https://img.shields.io/badge/Python-^3.8-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
54
![Flask](https://img.shields.io/badge/Flask-1.1.2-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
65
![Flask-Assets](https://img.shields.io/badge/Flask--Assets-v2.0-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
@@ -16,57 +15,38 @@
1615

1716
Make Plotly Dash part of your Flask Application by following this example.
1817

19-
* The full tutorial can be found here: https://hackersandslackers.com/plotly-dash-with-flask/
20-
* A live demo can be found here: https://plotlydashflask.hackersandslackers.app/
21-
22-
## Installation
23-
24-
**Installation via `requirements.txt`**:
25-
26-
```shell
27-
$ git clone https://github.com/toddbirchard/plotlydash-flask-tutorial.git
28-
$ cd plotlydash-flask-tutorial
29-
$ python3 -m venv myenv
30-
$ source myenv/bin/activate
31-
$ pip3 install -r requirements.txt
32-
$ flask run
33-
```
18+
* **Tutorial**: https://hackersandslackers.com/plotly-dash-with-flask/
19+
* **Demo**: https://plotlydashflask.hackersandslackers.app/
3420

35-
**Installation via [Pipenv](https://pipenv-fork.readthedocs.io/en/latest/)**:
21+
# Getting Started
3622

37-
```shell
38-
$ git clone https://github.com/toddbirchard/plotlydash-flask-tutorial.git
39-
$ cd plotlydash-flask-tutorial
40-
$ pipenv shell
41-
$ pipenv update
42-
$ flask run
43-
```
23+
Get set up locally in two steps:
4424

45-
**Installation via [Poetry](https://python-poetry.org/)**:
46-
47-
```shell
48-
$ git clone https://github.com/hackersandslackers/plotlydash-flask-tutorial.git
49-
$ cd plotlydash-flask-tutorial
50-
$ poetry shell
51-
$ poetry update
52-
$ poetry run
53-
```
54-
55-
## Usage
25+
### Environment Variables
5626

5727
Replace the values in **.env.example** with your values and rename this file to **.env**:
5828

59-
* `FLASK_APP`: Entry point of your application (should be `wsgi.py`).
60-
* `FLASK_ENV`: The environment to run your app in (either `development` or `production`).
29+
* `FLASK_APP`: Entry point of your application; should be `wsgi.py`.
30+
* `FLASK_ENV`: The environment in which to run your application; either `development` or `production`.
6131
* `SECRET_KEY`: Randomly generated string of characters used to encrypt your app's data.
62-
* `LESS_BIN`: Path to your local LESS installation via `which lessc` (optional for static assets).
63-
* `ASSETS_DEBUG`: Debug asset creation and bundling in `development` (optional).
64-
* `LESS_RUN_IN_DEBUG`: Debug LESS while in `development` (optional).
65-
* `COMPRESSOR_DEBUG`: Debug asset compression while in `development` (optional).
32+
* `LESS_BIN` *(optional for static assets)*: Path to your local LESS installation via `which lessc`.
33+
* `ASSETS_DEBUG` *(optional)*: Debug asset creation and bundling in `development`.
34+
* `LESS_RUN_IN_DEBUG` *(optional)*: Debug LESS while in `development`.
35+
* `COMPRESSOR_DEBUG` *(optional)*: Debug asset compression while in `development`.
6636

6737

6838
*Remember never to commit secrets saved in .env files to Github.*
6939

40+
### Installation
41+
42+
Get up and running with `make deploy`:
43+
44+
```shell
45+
$ git clone https://github.com/hackersandslackers/plotlydash-flask-tutorial.git
46+
$ cd plotlydash-flask-tutorial
47+
$ make deploy
48+
```
49+
7050
-----
7151

7252
**Hackers and Slackers** tutorials are free of charge. If you found this tutorial helpful, a [small donation](https://www.buymeacoffee.com/hackersslackers) would be greatly appreciated to keep us in business. All proceeds go towards coffee, and all coffee goes towards more content.

deploy.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
if [ -d ".venv" ]
4+
then
5+
source .venv/bin/activate
6+
pip install -r requirements.txt
7+
python3 wsgi.py
8+
else
9+
python3 -m venv .venv
10+
source .venv/bin/activate
11+
python3 -m pip install --upgrade pip
12+
pip install -r requirements.txt
13+
python3 wsgi.py
14+
fi

0 commit comments

Comments
 (0)