Skip to content

Commit

Permalink
[#686] fix/disable high priority warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbotsman committed Jan 30, 2019
1 parent dbb0813 commit 5c93f4f
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 83 deletions.
13 changes: 6 additions & 7 deletions legion/legion/containers/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
LOGGER = logging.getLogger(__name__)


def build_docker_client(args=None):
def build_docker_client(args=None): # pylint: disable=W0613
"""
Create docker client
Expand All @@ -55,7 +55,7 @@ def get_docker_container_id_from_cgroup_line(line):
parts = line.split('/')

try:
if 'docker' in parts:
if 'docker' in parts: # pylint: disable=R1705
docker_pos = parts.index('docker')
return parts[docker_pos + 1]
elif 'kubepods' in parts:
Expand All @@ -73,7 +73,7 @@ def get_current_docker_container_id():
:return: str -- current container id
"""
with open('/proc/self/cgroup') as f:
with open('/proc/self/cgroup') as f: # pylint: disable=C0103
lines = [line.strip('\n') for line in f]
longest_line = max(lines, key=len)
return get_docker_container_id_from_cgroup_line(longest_line)
Expand Down Expand Up @@ -118,8 +118,7 @@ def get_docker_log_line_content(log_line):
return str_line.rstrip('\n')


def build_docker_image(client, model_id, model_file, labels,
docker_image_tag):
def build_docker_image(client, model_id, model_file, labels, docker_image_tag): # pylint: disable=R0914
"""
Build docker image from current image with addition files
Expand Down Expand Up @@ -208,7 +207,7 @@ def build_docker_image(client, model_id, model_file, labels,

LOGGER.info('Building docker image in folder {}'.format(temp_directory.path))
try:
image, logs = client.images.build(
image, logs = client.images.build( # pylint: disable=W0612
tag=docker_image_tag,
nocache=True,
path=temp_directory.path,
Expand All @@ -224,7 +223,7 @@ def build_docker_image(client, model_id, model_file, labels,
return image


def generate_docker_labels_for_image(model_file, model_id, args):
def generate_docker_labels_for_image(model_file, model_id):
"""
Generate docker image labels from model file
Expand Down
10 changes: 5 additions & 5 deletions legion/legion/docker_bootup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
LOGGER = logging.getLogger(__name__)

try:
host = os.getenv('PYDEVD_HOST')
port = os.getenv('PYDEVD_PORT')
host = os.getenv('PYDEVD_HOST') # pylint: disable=C0103
port = os.getenv('PYDEVD_PORT') # pylint: disable=C0103
LOGGER.debug('Docker bootup got configuration: host={!r} port={!r}'.format(host, port))

if host and port:
import pydevd
import pydevd # pylint: disable=F0401

try:
port = int(port)
port = int(port) # pylint: disable=C0103
except ValueError as value_error:
LOGGER.exception('Invalid port value: {}'.format(port), exc_info=value_error)

Expand All @@ -42,5 +42,5 @@
patch_multiprocessing=True,
stdoutToServer=True,
stderrToServer=True)
except Exception as pydevd_connection_exception:
except Exception as pydevd_connection_exception: # pylint: disable=W0703
LOGGER.exception('Unable to connect to pydevd. Ignoring...', exc_info=pydevd_connection_exception)
4 changes: 2 additions & 2 deletions legion/legion/edi/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def build_model(args):
container = legion.pymodel.Model.load(external_reader.path)
model_id = container.model_id

image_labels = legion.containers.docker.generate_docker_labels_for_image(external_reader.path, model_id, args)
image_labels = legion.containers.docker.generate_docker_labels_for_image(external_reader.path, model_id)

