diff --git a/.travis.yml b/.travis.yml
index 179c5713e6..c9c24b14a9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,7 +20,7 @@ install:
- pip install -r test-requirements.txt
# command to run tests
script:
- - pep8 mycroft test
+ - pycodestyle mycroft test
- ./start-mycroft.sh unittest
env:
- IS_TRAVIS=true
diff --git a/dev_setup.sh b/dev_setup.sh
index 99188f1a2f..d0197ecb47 100755
--- a/dev_setup.sh
+++ b/dev_setup.sh
@@ -369,8 +369,8 @@ source "${VIRTUALENV_ROOT}/bin/activate"
cd "${TOP}"
# Install pep8 pre-commit hook
-if [ -z ${INSTALL_PRECOMMIT_HOOK} ] ; then
- HOOK_FILE="./.git/hooks/pre-commit"
+HOOK_FILE="./.git/hooks/pre-commit"
+if [ ! -z ${INSTALL_PRECOMMIT_HOOK+x} ] || grep -q "MYCROFT DEV SETUP" ${HOOK_FILE}; then
if [ ! -f ${HOOK_FILE} ] || grep -q "MYCROFT DEV SETUP" ${HOOK_FILE} ; then
echo "Installing PEP8 check as precommit-hook"
echo "#! $( which python )" > ${HOOK_FILE}
diff --git a/mycroft/api/__init__.py b/mycroft/api/__init__.py
index dc2b041e0a..a0c219289c 100644
--- a/mycroft/api/__init__.py
+++ b/mycroft/api/__init__.py
@@ -171,7 +171,7 @@ class Api:
def get_data(self, response):
try:
return response.json()
- except:
+ except Exception:
return response.text
def build_headers(self, params):
@@ -331,7 +331,7 @@ class DeviceApi(Api):
"""
try:
return self.get_subscription().get('@type') != 'free'
- except:
+ except Exception:
# If can't retrieve, assume not paired and not a subscriber yet
return False
diff --git a/mycroft/audio/services/mopidy/__init__.py b/mycroft/audio/services/mopidy/__init__.py
index d9adb7821e..cfdaa1ff43 100644
--- a/mycroft/audio/services/mopidy/__init__.py
+++ b/mycroft/audio/services/mopidy/__init__.py
@@ -37,7 +37,7 @@ class MopidyService(RemoteAudioBackend):
url = self.config.get('url', url)
try:
self.mopidy = Mopidy(url)
- except:
+ except Exception:
if self.connection_attempts < 1:
LOG.debug('Could not connect to server, will retry quietly')
self.connection_attempts += 1
diff --git a/mycroft/audio/services/mopidy/mopidypost.py b/mycroft/audio/services/mopidy/mopidypost.py
index a9653e867e..9efd1dda43 100644
--- a/mycroft/audio/services/mopidy/mopidypost.py
+++ b/mycroft/audio/services/mopidy/mopidypost.py
@@ -53,11 +53,11 @@ class Mopidy:
d['method'] = 'core.library.search'
d['params'] = {'album': [album]}
r = requests.post(self.url, data=json.dumps(d))
- l = [res['albums'] for res in r.json()['result'] if 'albums' in res]
+ lst = [res['albums'] for res in r.json()['result'] if 'albums' in res]
if filter is None:
- return l
+ return lst
else:
- return [i for sl in l for i in sl if filter + ':' in i['uri']]
+ return [i for sl in lst for i in sl if filter + ':' in i['uri']]
def find_exact(self, uris='null'):
d = copy(_base_dict)
diff --git a/mycroft/messagebus/service/ws.py b/mycroft/messagebus/service/ws.py
index 7a5e3b3133..272979eb49 100644
--- a/mycroft/messagebus/service/ws.py
+++ b/mycroft/messagebus/service/ws.py
@@ -41,7 +41,7 @@ class WebsocketEventHandler(tornado.websocket.WebSocketHandler):
# LOG.debug(message)
try:
deserialized_message = Message.deserialize(message)
- except:
+ except Exception:
return
try:
diff --git a/mycroft/stt/__init__.py b/mycroft/stt/__init__.py
index f05ef7df71..4cb48de529 100644
--- a/mycroft/stt/__init__.py
+++ b/mycroft/stt/__init__.py
@@ -132,7 +132,7 @@ class MycroftSTT(STT):
try:
return self.api.stt(audio.get_flac_data(convert_rate=16000),
self.lang, 1)[0]
- except:
+ except Exception:
return self.api.stt(audio.get_flac_data(), self.lang, 1)[0]
@@ -179,7 +179,7 @@ class KaldiSTT(STT):
try:
hypotheses = response.json()["hypotheses"]
return re.sub(r'\s*\[noise\]\s*', '', hypotheses[0]["utterance"])
- except:
+ except Exception:
return None
diff --git a/mycroft/tts/__init__.py b/mycroft/tts/__init__.py
index 73735ab775..43c26bf7fc 100644
--- a/mycroft/tts/__init__.py
+++ b/mycroft/tts/__init__.py
@@ -72,7 +72,7 @@ class PlaybackThread(Thread):
self.queue.get()
try:
self.p.terminate()
- except:
+ except Exception:
pass
def run(self):
@@ -386,7 +386,7 @@ class TTS:
with open(pho_file, "r") as cachefile:
phonemes = cachefile.read().strip()
return phonemes
- except:
+ except Exception:
LOG.debug("Failed to read .PHO from cache")
return None
diff --git a/mycroft/tts/espeak_tts.py b/mycroft/tts/espeak_tts.py
index 5110e8666c..e9ceeb60b5 100644
--- a/mycroft/tts/espeak_tts.py
+++ b/mycroft/tts/espeak_tts.py
@@ -39,7 +39,7 @@ class ESpeakValidator(TTSValidator):
def validate_connection(self):
try:
subprocess.call(['espeak', '--version'])
- except:
+ except Exception:
raise Exception(
'ESpeak is not installed. Run: sudo apt-get install espeak')
diff --git a/mycroft/tts/fa_tts.py b/mycroft/tts/fa_tts.py
index fcdcdee55f..147a8c8407 100644
--- a/mycroft/tts/fa_tts.py
+++ b/mycroft/tts/fa_tts.py
@@ -54,7 +54,7 @@ class FATTSValidator(TTSValidator):
content = resp.json()
if content.get('product', '').find('FA-TTS') < 0:
raise Exception('Invalid FA-TTS server.')
- except:
+ except Exception:
raise Exception(
'FA-TTS server could not be verified. Check your connection '
'to the server: ' + self.tts.url)
diff --git a/mycroft/tts/google_tts.py b/mycroft/tts/google_tts.py
index 1c7e95bfdb..6dc0778cb2 100644
--- a/mycroft/tts/google_tts.py
+++ b/mycroft/tts/google_tts.py
@@ -39,7 +39,7 @@ class GoogleTTSValidator(TTSValidator):
def validate_connection(self):
try:
gTTS(text='Hi').save(self.tts.filename)
- except:
+ except Except:
raise Exception(
'GoogleTTS server could not be verified. Please check your '
'internet connection.')
diff --git a/mycroft/tts/mary_tts.py b/mycroft/tts/mary_tts.py
index d4709c69ff..993bfeaeaf 100644
--- a/mycroft/tts/mary_tts.py
+++ b/mycroft/tts/mary_tts.py
@@ -53,7 +53,7 @@ class MaryTTSValidator(TTSValidator):
resp = requests.get(self.tts.url + "/version", verify=False)
if resp.content.find('Mary TTS server') < 0:
raise Exception('Invalid MaryTTS server.')
- except:
+ except Exception:
raise Exception(
'MaryTTS server could not be verified. Check your connection '
'to the server: ' + self.tts.url)
diff --git a/mycroft/tts/mimic_tts.py b/mycroft/tts/mimic_tts.py
index 4848dfc248..303a4e41d2 100644
--- a/mycroft/tts/mimic_tts.py
+++ b/mycroft/tts/mimic_tts.py
@@ -168,7 +168,7 @@ class MimicValidator(TTSValidator):
def validate_connection(self):
try:
subprocess.call([BIN, '--version'])
- except:
+ except Exception:
LOG.info("Failed to find mimic at: " + BIN)
raise Exception(
'Mimic was not found. Run install-mimic.sh to install it.')
diff --git a/mycroft/tts/spdsay_tts.py b/mycroft/tts/spdsay_tts.py
index 53a323a1cb..7aac241920 100644
--- a/mycroft/tts/spdsay_tts.py
+++ b/mycroft/tts/spdsay_tts.py
@@ -39,7 +39,7 @@ class SpdSayValidator(TTSValidator):
def validate_connection(self):
try:
subprocess.call(['spd-say', '--version'])
- except:
+ except Exception:
raise Exception(
'SpdSay is not installed. Run: sudo apt-get install '
'speech-dispatcher')
diff --git a/scripts/pre-commit b/scripts/pre-commit
index d0cf54185e..01affc6d43 100755
--- a/scripts/pre-commit
+++ b/scripts/pre-commit
@@ -13,7 +13,7 @@ import tempfile
# don't fill in both of these
select_codes = []
ignore_codes = ["E121", "E122", "E123", "E124", "E125", "E126", "E127", "E128",
- "E129", "E501", "E722", "E226"]
+ "E129", "E501", "E722", "E226", "W504"]
# Add things like "--max-line-length=120" below
overrides = []
@@ -40,7 +40,10 @@ def main():
with open(filename, 'w') as f:
system('git', 'show', ':' + name, stdout=f)
- args = ['pep8']
+ checker_path = os.path.join(os.path.dirname(__file__),
+ '..', '..', '.venv', 'bin', 'pycodestyle')
+ checker_path = os.path.abspath(checker_path)
+ args = [checker_path]
if select_codes and ignore_codes:
print(u'Error: select and ignore codes are mutually exclusive')
sys.exit(1)
diff --git a/test-requirements.txt b/test-requirements.txt
index 8ada8157c9..68b6937b91 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,4 +1,4 @@
-pep8==1.7.0
+pycodestyle===2.5.0
coveralls==1.5.0
pytest==3.5.0
pytest-cov==2.5.1
diff --git a/test/unittests/tts/test_tts.py b/test/unittests/tts/test_tts.py
index efb74ed1e9..63da8b69a5 100644
--- a/test/unittests/tts/test_tts.py
+++ b/test/unittests/tts/test_tts.py
@@ -44,7 +44,7 @@ class TestTTS(unittest.TestCase):
"a lower pitch preferable?"
sentence_bad_ssml = "" + sentence + \
""
- sentence_extra_ssml = "whisper tts<\whispered>"
+ sentence_extra_ssml = "whisper tts<\\whispered>"
# test valid ssml
tts = TestTTS("en-US", {}, TestTTSValidator(None),
diff --git a/test/unittests/util/test_format_it.py b/test/unittests/util/test_format_it.py
index 60a5abbc45..b8fe4c7a8f 100644
--- a/test/unittests/util/test_format_it.py
+++ b/test/unittests/util/test_format_it.py
@@ -353,5 +353,6 @@ class TestPronounceNumber(unittest.TestCase):
self.assertEqual(pronounce_number(float("-inf"),
lang="it"), "meno infinito")
+
if __name__ == "__main__":
unittest.main()