From e57223f1a87526bf4f6129e3f835e542dda3b30a Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 15 Aug 2018 15:18:33 +0200 Subject: [PATCH] Run flake8 linter on python code (#474) * Run-flake8-linter-on-Python-code * Remove hardware/unicorn/scripts/checklib.js --- .travis.yml | 13 +++++++++++++ hardware/unicorn/scripts/checklib.js | 13 ------------- hardware/unicorn/unihat.py | 18 ++++++++++++------ 3 files changed, 25 insertions(+), 19 deletions(-) delete mode 100755 hardware/unicorn/scripts/checklib.js diff --git a/.travis.yml b/.travis.yml index 19f43cb6..64e6741c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,19 @@ node_js: - "6" - "8" - "10" +matrix: + include: + - python: 2.7 + language: python + before_script: pip install flake8 + script: flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics + - python: 3.7 + language: python + dist: xenial # required for Python 3.7 (travis-ci/travis-ci#9069) + sudo: required # required for Python 3.7 (travis-ci/travis-ci#9069) + before_script: pip install flake8 + script: flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics + before_script: # Remove the './node_modules/.bin:' entry, see https://github.com/travis-ci/travis-ci/issues/8813 - npm i -g npm diff --git a/hardware/unicorn/scripts/checklib.js b/hardware/unicorn/scripts/checklib.js deleted file mode 100755 index 0ebb8a95..00000000 --- a/hardware/unicorn/scripts/checklib.js +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env node -var fs = require('fs'); - -if (!fs.existsSync('/usr/local/lib/python2.7/dist-packages/unicornhat.py')) { - console.warn("WARNING : Can't find required python library"); - console.warn("WARNING : Please install using the following command"); - console.warn("WARNING : Note: this uses root..."); - console.warn("WARNING : curl -sS get.pimoroni.com/unicornhat | bash\n"); - //process.exit(1); -} -else { - console.log("Python library found OK.\n") -} diff --git a/hardware/unicorn/unihat.py b/hardware/unicorn/unihat.py index 43a6648e..ea3dbb25 100755 --- a/hardware/unicorn/unihat.py +++ b/hardware/unicorn/unihat.py @@ -2,13 +2,19 @@ # Import library functions we need from __future__ import print_function -import sys -import os -import unicornhat as UH -if sys.version_info >= (3,0): - print("Sorry - currently only configured to work with python 2.x") - sys.exit(1) +import sys + +try: + import unicornhat as UH +except ImportError: + print("run: pip install --user --upgrade unicornhat\n before trying again.") + sys.exit(0) + +try: + raw_input # Python 2 +except NameError: + raw_input = input # Python 3 brightness = float(sys.argv[1])/100 UH.off()