Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Commit

Permalink
Run autopep8 on public python codebase to make travis happy
Browse files Browse the repository at this point in the history
pip3 install --user autopep8
find . -name *.py | xargs -n1 ~/.local/bin/autopep8 --aggressive
--in-place --max-line-length 100

Change-Id: I7afbf5621b987255d31823fd8f1ca35e2406fe92
  • Loading branch information
Peter Malkin committed Jan 16, 2018
1 parent 4f4d572 commit 756e10c
Show file tree
Hide file tree
Showing 34 changed files with 1,908 additions and 1,887 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ before_install:
- sudo apt-get install -y python3-numpy python3-scipy

install:
- pip3 install pep8 pyflakes coverage
- pip3 install pyflakes coverage pycodestyle
- pip3 install -r requirements.txt

script:
- pep8 --max-line-length=100 .
- pycodestyle --max-line-length=100 --exclude=*_pb2.py .
- nosetests --with-coverage

after_success:
Expand Down
3 changes: 2 additions & 1 deletion checkpoints/check_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

RECORD_DURATION_SECONDS = 3


def get_sound_cards():
"""Read a dictionary of ALSA cards from /proc, indexed by number."""
cards = {}
Expand Down Expand Up @@ -159,4 +160,4 @@ def main():
input('Press Enter to close...')
except Exception: # pylint: disable=W0703
traceback.print_exc()
input('Press Enter to close...')
input('Press Enter to close...')
2 changes: 1 addition & 1 deletion checkpoints/check_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ def main():
try:
main()
input('Press Enter to close...')
except: # pylint: disable=bare-except
except Exception:
traceback.print_exc()
input('Press Enter to close...')
2 changes: 1 addition & 1 deletion checkpoints/check_wifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ def main():
try:
main()
input('Press Enter to close...')
except: # pylint: disable=bare-except
except Exception:
traceback.print_exc()
input('Press Enter to close...')
3 changes: 2 additions & 1 deletion src/aiy/_apis/_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ def _stop_sending_audio(self, resp):
resp.speech_event_type)
logger.info('endpointer_type: %s', speech_event_type)

END_OF_SINGLE_UTTERANCE = types.StreamingRecognizeResponse.SpeechEventType.Value('END_OF_SINGLE_UTTERANCE')
END_OF_SINGLE_UTTERANCE = types.StreamingRecognizeResponse.SpeechEventType.Value(
'END_OF_SINGLE_UTTERANCE')
return resp.speech_event_type == END_OF_SINGLE_UTTERANCE

def _handle_response(self, resp):
Expand Down
12 changes: 5 additions & 7 deletions src/aiy/_drivers/_buzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def _wait_for_access(self, path):
if not os.access(path, os.W_OK):
raise IOError('Could not open %s' % path)


def _pwrite_int(self, path, data):
"""Helper method to quickly write a value to a sysfs node.
Expand Down Expand Up @@ -131,7 +130,7 @@ def _export_pwm(self):
"""
try:
self._pwrite_int(self.PWM_SOFT_EXPORT_PATH, self.gpio)
except:
except BaseException:
self._exported = False
raise

Expand All @@ -141,30 +140,29 @@ def _export_pwm(self):
try:
self._wait_for_access(period_path)
self._period_fh = open(period_path, 'w')
except:
except BaseException:
self._unexport_pwm()
raise

pulse_path = self._make_pwm_path(self.gpio) + '/pulse'
try:
self._wait_for_access(pulse_path)
self._pulse_fh = open(pulse_path, 'w')
except:
except BaseException:
self._unexport_pwm()
raise


def _unexport_pwm(self):
"""Unexports the given GPIO from the pwm-soft driver.
This effectively reverses _export_pwm by closing the two file handles it
previously opened, and then unexporting the given gpio.
"""
if self._exported:
if self._period_fh != None:
if self._period_fh is not None:
self._period_fh.close()

if self._pulse_fh != None:
if self._pulse_fh is not None:
self._pulse_fh.close()

self._pwrite_int(self.PWM_SOFT_UNEXPORT_PATH, self.gpio)
Expand Down
40 changes: 22 additions & 18 deletions src/aiy/_drivers/_hat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,32 @@
3: 'Voice Bonnet',
}


def _is_hat_attached():
return os.path.exists(HAT_PATH)
return os.path.exists(HAT_PATH)


def _get_hat_product():
with open(os.path.join(HAT_PATH, 'product')) as f:
return f.readline().strip()
with open(os.path.join(HAT_PATH, 'product')) as f:
return f.readline().strip()


def _get_hat_product_id():
with open(os.path.join(HAT_PATH, 'product_id')) as f:
matches = HAT_PRODUCT_ID_RE.match(f.readline().strip())
if matches:
return int(matches.group(0), 16)
with open(os.path.join(HAT_PATH, 'product_id')) as f:
matches = HAT_PRODUCT_ID_RE.match(f.readline().strip())
if matches:
return int(matches.group(0), 16)


def get_aiy_device_name():
if not _is_hat_attached():
return None
product = _get_hat_product()
if not 'AIY' in product:
return None
product_id = _get_hat_product_id()
if not product_id:
return None
if not product_id in AIY_HATS:
return None
return AIY_HATS[product_id]
if not _is_hat_attached():
return None
product = _get_hat_product()
if 'AIY' not in product:
return None
product_id = _get_hat_product_id()
if not product_id:
return None
if product_id not in AIY_HATS:
return None
return AIY_HATS[product_id]
Loading

0 comments on commit 756e10c

Please sign in to comment.