Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and improvement for 0.1.8 #11

Merged
merged 31 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5091356
Remove dead code
lamhoangtung Sep 23, 2020
92918c3
Compress swagger html
lamhoangtung Sep 23, 2020
f6997fb
Detach base64 img to file to reduce html footprint on mlchain server …
lamhoangtung Sep 23, 2020
8a6ec59
Trying to strip down mlchain dependencies
lamhoangtung Sep 24, 2020
baaf1e7
Still trying
lamhoangtung Sep 24, 2020
e084a29
turn grpc on
lamhoangtung Sep 24, 2020
0ac03e5
Minor travis config fix
lamhoangtung Sep 24, 2020
157ead2
Set version 0.1.7 for cli --version
lamhoangtung Sep 24, 2020
8c6a191
Fix yaml loader deprecated
lamhoangtung Sep 24, 2020
2da43c2
Remove useless warning
lamhoangtung Sep 24, 2020
f817ad8
Fixed parser worker config bugs
lamhoangtung Sep 24, 2020
22c7ec2
Add missing dep for fuzzywuzzy
lamhoangtung Sep 24, 2020
2922805
Remove dead file
lamhoangtung Sep 24, 2020
9bc7e24
Better long description for PYPI
lamhoangtung Sep 24, 2020
d7aec6f
Fixed workers config bug with quart and hypercorn
lamhoangtung Sep 24, 2020
5328f5b
Minor
lamhoangtung Sep 24, 2020
2935345
Let user set torch thread for multiprocessing on their own
lamhoangtung Sep 24, 2020
1c84034
Minor CLI fix
lamhoangtung Sep 24, 2020
7127771
Dont check coverage for tests
lamhoangtung Sep 24, 2020
5188112
Minor
lamhoangtung Sep 25, 2020
72dcd0c
Avoid leaving unclose resource
lamhoangtung Sep 25, 2020
fa2f2a4
Minor
lamhoangtung Sep 25, 2020
4b2340a
PEP8 old test
lamhoangtung Sep 25, 2020
1c0ab5b
Much more unit test and better code coverage
lamhoangtung Sep 25, 2020
342d69a
exclude other lib from coverage check
lamhoangtung Sep 25, 2020
f1e90cd
macos test tune
lamhoangtung Sep 25, 2020
4887328
oh shit
lamhoangtung Sep 25, 2020
042d02a
Test more serializer
lamhoangtung Sep 25, 2020
5d319af
Auto switch off gunicorn on Windows
lamhoangtung Sep 25, 2020
24e547c
Turn off some test for windows
lamhoangtung Sep 25, 2020
3941555
Add codecov config to turn off coverage check on patch
lamhoangtung Sep 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
omit =
*/site-packages/*
*/distutils/*
tests/*
setup.py
mlchain/__main__.py
concurrency = multiprocessing
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ mlchain.egg-info
.pyc
test/*
.pytest_cache
**/.DS_Store
**/.DS_Store
htmlcov
.coverage
.coverage.*
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- stage: build
name: "Build on Python 3.7 MacOS"
os: osx
language: minimal
language: shell
install:
- pip3 install -U scikit-build awscli pip
- pip3 install -U -r requirements.txt
Expand Down Expand Up @@ -78,6 +78,7 @@ jobs:
script:
- pip install .
- python -m coverage run --source=. -m unittest discover
- python -m coverage combine
- python -m coverage report
after_success:
- codecov
Expand All @@ -93,6 +94,7 @@ jobs:
script:
- pip install .
- python -m coverage run --source=. -m unittest discover
- python -m coverage combine
- python -m coverage report
after_success:
- codecov
Expand All @@ -101,13 +103,14 @@ jobs:
- stage: test
name: "Test on Python 3.7 MacOS"
os: osx
language: minimal
language: shell
install:
- pip3 install -U scikit-build pytest coverage codecov pip
- pip3 install -U attrs
script:
- pip3 install .
- python3 -m coverage run --source=. -m unittest discover
- python3 -m coverage combine
- python3 -m coverage report
after_success:
- codecov
Expand All @@ -125,6 +128,7 @@ jobs:
script:
- python -m pip install .
- python -m coverage run --source=. -m unittest discover
- python -m coverage combine
- python -m coverage report
after_success:
- codecov
Expand All @@ -142,4 +146,4 @@ jobs:
secure: lEK5DTFYmn2vkeP8OrG8CPgUOH/PvhO76OO5F2/K3HbQxJZLH3Vsmzk/mRsY1pIC52XpGLDSg/8d62V9bu2WNReLRQJZ1zIgKSswvf4USrsd0axGwIbJyuX+vr81/x4j4rQr3ohfb2zOIit7JoDrRugwBICSAEukNfXoOZdN6wVn4zpLsW/bdlrNlIsNmhzUBKfurRMPEqsSE1Bq2dDGmyd4KNiZlaJF4PEgNQHfV9qwW2+j/ky4ulCzFgIfxKUpIfvUPFN3Uw3HdaJAaOH6h+S84hvi30xwD8bT8os990fK0zZ/sW5e0ogRckmkGh3jDJcXzyCPetAABMkUjwTrIkehQ2I2QhT49V0+Qqq3A3iJFAGxufl3HEYNY4ZVxo7PXMBIkmA6TdKomhPLh1nKeQTaFomSvoY/Usnc5pF1Va5vhHUz2mGeUgnbR0kQPN2d3yF6hVvl2TnM4Ml0YK2sQa4og4xYOouBGqJsATTZ7OEdG/Iha1KpQRwkHaWs+FShGs1UL0UZO5+FYVSd6va3i1IPxZLoZzJBPscclKBJbrtfup7cWRO2LEeS1uzS0NEKGTmrZLmOW8m9o0Pt+F61pU8meG3O+n0CxYGrytUSNvCrMA0+ZT9DY0hF9Q08w7AASG+zZVarwhnFDakeNq91Z1GLGxB+mD3vIa5mslZGYMw=
on:
tags: true
distributions: "sdist bdist_wheel"
distributions: "sdist bdist_wheel"
21 changes: 0 additions & 21 deletions LICENSE.txt

