Skip to content

Commit

Permalink
moved flasgger to be an 'extras_require' to avoid jsonschema pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Schonfeld authored and aschonfeld committed Nov 20, 2019
1 parent 7359eb6 commit 21c1575
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
4 changes: 1 addition & 3 deletions docs/source/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
jsonschema<3.0.0 # needed for sphinx, flasgger collisons
flasgger==0.9.3
sphinx==1.6.7
nbsphinx
nbsphinx==0.4.3
matplotlib
prompt-toolkit<2.0.0,>=1.0.4,!=1.0.17; python_version < '3.0'
prompt-toolkit<2.1.0,>=2.0.0; python_version > '3.0'
Expand Down
13 changes: 8 additions & 5 deletions dtale/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
from flask.testing import FlaskClient

import requests
from flasgger import Swagger
from flasgger.utils import swag_from
from flask_compress import Compress
from six import PY3

from dtale import dtale
from dtale.cli.clickutils import retrieve_meta_info_and_version, setup_logging
from dtale.utils import build_shutdown_url, build_url, dict_merge
from dtale.utils import build_shutdown_url, build_url, dict_merge, swag_from
from dtale.views import cleanup, startup

if PY3:
Expand Down Expand Up @@ -198,11 +196,16 @@ def build_app(reaper_on=True, hide_shutdown=False):
host=socket.gethostname(),
schemes=['http'],
)
Swagger(app, template=template)
try:
from flasgger import Swagger # flake8: NOQA
Swagger(app, template=template)
except ImportError:
import warnings
warnings.warn('flasgger dependency not found, please install to enable feature')

@app.route('/')
@app.route('/dtale')
@swag_from('./swagger/dtale/root.yml')
@swag_from('swagger/dtale/root.yml')
def root():
"""
Flask routes which redirect to dtale/main
Expand Down
14 changes: 14 additions & 0 deletions dtale/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import time
from builtins import map, object
from functools import wraps
from logging import getLogger

from flask import jsonify as _jsonify
Expand Down Expand Up @@ -615,3 +616,16 @@ def dict_merge(d1, d2):
elif not d2:
return d1 or {}
return dict(list(d1.items()) + list(d2.items()))


def swag_from(path):
try:
from flasgger.utils import swag_from as flasgger_swag_from
return flasgger_swag_from(path)
except ImportError:
def _swag_from(f):
@wraps(f)
def decorated(*args, **kwargs):
return f(*args, **kwargs)
return decorated
return _swag_from
9 changes: 4 additions & 5 deletions dtale/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import numpy as np
import pandas as pd
import requests
from flasgger.utils import swag_from
from future.utils import string_types
from pandas.tseries.offsets import Day, MonthBegin, QuarterBegin, YearBegin

Expand All @@ -22,7 +21,7 @@
get_str_arg, grid_columns, grid_formatter, json_date,
json_float, json_int, json_timestamp, jsonify,
make_list, retrieve_grid_params, running_with_flask,
running_with_pytest, sort_df_for_grid)
running_with_pytest, sort_df_for_grid, swag_from)

logger = getLogger(__name__)

Expand Down Expand Up @@ -192,7 +191,7 @@ def view_main():


@dtale.route('/processes')
@swag_from('swagger/dtale/views/test-filter.yml')
@swag_from('swagger/dtale/views/processes.yml')
def get_processes():
"""
Flask route which returns list of running D-Tale processes within current python process
Expand Down Expand Up @@ -279,7 +278,7 @@ def test_filter():


@dtale.route('/dtypes')
@swag_from('swagger/dtale/views/dtypes.yaml')
@swag_from('swagger/dtale/views/dtypes.yml')
def dtypes():
"""
Flask route which returns a list of column names and dtypes to the front-end as JSON
Expand Down Expand Up @@ -321,7 +320,7 @@ def load_describe(column_series):


@dtale.route('/describe/<column>')
@swag_from('swagger/dtale/views/describe.yaml')
@swag_from('swagger/dtale/views/describe.yml')
def describe(column):
"""
Flask route which returns standard details about column data using pandas.DataFrame[col].describe to
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def run_tests(self):
url="https://github.com/man-group/dtale",
install_requires=[
"arctic",
"jsonschema<3.0.0",
"flasgger==0.9.3",
"Flask",
"Flask-Compress",
"future",
Expand All @@ -71,6 +69,9 @@ def run_tests(self):
"scipy",
"six"
],
extras_require={
'flasgger': ["jsonschema<3.0.0", "flasgger==0.9.3"]
},
tests_require=[
"mock",
"pytest==4.6.4",
Expand Down
8 changes: 7 additions & 1 deletion tests/dtale/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,13 @@ def test_main():

@pytest.mark.unit
def test_200():
paths = ['/dtale/main', 'site-map', 'apidocs/', 'version-info']
paths = ['/dtale/main', 'site-map', 'version-info']
try:
# flake8: NOQA
from flasgger import Swagger
paths.append('apidocs/')
except ImportError:
pass
with app.test_client() as c:
for path in paths:
response = c.get(path)
Expand Down

0 comments on commit 21c1575

Please sign in to comment.