Skip to content

Commit 48ca1cb

Browse files
authored
fixing bullshit python packaging issues
1 parent 1671f86 commit 48ca1cb

File tree

6 files changed

+39
-12
lines changed

6 files changed

+39
-12
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ install:
33
pip install -r requirements.txt
44

55
test:
6-
python -m pytest -vv --cov=cli --cov=mlib --cov=utilscli test_mlib.py
6+
python -m pytest -vv --cov=cli --cov=mlib --cov=utilscli --cov=app test_mlib.py
77

88
format:
99
black *.py

app.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@
1212
LOG = create_logger(app)
1313
LOG.setLevel(logging.INFO)
1414

15+
1516
@app.route("/")
1617
def home():
1718
html = f"<h3>Predict the Height From Weight of MLB Players</h3>"
1819
return html.format(format)
1920

20-
@app.route("/predict", methods=['POST'])
21+
22+
@app.route("/predict", methods=["POST"])
2123
def predict():
2224
"""Predicts the Height of MLB Players"""
23-
25+
2426
json_payload = request.json
2527
LOG.info(f"JSON payload: {json_payload}")
26-
prediction = mlib.predict(json_payload['Weight'])
27-
return jsonify({'prediction': prediction})
28+
prediction = mlib.predict(json_payload["Weight"])
29+
return jsonify({"prediction": prediction})
30+
2831

2932
if __name__ == "__main__":
30-
app.run(host='0.0.0.0', port=8080, debug=True)
33+
app.run(host="0.0.0.0", port=8080, debug=True)

cli.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import click
33
from mlib import predict
44

5-
#var=
5+
# var=
6+
67

78
@click.command()
89
@click.option(

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ pylint==2.7.2
44
pytest==6.2.2
55
black==20.8b1
66
click==7.1.2
7-
Flask==1.1.2
7+
Flask==1.1.4
8+
markupsafe==2.0.1
89
joblib==1.0.1
910
pytest-cov==2.11.1
1011
requests==2.25.1

test_mlib.py

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from click.testing import CliRunner
55
from cli import predictcli
66
import utilscli
7+
from app import app as flask_app
78

89

910
@pytest.fixture
@@ -12,6 +13,15 @@ def test_array():
1213
feature = val.reshape(-1, 1)
1314
return feature
1415

16+
@pytest.fixture
17+
def app():
18+
yield flask_app
19+
20+
21+
@pytest.fixture
22+
def client(app):
23+
return app.test_client()
24+
1525

1626
def test_format_input(test_array):
1727
assert test_array.shape == format_input(2).shape
@@ -37,3 +47,11 @@ def test_retrain():
3747
runner = CliRunner()
3848
result = runner.invoke(utilscli.cli, ["--version"])
3949
assert result.exit_code == 0
50+
51+
52+
# Smoke test Flask
53+
def test_index(app, client):
54+
res = client.get('/')
55+
assert res.status_code == 200
56+
expected = "Predict the Height From Weight of MLB Players"
57+
assert expected in res.get_data(as_text=True)

utilscli.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import mlib
44
import requests
55

6+
67
@click.group()
78
@click.version_option("1.0")
89
def cli():
@@ -30,10 +31,13 @@ def retrain(tsize):
3031
@click.option("--host", default="http://localhost:8080/predict", help="Host to query")
3132
def mkrequest(weight, host):
3233
"""Sends prediction to ML Endpoint"""
33-
34-
click.echo(click.style(f"Querying host {host} with weight: {weight}",
35-
bg="green", fg="white"))
36-
payload = {"Weight":weight}
34+
35+
click.echo(
36+
click.style(
37+
f"Querying host {host} with weight: {weight}", bg="green", fg="white"
38+
)
39+
)
40+
payload = {"Weight": weight}
3741
result = requests.post(url=host, json=payload)
3842
click.echo(click.style(f"result: {result.text}", bg="red", fg="white"))
3943

0 commit comments

Comments
 (0)