LOGGER.info('Building docker image...')
image = legion.containers.docker.build_docker_image(
Expand All @@ -77,7 +77,7 @@ def build_model(args):
return image


def inspect_kubernetes(args):
def inspect_kubernetes(args): # pylint: disable=R0912
"""
Inspect kubernetes
Expand Down
4 changes: 2 additions & 2 deletions legion/legion/edi/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def get_security_params_from_config():
config_parser.read(str(config_path))

return dict(config_parser['security'])
except Exception as e:
LOG.debug('Exception during parsing of legion config {}'.format(e), exc_info=True)
except Exception as exception: # pylint: disable=W0703
LOG.debug('Exception during parsing of legion config {}'.format(exception), exc_info=True)

return {}

Expand Down
17 changes: 10 additions & 7 deletions legion/legion/edi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@
from datetime import datetime, timedelta

import jwt

from flask import Flask, Blueprint, render_template, request
from flask import current_app as app

import legion.config
import legion.external.grafana
import legion.http
import legion.k8s
import legion.model
from flask import Flask, Blueprint, render_template, request
from flask import current_app as app


LOGGER = logging.getLogger(__name__)
blueprint = Blueprint('apiserver', __name__)
blueprint = Blueprint('apiserver', __name__) # pylint: disable=C0103
TEMPLATES_FOLDER = os.path.abspath(os.path.join(
os.path.dirname(__file__), os.pardir, 'templates', 'edi')
)
) # pylint: disable=C0330
AUTH_COOKIE_NAME = '_oauth2_proxy'

EDI_VERSION = '1.0'
Expand Down Expand Up @@ -81,7 +84,7 @@ def authenticate(user, password):

return False

# TODO: Add LDAP authorisation
# TODO: Add LDAP authorisation # pylint:disable=W0511
return False


Expand Down Expand Up @@ -293,7 +296,7 @@ def inspect(model=None, version=None):
try:
model_api_info['result'] = model_client.info()
model_api_ok = True
except Exception as model_api_exception:
except Exception as model_api_exception: # pylint: disable=W0703
LOGGER.error('Cannot connect to model <{}> endpoint to get info: {}'.format(model_service,
model_api_exception))
model_api_info['exception'] = str(model_api_exception)
Expand Down Expand Up @@ -445,5 +448,5 @@ def serve(args):
use_reloader=False)

return application
except Exception as run_exception:
except Exception as run_exception: # pylint: disable=W0703
LOGGER.exception('EDI server exited with exception', exc_info=run_exception)
2 changes: 1 addition & 1 deletion legion/legion/edi/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
set_log_level()
redirect_to_stdout()

application = init_application()
application = init_application() # pylint: disable=C0103
14 changes: 8 additions & 6 deletions legion/legion/external/edi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import os
from urllib.parse import urlparse

import requests
import requests.exceptions

import legion.k8s
import legion.edi.server
import legion.config
import requests
import requests.exceptions
from legion.edi import security

LOGGER = logging.getLogger(__name__)
Expand All @@ -53,7 +54,7 @@ def __init__(self, base, token=None, retries=3):
self._version = legion.edi.server.EDI_VERSION
self._retries = retries

def _request(self, action, url, data=None, headers=None, cookies=None):
def _request(self, action, url, data=None, headers=None, cookies=None): # pylint: disable=R0201, R0913
"""
Make HTTP request
:param action: request action, e.g. get / post / delete
Expand Down Expand Up @@ -173,7 +174,8 @@ def info(self):
"""
return self._query(legion.edi.server.EDI_INFO)

def deploy(self, image, model_iam_role=None, count=1, livenesstimeout=2, readinesstimeout=2):
def deploy(self, image, model_iam_role=None, count=1, livenesstimeout=2, # pylint: disable=R0913
readinesstimeout=2):
"""
Deploy API endpoint
Expand Down Expand Up @@ -250,7 +252,7 @@ def scale(self, model, count, version=None):

return self.parse_deployments(self._query(legion.edi.server.EDI_SCALE, action='POST', payload=payload))

def get_token(self, model_id, model_version):
def get_token(self, model_id, model_version): # pylint: disable=R1710
"""
Get API token
Expand Down Expand Up @@ -322,7 +324,7 @@ def build_client(args=None):
if not host:
try:
host = legion.k8s.Enclave(os.environ.get("NAMESPACE")).edi_service.url
except Exception:
except Exception: # pylint: disable=W0703
LOGGER.warning('Cannot get EDI URL from K8S API')

client = EdiClient(host, token)
Expand Down
5 changes: 3 additions & 2 deletions legion/legion/external/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import logging
import os

import requests

import legion.config
from legion.utils import render_template

import requests

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -79,7 +80,7 @@ def _query(self, url, payload=None, action='GET'):
if resp.status_code != 200:
raise Exception('Wrong answer for [url="{}", status="{}", text="{}"]'.format(
full_url, resp.status_code, resp.text)
)
) # pylint: disable=C0330

answer = resp.json()

Expand Down
23 changes: 12 additions & 11 deletions legion/legion/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
import functools
import os
import logging
from urllib.parse import parse_qs

import flask
from requests.compat import urlencode
from requests.utils import to_key_val_list

import legion.config
import legion.containers.headers
import legion.utils

import flask
from requests.compat import urlencode
from requests.utils import to_key_val_list
from urllib.parse import parse_qs

LOGGER = logging.getLogger(__name__)

Expand All @@ -40,15 +41,15 @@ def encode_http_params(data):
:type data: str or bytes or tuple or list
:return: str -- encoded data
"""
if isinstance(data, (str, bytes)):
if isinstance(data, (str, bytes)): # pylint: disable=R1705
return urlencode(data)
elif hasattr(data, '__iter__'):
result = []
for k, vs in to_key_val_list(data):
if vs is not None:
for key, value in to_key_val_list(data):
if value is not None:
result.append(
(k.encode('utf-8') if isinstance(k, str) else k,
vs.encode('utf-8') if isinstance(vs, str) else vs))
(key.encode('utf-8') if isinstance(key, str) else key,
value.encode('utf-8') if isinstance(value, str) else value))
return urlencode(result, doseq=True)
else:
raise ValueError('Invalid argument')
Expand Down Expand Up @@ -122,7 +123,7 @@ def parse_request(input_request):
:type input_request: :py:class:`Flask.request`
:return: dict with requested fields
"""
if input_request.method == 'GET':
if input_request.method == 'GET': # pylint: disable=R1705
return parse_multi_dict(input_request.args)
elif input_request.method == 'POST':
return {
Expand Down Expand Up @@ -178,7 +179,7 @@ def decorated_function(*args, **kwargs):
response = {'status': response}
elif not isinstance(response, dict) and not isinstance(response, list):
raise Exception('Wrong value returned from API handler')
except Exception as exception:
except Exception as exception: # pylint: disable=W0703
code = 500
response = {'error': True,
'exception': str(exception)}
Expand Down
6 changes: 3 additions & 3 deletions legion/legion/k8s/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, model_id, model_version):
self._version = model_version

@property
def id(self):
def id(self): # pylint: disable=C0103
"""
Get model ID
Expand Down Expand Up @@ -120,12 +120,12 @@ def __hash__(self):
__str__ = __repr__