This file was deleted.

2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include LICENSE *.rst *.toml *.yml *.yaml
include LICENSE *.rst *.md *.toml *.yml *.yaml
include requirements.txt
graft .github

Expand Down
3 changes: 0 additions & 3 deletions README.rst

This file was deleted.

9 changes: 9 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coverage:
status:
project: # settings affecting project coverage
default:
target: auto # auto % coverage target
threshold: 5% # allow for 5% reduction of coverage without failing

# do not run coverage on patch nor changes
patch: false
11 changes: 2 additions & 9 deletions mlchain/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Parameters of MLchain
__version__ = "0.1.6"
__version__ = "0.1.7"
HOST = "https://www.api.mlchain.ml"
WEB_HOST = HOST
API_ADDRESS = HOST
Expand All @@ -11,11 +11,4 @@
from .context import mlchain_context

from .base.exceptions import *
from .config import mlconfig

try:
import torch

torch.set_num_thread(1)
except Exception as e:
pass
from .config import mlconfig
3 changes: 2 additions & 1 deletion mlchain/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ def init_command(file):
logger.warning("File {} exists. Please change name file".format(file))
else:
with open(file, 'wb') as fp:
fp.write(open(os.path.join(root_path, 'config.yaml'), 'rb').read())
with open(os.path.join(root_path, 'config.yaml'), 'rb') as fr:
fp.write(fr.read())
12 changes: 6 additions & 6 deletions mlchain/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ def get_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return

message = "Python %(python)s\nMlChain %(mlchain)s\nFlask %(flask)s\nQuart %(quart)s\nGrpc %(grpc)s"
message = "Python %(python)s\nMlChain %(mlchain)s\nFlask %(flask)s\nQuart %(quart)s\n"
click.echo(
message
% {
"python": platform.python_version(),
"mlchain": __version__,
"flask": flask.__version__,
"quart": quart.__version__,
"grpc": grpc.__version__
"quart": quart.__version__
},
color=ctx.color,
)
ctx.exit()


