From fce391ae90fc83260a420579343b2900db6de27d Mon Sep 17 00:00:00 2001 From: Shinya Ohyanagi Date: Mon, 23 Sep 2019 00:06:41 +0900 Subject: [PATCH 1/2] Add flake8 --- .travis.yml | 14 ++++++++-- mackerel/__init__.py | 1 + mackerel/client.py | 11 ++++---- mackerel/host.py | 16 +++++++++--- mackerel/runner.py | 3 ++- requirements.txt | 9 +++++++ setup.cfg | 15 +++++++++++ setup.py | 10 ++++--- tests/test_client.py | 62 ++++++++++++++++++++++++-------------------- tox.ini | 8 +++--- 10 files changed, 103 insertions(+), 46 deletions(-) create mode 100644 setup.cfg diff --git a/.travis.yml b/.travis.yml index ebe996a..909656a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,24 @@ +dist: xenial language: python +cache: + pip: true + directories: + - "$TRAVIS_BUILD_DIR/.tox" python: - 2.7 - 3.6 - 3.7 + - 3.8 env: global: MACKEREL_APIKEY='xxxxxxxx' -before_install: pip install -r requirements.txt +before_install: + - pip install -U -r requirements.txt +before_script: + - flake8 --verbose --jobs=8 -script: python setup.py test +script: + - python setup.py test diff --git a/mackerel/__init__.py b/mackerel/__init__.py index de40ea7..68c04af 100644 --- a/mackerel/__init__.py +++ b/mackerel/__init__.py @@ -1 +1,2 @@ +# -*- coding: utf-8 -*- __import__('pkg_resources').declare_namespace(__name__) diff --git a/mackerel/client.py b/mackerel/client.py index da1e110..44be228 100644 --- a/mackerel/client.py +++ b/mackerel/client.py @@ -13,6 +13,7 @@ :license: BSD, see LICENSE for more details. """ import logging + import requests import simplejson as json from mackerel.host import Host @@ -25,7 +26,7 @@ class MackerelClientError(Exception): class Client(object): #: Mackerel apikey error message. - ERROR_MESSAGE_FOR_API_KEY_ABSENCE = 'API key is absent. Set your API key in a environment variable called MACKEREL_APIKEY.' + ERROR_MESSAGE_FOR_API_KEY_ABSENCE = 'API key is absent. Set your API key in a environment variable called MACKEREL_APIKEY.' # noqa E501 #: Log format. debug_log_format = ( '[%(asctime)s %(levelname)s][%(pathname)s:%(lineno)d]: %(message)s' @@ -44,8 +45,7 @@ def __init__(self, logger=None, **kwargs): self.api_key = api_key if logger is None: - logging.basicConfig(level=logging.INFO, - format=self.debug_log_format) + logging.basicConfig(level=logging.INFO, format=self.debug_log_format) self.logger = logging.getLogger('mackerel.client') else: self.logger = logger @@ -176,8 +176,9 @@ def _request(self, uri, method='GET', headers=None, params=None): message = '{0} is not supported.'.format(method) raise NotImplementedError(message) - self.logger.debug('Response from {0} is {1}'.format(self.origin, - res.status_code)) + self.logger.debug( + 'Response from {0} is {1}'.format(self.origin, res.status_code), + ) if res.status_code != 200: message = '{0} {1} failed: {2}'.format(method, uri, res.status_code) raise MackerelClientError(message) diff --git a/mackerel/host.py b/mackerel/host.py index c6d27e1..0967376 100644 --- a/mackerel/host.py +++ b/mackerel/host.py @@ -57,10 +57,20 @@ def mac_addr(self): return i['macAddress'] def __repr__(self): + """Host instance.""" repr = ' Date: Mon, 23 Sep 2019 00:10:30 +0900 Subject: [PATCH 2/2] Fix oops Python3.8 not released yet --- .travis.yml | 1 - tox.ini | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 909656a..ef8a475 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ python: - 2.7 - 3.6 - 3.7 - - 3.8 env: global: diff --git a/tox.ini b/tox.ini index ebc0513..1b3c5de 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py36,py37,py38,flake8 +envlist = py27,py36,py37,flake8 [testenv] commands=python setup.py test