class ModelDeploymentDescription:
class ModelDeploymentDescription: # pylint: disable=R0902
"""
Holder for model deployment description
"""

def __init__(self,
def __init__(self, # pylint: disable=R0913
status,
model, version,
image,
Expand Down
6 changes: 3 additions & 3 deletions legion/legion/k8s/enclave.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ def _validate_model_properties_storage(self, model_id, model_version, default_va
.format(missed_property, default_values[missed_property]))
else:
LOGGER.info('Creating properties storage {!r} for model {!r} with default values'.format(storage, model_id))
for k, v in default_values.items():
for k, v in default_values.items(): # pylint: disable=C0103
storage[k] = v
LOGGER.info('Property {!r} has been set to default value {!r}'.format(k, v))
storage.save()

def deploy_model(self, image, model_iam_role=None, count=1, livenesstimeout=2, readinesstimeout=2):
def deploy_model(self, image, model_iam_role=None, count=1, livenesstimeout=2, readinesstimeout=2): # pylint: disable=R0913,R0914
"""
Deploy new model. Return True if model is deployed
Expand Down Expand Up @@ -469,7 +469,7 @@ def normalize_endpoints(endpoints_to_normalize):
for endpoint in endpoints_to_normalize:
model_id = endpoint.model_service.id

# TODO: Change in future, add default model choosing algorithm
# TODO: Change in future, add default model choosing algorithm # pylint: disable=W0511
default_endpoints_models[model_id] = endpoint
result.append(endpoint)

Expand Down
Loading

0 comments on commit 5c93f4f

Please sign in to comment.