def main(as_module=False):
def main(as_module=False, is_testing=False):
version_option = click.Option(
["--version"],
help="Show the mlchain version",
Expand All @@ -46,8 +45,9 @@ def main(as_module=False):
cli.add_command(init_command)
cli.add_command(artifact_command)
cli.add_command(serve_command)
if is_testing:
return cli
cli.main(args=sys.argv[1:], prog_name="python -m mlchain" if as_module else None)


if __name__ == "__main__":
main(as_module=True)
cli = main(as_module=True)
14 changes: 8 additions & 6 deletions mlchain/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ def run_command(entry_file, host, port, bind, wrapper, server, workers, config,
bind = None
bind = mlconfig.get_value(bind, config, 'bind', [])
wrapper = mlconfig.get_value(wrapper, config, 'wrapper', None)
workers = mlconfig.get_value(workers, config, 'workers', None)
if workers is None:
workers = 1
else:
workers = int(workers)
if wrapper == 'gunicorn' and os.name == 'nt':
logger.warning('Gunicorn warper are not supported on Windows. Switching to None instead.')
wrapper = None
workers = mlconfig.get_value(workers, config['gunicorn'], 'workers', None)
if workers is None and 'hypercorn' in config.keys():
workers = mlconfig.get_value(workers, config['hypercorn'], 'workers', None)
workers = int(workers) if workers is not None else 1
name = mlconfig.get_value(name, config, 'name', None)
cors = mlconfig.get_value(None, config, 'cors', False)

Expand Down Expand Up @@ -262,7 +264,7 @@ def load(self):
static_url_path=static_url_path,
static_folder=static_folder,
template_folder=template_folder)
app.run(host, port, bind=bind, cors=cors, workers=workers,
app.run(host, port, bind=bind, cors=cors,
gunicorn=False, hypercorn=True, **config.get('hypercorn', {}), model_id=model_id)

app = get_model(entry_file)
Expand Down
4 changes: 1 addition & 3 deletions mlchain/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
class Client(HttpClient, GrpcClient):
def __init__(self, api_key=None, api_address=None, serializer='json', timeout=5 * 60, headers=None, type='http',
name: str = "", version: str = "", check_status=False):
logger.warn("mlchain.client.Client is deprecated and will be remove in the next version. "
"Please use mlchain.client.HttpModel instead")
assert isinstance(type, str), "type model must be a string"
self._api_key = api_key
self._api_address = api_address
Expand All @@ -28,7 +26,7 @@ def __init__(self, api_key=None, api_address=None, serializer='json', timeout=5
raise Exception("type must be http or grpc")

def model(self, name: str = "", version: str = "", check_status=False):
logger.warn(
logger.warning(
"function .model is deprecated and will be remove in the next version")
if self._type.lower() == 'http':
return HttpClient(api_key=self._api_key, api_address=self._api_address, serializer=self._serializer,
Expand Down
8 changes: 5 additions & 3 deletions mlchain/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def from_json(self, path):

def from_yaml(self, path):
import yaml
self.update(yaml.load(open(path)))
self.update(yaml.load(open(path), Loader=yaml.FullLoader))

def update(self, data):
for k, v in data.items():
Expand Down Expand Up @@ -134,12 +134,14 @@ def load_config(data):

def load_json(path):
import json
return json.load(open(path, encoding='utf-8'))
with open(path, encoding='utf-8') as f:
return json.load(f)


def load_yaml(path):
import yaml
return yaml.load(open(path))
with open(path) as f:
return yaml.load(f, Loader=yaml.FullLoader)


def load_file(path):
Expand Down
Binary file added mlchain/server/static/mlchain_fig_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mlchain/server/static/mlchain_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
832 changes: 456 additions & 376 deletions mlchain/server/templates/home.html

Large diffs are not rendered by default.

61 changes: 1 addition & 60 deletions mlchain/server/templates/swaggerui/index.html
Original file line number Diff line number Diff line change
@@ -1,60 +1 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after
{
box-sizing: inherit;
}

body
{
margin:0;
background: #fafafa;
}
</style>
</head>

<body>
<div id="swagger-ui"></div>

<script src="./swagger-ui-bundle.js"> </script>
<script src="./swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "./swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region

window.ui = ui
}
</script>
</body>
</html>
<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><title>Swagger UI</title><link rel=stylesheet type=text/css href=./swagger-ui.css><link rel=icon type=image/png href=./favicon-32x32.png sizes=32x32 /><link rel=icon type=image/png href=./favicon-16x16.png sizes=16x16 /><style>html{box-sizing:border-box;overflow:-moz-scrollbars-vertical;overflow-y:scroll}*,*:before,*:after{box-sizing:inherit}body{margin:0;background:#fafafa}</style></head><body><div id=swagger-ui></div> <script src=./swagger-ui-bundle.js></script> <script src=./swagger-ui-standalone-preset.js></script> <script>window.onload=function(){const a=SwaggerUIBundle({url:"./swagger.json",dom_id:"#swagger-ui",deepLinking:true,presets:[SwaggerUIBundle.presets.apis,SwaggerUIStandalonePreset],plugins:[SwaggerUIBundle.plugins.DownloadUrl],layout:"StandaloneLayout"});window.ui=a};</script> </body></html>
67 changes: 0 additions & 67 deletions mlchain/server/templates/swaggerui/oauth2-redirect.html

This file was deleted.

Loading