Skip to content

Commit 95fffda

Browse files
Seluj78gmorer
andauthored
Added Makefile (#40)
* Adding the front and moving the back in his directory * Renamed front -> frontend * Removed node modules and added folder to gitignore * Moved files to frontend folder * Moved black config to root * Started on a Makefile Will fix #38 * Updated makefile and moved files back to normal dir * Removed useless file * Some adjustments * Added venv source * New travis setup * fix Makefile on the source * npm install fix * Should be working * Testing * Added back build * Renamed folders * Moved home react route to base init file * Added more specifications for 3.7 python and source * Testing new stuff for venv * Testing with caps * Added cors * [FIX] error 404 on / * Trying new travis install technique (not using the makefile) * Forgot the folder * Changed makefile prereqs * Removed useless install on tests * [FIX] Npm wasn't fully installed after last change * Added test to see if build was correctly creared * [FIX] Added a env var test for CI so python doesnt install on travis * [FIX] build backend * Apply suggestions from code review Co-authored-by: gmorer <gmorer@users.noreply.github.com>
1 parent f8c0fa8 commit 95fffda

10 files changed

Lines changed: 97 additions & 91 deletions

File tree

.travis.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ language: python
99
python:
1010
- 3.7
1111

12-
install: pip install -r requirements-dev.txt
12+
install: pip install -r backend/requirements-dev.txt
1313

14-
before_script:
15-
- export FLASK_APP="$TRAVIS_BUILD_DIR/backend/app.py"
16-
- export FLASK_ENV="dev"
17-
- export CI=1
14+
#before_script:
15+
# - make build
16+
# - export FLASK_APP="$TRAVIS_BUILD_DIR/backend/app.py"
17+
# - export FLASK_ENV="dev"
18+
# - export CI=1
1819

1920
script:
20-
- export FLASK_DEBUG=1 && export FLASK_SECRET_KEY=ThisIsADevelopmentKey && pytest
21-
- flake8
22-
- black --check backend/app.py backend/PyMatcha/**/*.py
21+
- make tests
22+
# - cd backend
23+
# - export FLASK_DEBUG=1 && export FLASK_SECRET_KEY=ThisIsADevelopmentKey && pytest
24+
# - flake8
25+
# - black --check backend/app.py backend/PyMatcha/**/*.py
2326

2427
notifications:
2528
email:

Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
SHELL := /bin/bash
2+
VENV = $(PWD)/venv
3+
PIP = $(VENV)/bin/pip
4+
PYTHON = $(VENV)/bin/python3
5+
FLASK = $(VENV)/bin/flask
6+
PYTEST = $(VENV)/bin/pytest
7+
FRONTEND = $(PWD)/frontend
8+
BACKEND = $(PWD)/backend
9+
10+
all: install build prod
11+
# TODO: Build and run the server
12+
13+
install_python:
14+
ifndef TRAVIS
15+
test -d $(VENV) || python3.7 -m venv $(VENV)
16+
( \
17+
source $(VENV)/bin/activate; \
18+
pip install wheel; \
19+
$(PIP) install -r $(BACKEND)/requirements.txt \
20+
)
21+
endif
22+
# TODO: Create envs, install everything
23+
24+
install_react:
25+
npm install --prefix $(FRONTEND)
26+
27+
install: install_python install_react
28+
29+
build: install
30+
npm run build --prefix $(FRONTEND)
31+
32+
dev: install
33+
npm run start --prefix $(FRONTEND) &
34+
# TODO: Run the whole server for dev
35+
36+
run: build
37+
( \
38+
export DB_USER=EWARSESTHJ; \
39+
export DB_PASSWORD=EWARSESTHJ; \
40+
export FLASK_SECRET_KEY=EWARSESTHJ; \
41+
export FLASK_DEBUG=EWARSESTHJ; \
42+
source $(VENV)/bin/activate && \
43+
python3 $(BACKEND)/app.py \
44+
)
45+
# TODO: Run the whole server for prod
46+
47+
tests: build
48+
test -d frontend/build
49+
# TODO: Maybe move this to the build stage ? so if the build fails and the folder isn't here it fails immediatly and not at the test stage
50+
# TODO: Run the tests
51+
52+
docker:
53+
# TODO
54+
55+
clean:
56+
rm -rf $(FRONTEND)/node_modules
57+
58+
fclean: clean
59+
rm -rf $(FRONTEND)/build
60+
rm -rf $(VENV)
61+
62+
re: clean all
63+
64+
.PHONY : build backend frontend prod dev clean tests fclean all re
File renamed without changes.

backend/PyMatcha/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424

2525
import peewee
2626

27-
from flask import Flask
27+
from flask import Flask, send_from_directory
2828

2929
from flask_admin import Admin
3030

31+
from flask_cors import CORS
32+
3133

3234
if os.environ.get("FLASK_ENV", None) == "dev":
3335
os.environ["FLASK_DEBUG"] = "1"
@@ -49,7 +51,8 @@
4951
raise EnvironmentError("DB_PASSWORD is not set in the server's environment. Please fix and restart the server.")
5052

5153

52-
application = Flask(__name__)
54+
# TODO: Set static folder to env var or conf
55+
application = Flask(__name__, static_folder='../../frontend/build')
5356
application.debug = os.environ.get("FLASK_DEBUG", 1)
5457
application.secret_key = os.environ.get("FLASK_SECRET_KEY", "ThisIsADevelopmentKey")
5558

@@ -64,16 +67,26 @@
6467
application.config["FLASK_ADMIN_SWATCH"] = "simplex"
6568
admin = Admin(application, name="PyMatcha Admin", template_mode="bootstrap3")
6669

70+
CORS(application)
71+
6772
from PyMatcha.models.user import User, UserAdmin
6873

6974
admin.add_view(UserAdmin(User))
7075

71-
from PyMatcha.routes.views.home import home_bp
7276
from PyMatcha.routes.api.ping_pong import ping_pong_bp
7377

74-
application.register_blueprint(home_bp)
7578
application.register_blueprint(ping_pong_bp)
7679

7780
if bool(int(os.environ.get("CI", 0))):
7881
User.drop_table()
7982
User.create_table()
83+
84+
85+
# Serve React App
86+
@application.route('/', defaults={'path': ''})
87+
@application.route('/<path:path>')
88+
def serve(path):
89+
if path != "" and os.path.exists(application.static_folder + '/' + path):
90+
return send_from_directory(application.static_folder, path)
91+
else:
92+
return send_from_directory(application.static_folder, 'index.html')

backend/PyMatcha/routes/views/__init__.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

backend/PyMatcha/routes/views/home.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

backend/conftest.py

Lines changed: 0 additions & 29 deletions
This file was deleted.
File renamed without changes.

backend/requirements-dev.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ wtf-peewee
55
peewee
66
pymysql
77

8+
flask-cors
9+
810
pytest
911
pytest-flask
1012

1113
flake8
1214
black
13-
pre-commit
15+
pre-commit

backend/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ Flask-Admin
33
wtf-peewee
44
peewee
55
pymysql
6+
7+
flask-cors

0 commit comments

Comments
 (0)