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 e50eeae
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 59 deletions.
12 changes: 6 additions & 6 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():
"""
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,8 +73,8 @@ def get_current_docker_container_id():
:return: str -- current container id
"""
with open('/proc/self/cgroup') as f:
lines = [line.strip('\n') for line in f]
with open('/proc/self/cgroup') as file:
lines = [line.strip('\n') for line in file]
longest_line = max(lines, key=len)
return get_docker_container_id_from_cgroup_line(longest_line)

Expand Down Expand Up @@ -208,7 +208,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, _ = client.images.build(
tag=docker_image_tag,
nocache=True,
path=temp_directory.path,
Expand All @@ -224,7 +224,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
2 changes: 1 addition & 1 deletion legion/legion/docker_bootup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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)
Expand Down
6 changes: 3 additions & 3 deletions legion/legion/edi/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def build_model(args):
:type args: :py:class:`argparse.Namespace`
:return: :py:class:`docker.model.Image` docker image
"""
client = legion.containers.docker.build_docker_client(args)
client = legion.containers.docker.build_docker_client()

with ExternalFileReader(args.model_file) as external_reader:
if not os.path.exists(external_reader.path):
Expand All @@ -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:
LOG.debug('Exception during parsing of legion config {}'.format(exception), exc_info=True)

return {}

Expand Down
15 changes: 9 additions & 6 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
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: 11 additions & 12 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 @@ -44,14 +45,13 @@ def encode_http_params(data):
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')
raise ValueError('Invalid argument')


def parse_multi_dict(multi_dict, map_func=None):
Expand Down Expand Up @@ -129,8 +129,7 @@ def parse_request(input_request):
**parse_multi_dict(input_request.form),
**parse_multi_dict(input_request.files, lambda file: file.read())
}
else:
raise ValueError('Unexpected http method: {}'.format(input_request.method))
raise ValueError('Unexpected http method: {}'.format(input_request.method))


def prepare_response(response_data, model_id=None, model_version=None, model_endpoint=None):
Expand Down
2 changes: 1 addition & 1 deletion 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
6 changes: 3 additions & 3 deletions legion/legion/pymodel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def invoke(self, input_vector):
data_frame = legion.model.types.build_df(self.column_types, input_vector, not self.use_df)

LOGGER.info('Running prepare with DataFrame: %r' % data_frame)
data_frame = self.prepare(data_frame)
data_frame = self.prepare(data_frame) # pylint: disable=E1102

LOGGER.info('Applying function with DataFrame: %s' % str(data_frame))
response = self.apply(data_frame)
response = self.apply(data_frame) # pylint: disable=E1102
LOGGER.info('Returning response: %s' % str(response))

return response
Expand Down Expand Up @@ -439,7 +439,7 @@ def _export(self, apply_func, prepare_func, column_types, use_df, endpoint_name)
raise Exception('Bad param_types / input_data_frame provided')

if prepare_func is None:
def prepare_func(input_dict):
def prepare_func(input_dict): # pylint: disable=E0102
"""
Return input value (default prepare function)
:param input_dict: dict of values
Expand Down
10 changes: 5 additions & 5 deletions legion/legion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import contextlib
import os
import getpass
import distutils.dir_util
import distutils.dir_util # pylint: disable=E0611,E0401
import re
import logging
import shutil
Expand All @@ -33,13 +33,13 @@
import zipfile
import inspect

import legion.config
import legion.containers.headers

import requests
import requests.auth
from jinja2 import Environment, PackageLoader, select_autoescape

import legion.config
import legion.containers.headers


KUBERNETES_STRING_LENGTH_LIMIT = 63
LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -593,7 +593,7 @@ def get_installed_packages():
import pkg_resources
return sorted([
(item.key, item.version)
for item in pkg_resources.working_set
for item in pkg_resources.working_set # pylint: disable=E1133
], key=lambda item: item[0])


Expand Down
8 changes: 4 additions & 4 deletions legion/tests/legion_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def response_catcher(*args, **kwargs):

# This helps to emulate kubernetes exception
if isinstance(current_test_resource_name, BaseException):
raise current_test_resource_name
raise current_test_resource_name # pylint: disable=E0702

searched_files = glob.glob('{}/{}.*.{}.json'.format(TEST_RESPONSES_LOCATION, function,
current_test_resource_name))
Expand Down Expand Up @@ -264,7 +264,7 @@ def __init__(self, image, port):
:type port: int
"""

self._docker_client = legion.containers.docker.build_docker_client(None)
self._docker_client = legion.containers.docker.build_docker_client()
self._image = image
self._port = port

Expand Down Expand Up @@ -373,7 +373,7 @@ def __init__(self,
self._docker_tag = 'legion/base-python-image:{}'.format(self._docker_image_version)
self._docker_base_image = None
self._docker_container = None
self._docker_client = legion.containers.docker.build_docker_client(None)
self._docker_client = legion.containers.docker.build_docker_client()
self._docker_volume = None

# Legion python package
Expand Down Expand Up @@ -782,7 +782,7 @@ def __init__(self, model_image):
:type model_image: str
"""
self._image_id = model_image
self._docker_client = legion.containers.docker.build_docker_client(None)
self._docker_client = legion.containers.docker.build_docker_client()

self._image = self._docker_client.images.get(self._image_id)

Expand Down
4 changes: 2 additions & 2 deletions legion/tests/test_utils_external_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def test_resource_type_detection(self):
with self.assertRaisesRegex(Exception, 'Unknown or unavailable resource'):
utils.is_local_resource(path)

@responses.activate
@responses.activate # pylint: disable=E1101
def _test_external_file_reader(self, url):
body = 'Example' * 200
responses.add('GET', url, body=body, stream=True)
responses.add('GET', url, body=body, stream=True) # pylint: disable=E1101

with utils.ExternalFileReader(url) as reader:
self.assertTrue(os.path.exists(reader.path))
Expand Down
7 changes: 2 additions & 5 deletions legion_airflow/legion_airflow/auth/dex_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@

from sys import version_info

import flask_login
from flask_login import (current_user,
logout_user,
login_required,
login_user)
import flask_login # pylint: disable=E0401
from flask_login import current_user, logout_user, login_required, login_user # pylint: disable=W0611,E0401

from flask import flash

Expand Down
Loading

0 comments on commit e50eeae

Please sign in to comment.