Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 2 additions & 10 deletions recipes/sync_recipe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def export_recipes_to_yaml(recipes, yml_file):
class RecipeDumper(yaml.Dumper):
pass

class literal(unicode):
class literal(str):
pass

def _dict_representer(dumper, data):
Expand All @@ -100,17 +100,9 @@ def _literal_representer(dumper, data):
RecipeDumper.add_representer(dict, _dict_representer)
RecipeDumper.add_representer(literal, _literal_representer)

# Needed for python2,
# otherwise: 'item': !!python/unicode "some string" is dumped
if sys.version_info < (3,0):
def represent_unicode(dumper, data):
return dumper.represent_scalar(u'tag:yaml.org,2002:str', data)

RecipeDumper.add_representer(unicode, represent_unicode)

yaml_recipes = []
for r in recipes:
recipe_expression = literal(unicode(dict(r)['fields'][0]['expression']))
recipe_expression = literal(str(dict(r)['fields'][0]['expression']))
dict(r)['fields'][0]['expression'] = recipe_expression
recipe_details = {
"name": dict(r)['name'],
Expand Down
1 change: 0 additions & 1 deletion recipes/tests/test_recipes_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def retrieve(*args, **kwargs):
return usr
monkeypatch.setattr(sync_recipes.sb.User, "retrieve", retrieve)

@pytest.mark.skipif(sys.version_info < (3,0), reason="requires python3")
def test_sync_recipe(mock_dataset_template_retrieve,
mock_user_retrieve):
with pytest.raises(SystemExit) as e:
Expand Down
12 changes: 6 additions & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
flake8
mock
requests[security]
six
urllib3>=1.26.0
flask
percy
selenium
dash==1.19.0
dash_auth==1.4.1
dash_core_components==1.15.0
dash_html_components==1.1.2
dash_renderer==1.9.0
dash>=2.14.0
dash_auth>=2.0.0
dash_core_components>=2.0.0
dash_html_components>=2.0.0
dash_renderer>=1.9.1
Werkzeug<=2.0.3
solvebio==2.12.0
pyyaml==5.3.1
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description_file = README.md
28 changes: 1 addition & 27 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function
from setuptools import setup, find_packages

import sys
import warnings

VERSION = 'undefined'
install_requires = ['six', 'pyprind']
install_requires = ['pyprind', 'requests>=2.0.0', 'urllib3>=1.26.0']
extra = {}

with open('solvebio/version.py') as f:
for row in f.readlines():
if row.startswith('VERSION'):
exec(row)

if sys.version_info < (2, 6):
warnings.warn(
'Python 2.5 is no longer officially supported by SolveBio. '
'If you have any questions, please file an issue on GitHub or '
'contact us at support@solvebio.com.',
DeprecationWarning)
install_requires.append('requests >= 0.8.8, < 0.10.1')
install_requires.append('ssl')
elif sys.version_info < (2, 7):
install_requires.append('ordereddict')
else:
install_requires.append('requests>=2.0.0')


# solvebio-recipes requires additional packages
recipes_requires = [
'pyyaml==5.3.1',
Expand All @@ -38,17 +23,6 @@
"recipes": recipes_requires
}

# Adjustments for Python 2 vs 3
if sys.version_info < (3, 0):
# Get simplejson if we don't already have json
try:
import json # noqa
except ImportError:
install_requires.append('simplejson')

# solvebio-recipes only available in python3
extras_requires = {}

with open('README.md') as f:
long_description = f.read()

Expand Down
6 changes: 2 additions & 4 deletions solvebio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

Have questions or comments? email us at: support@solvebio.com
"""
from __future__ import absolute_import
from __future__ import print_function
__docformat__ = 'restructuredtext'

import os as _os
import errno
import logging as _logging
from typing import Literal
from .help import open_help as _open_help
Expand Down Expand Up @@ -61,7 +60,7 @@ def _init_logging():
_os.makedirs(logdir)
except OSError as err:
# Re-raise anything other than 'File exists'.
if err[1] != 'File exists':
if err.errno != errno.EEXIST:
raise err

file_handler = _logging.FileHandler(logfile_path)
Expand All @@ -74,7 +73,6 @@ def _init_logging():
try:
base_logger.addHandler(_logging.NullHandler())
except:
# supports Python < 2.7
class NullHandler(_logging.Handler):
def emit(self, record):
pass
Expand Down
1 change: 0 additions & 1 deletion solvebio/annotate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from .client import client

Expand Down
4 changes: 1 addition & 3 deletions solvebio/auth.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import absolute_import

import os
from typing import Literal, Tuple

from six.moves.urllib.parse import urlparse
from urllib.parse import urlparse

import logging

Expand Down
2 changes: 0 additions & 2 deletions solvebio/cli/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function

import solvebio
from ..client import client
Expand Down
9 changes: 3 additions & 6 deletions solvebio/cli/credentials.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import
from collections import namedtuple
import six

import solvebio

Expand Down Expand Up @@ -55,11 +52,11 @@ def save(self, path):
for host in self.hosts.keys():
attrs = self.hosts[host]
rep = (
rep + "machine " + host + "\n\tlogin " + six.text_type(attrs[0]) + "\n"
rep + "machine " + host + "\n\tlogin " + str(attrs[0]) + "\n"
)
if attrs[1]:
rep = rep + "\taccount " + six.text_type(attrs[1]) + "\n"
rep = rep + "\tpassword " + six.text_type(attrs[2]) + "\n"
rep = rep + "\taccount " + str(attrs[1]) + "\n"
rep = rep + "\tpassword " + str(attrs[2]) + "\n"

f = open(path, "w")
f.write(rep)
Expand Down
6 changes: 1 addition & 5 deletions solvebio/cli/data.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function

import concurrent.futures
from concurrent.futures import ThreadPoolExecutor

from six.moves import input as raw_input

import os
import re
import sys
Expand Down Expand Up @@ -1119,7 +1115,7 @@ def tag(args):
if not args.no_input:

print("")
res = raw_input(
res = input(
"Are you sure you want to apply the above changes to "
"{} object(s) in {} vault(s)? [y/N] ".format(
len(taggable_objects), len(seen_vaults.keys())
Expand Down
1 change: 0 additions & 1 deletion solvebio/cli/ipython.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import sys
import os

Expand Down
1 change: 0 additions & 1 deletion solvebio/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
import sys
import copy
Expand Down
1 change: 0 additions & 1 deletion solvebio/cli/tutorial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import os
from pydoc import pager

Expand Down
3 changes: 1 addition & 2 deletions solvebio/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

import json
import time
Expand All @@ -24,7 +23,7 @@
import ssl
import sys

from six.moves.urllib.parse import urljoin
from urllib.parse import urljoin

# Try using pyopenssl if available.
# Requires: pip install pyopenssl ndg-httpsclient pyasn1
Expand Down
1 change: 0 additions & 1 deletion solvebio/contrib/dash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from __future__ import absolute_import
from .solvebio_auth import SolveBioAuth # noqa: F401
from .solvebio_dash import SolveBioDash # noqa: F401
42 changes: 30 additions & 12 deletions solvebio/contrib/dash/solvebio_auth.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from __future__ import absolute_import

import json
import flask
import requests
import os

from six.moves.urllib.parse import urljoin
from urllib.parse import urljoin

from dash_auth.oauth import OAuthBase
from dash_auth.auth import Auth

import solvebio


class SolveBioAuth(OAuthBase):
class SolveBioAuth(Auth):
"""Handles OAuth2 flows with the SolveBio API."""
AUTH_COOKIE_NAME = 'dash_solvebio_auth'
TOKEN_COOKIE_NAME = 'solvebio_oauth_token'
Expand All @@ -26,12 +24,16 @@ class SolveBioAuth(OAuthBase):

def __init__(self, app, app_url, client_id, **kwargs):
secret_key = kwargs.get('secret_key') or app.server.secret_key
super(SolveBioAuth, self).__init__(
app,
app_url,
client_id,
secret_key=secret_key,
salt=kwargs.get('salt'))

# Initialize the base Auth class
super().__init__(app, public_routes=kwargs.get('public_routes', []))

# Store OAuth configuration
self._app = app
self._app_url = app_url
self._oauth_client_id = client_id
self._secret_key = secret_key
self._salt = kwargs.get('salt')

# Add logout URL
app.server.add_url_rule(
Expand Down Expand Up @@ -71,6 +73,22 @@ def __init__(self, app, app_url, client_id, **kwargs):
with open(os.path.join(_current_path, 'login.js'), 'r') as f:
self.login_bundle = f.read()

def is_authorized(self):
"""Check if the user is authorized by looking for a valid token cookie."""
try:
token = flask.request.cookies.get(self.TOKEN_COOKIE_NAME)
if not token:
return False

# Verify the token by making a test API call
return self.check_view_access(token)
except:
return False

def login_request(self):
"""Return the login page HTML."""
return self.html(self.login_bundle)

def auth_wrapper(self, f):
def wrap(*args, **kwargs):
if not self.is_authorized():
Expand Down Expand Up @@ -99,7 +117,7 @@ def wrap(*args, **kwargs):
if hasattr(self, 'add_access_token_to_response'):
return wrap
else:
return super(SolveBioAuth, self).auth_wrapper(f)
return super().auth_wrapper(f)

def html(self, script):
return ('''
Expand Down
7 changes: 3 additions & 4 deletions solvebio/contrib/dash/solvebio_dash.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import print_function

import dash
import flask

Expand All @@ -23,6 +20,7 @@ def __init__(self, name, *args, **kwargs):

app_url = kwargs.pop('app_url', self.APP_URL)
solvebio_url = kwargs.pop('solvebio_url', self.SOLVEBIO_URL)
api_host = kwargs.pop('api_host', None) # Extract api_host before passing to Dash

# OAuth2 credentials
client_id = kwargs.pop('client_id',
Expand All @@ -46,7 +44,8 @@ def __init__(self, name, *args, **kwargs):
salt=salt,
client_secret=client_secret,
grant_type=grant_type,
solvebio_url=solvebio_url)
solvebio_url=solvebio_url,
api_host=api_host)
else:
self.auth = None
print("WARNING: No SolveBio client ID found. "
Expand Down
1 change: 0 additions & 1 deletion solvebio/contrib/dash/tests/IntegrationTests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from selenium import webdriver
import multiprocessing
import requests
Expand Down
Loading
Loading