Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint in CI #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[flake8]
max-line-length = 160
exclude =
**/pulse_utils/pulse_lib.py
kuri_slack_bot/app.py
max-complexity = 20
# We import modules here to make the API cleaner
per-file-ignores =
**/kuri_api/lights.py:W293
**/kuri_api/__init__.py:F401
**/kuri_navigation/__init__.py:F401
**/anim/__init__.py:F401
**/utils/__init__.py:F401
**/kuri_api/base.py:N801
28 changes: 24 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@ on: [push, pull_request]

jobs:
industrial_ci:
env:
AFTER_INSTALL_TARGET_DEPENDENCIES: 'pip2 install --upgrade pip && pip2 install --upgrade "setuptools<0.45"'
CATKIN_LINT: true
ROS_REPO: main
strategy:
matrix:
env:
- {ROS_DISTRO: indigo, ROS_REPO: main}
- {ROS_DISTRO: indigo}
- {ROS_DISTRO: noetic}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: 'ros-industrial/industrial_ci@master'
env: ${{matrix.env}}
- uses: actions/checkout@v2
- uses: 'ros-industrial/industrial_ci@master'
env: ${{matrix.env}}
continue-on-error: ${{ matrix.env.ROS_DISTRO == 'noetic' }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 2.7
- name: Install dependencies
run: |
pip install flake8 pep8-naming
- name: Lint
run: |
flake8 -v
3 changes: 3 additions & 0 deletions audio_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ generate_messages(

catkin_package(
CATKIN_DEPENDS
geometry_msgs
mayfield_msgs
message_runtime
std_msgs
)

Expand Down
2 changes: 1 addition & 1 deletion gizmo_description/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.8.3)
project(gizmo_description)

find_package(catkin)
find_package(catkin REQUIRED COMPONENTS)

catkin_package()
11 changes: 3 additions & 8 deletions kuri_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ generate_messages(
)

catkin_package(
# INCLUDE_DIRS include
# LIBRARIES robot_api
CATKIN_DEPENDS roscpp rospy
CATKIN_DEPENDS message_runtime roscpp rospy std_msgs
)

catkin_install_python(PROGRAMS scripts/base_demo scripts/volume_interface
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})


include_directories(
include
${catkin_INCLUDE_DIRS}
)
12 changes: 8 additions & 4 deletions kuri_api/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
<name>kuri_api</name>
<version>0.1.0</version>
<description>High-level API for controlling the Kuri robot.</description>
<maintainer email="nwalker@cs.uw.edu">Nick Walker</maintainer>
<maintainer email="nswalker@cs.uw.edu">Nick Walker</maintainer>
<license>None</license>
<buildtool_depend>catkin</buildtool_depend>
<depend>actionlib</depend>
<depend>control_msgs</depend>

<exec_depend>actionlib</exec_depend>
<depend>roscpp</depend>
<depend>rospy</depend>
<depend>trajectory_msgs</depend>
<exec_depend>trajectory_msgs</exec_depend>

<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
<depend>std_msgs</depend>
<export>
</export>
</package>
4 changes: 2 additions & 2 deletions kuri_api/setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD
# DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

# fetch values from package.xml
setup_args = generate_distutils_setup(
packages=['kuri_api','assets'],
packages=['kuri_api', 'assets'],
package_dir={'': 'src'})

setup(**setup_args)
11 changes: 6 additions & 5 deletions kuri_api/src/assets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .memoize import memoize
from .mov import img_to_pix, mov_to_wav, mov_to_pixels, pixel_positions

__all__ = [
'memoize',
'img_to_pix',
'mov_to_wav',
'mov_to_pixels',
'pixel_positions']
'memoize',
'img_to_pix',
'mov_to_wav',
'mov_to_pixels',
'pixel_positions']
1 change: 1 addition & 0 deletions kuri_api/src/assets/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os


def get_data_path():
"""
Return the data path for either the GBZ or a development workspace.
Expand Down
14 changes: 9 additions & 5 deletions kuri_api/src/assets/memoize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import functools, hashlib, os, cPickle as pickle
import cPickle
import functools
import hashlib
import os


def _sha1(s):
return hashlib.sha1(s).hexdigest()
Expand All @@ -14,7 +18,7 @@ def _store(cache_dir, key, val):
if not os.path.isdir(objd):
os.makedirs(objd)
with open(os.path.join(objd, hash[2:]), 'w') as (f):
pickle.dump(val, f)
cPickle.dump(val, f)


def _load(cache_dir, key):
Expand All @@ -24,12 +28,12 @@ def _load(cache_dir, key):
hash = _keyhash(key)
objd = os.path.join(cache_dir, hash[:2])
with open(os.path.join(objd, hash[2:])) as (f):
return pickle.load(f)
return cPickle.load(f)


def memoize(root_dir):
""" A better memoize:
- pickle objects instead of yaml
- cPickle objects instead of yaml
- one file per object instead of a big dict
- objects are lazily loaded from disk when first used
"""
Expand All @@ -41,7 +45,7 @@ def memoize_helper(f):

@functools.wraps(f)
def cached(*args, **kwargs):
key = ('{}{}{}').format(f.func_name, pickle.dumps(args), pickle.dumps(kwargs))
key = '{}{}{}'.format(f.func_name, cPickle.dumps(args), cPickle.dumps(kwargs))
if key not in cache:
try:
cache[key] = _load(cache_dir, key)
Expand Down
24 changes: 15 additions & 9 deletions kuri_api/src/assets/mov.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import glob, os, subprocess
import glob
import os
import subprocess
from PIL import Image

import numpy as np

from . import config
from . import memoize

MOVIE_WIDTH_HEIGHT = 720

@memoize(lambda : config.get_assets_path())

@memoize(lambda: config.get_assets_path())
def mov_to_pixels(mov_name):
"""
These pixels are generated at build-time and cached through memoization.
Expand All @@ -14,7 +20,7 @@ def mov_to_pixels(mov_name):
return _pixels_for_file(mov_path)


@memoize(lambda : config.get_assets_path())
@memoize(lambda: config.get_assets_path())
def mov_to_wav(mov_name):
"""
These wavs are generated at build-time and cached through memoization.
Expand All @@ -32,10 +38,10 @@ def _pixels_for_file(mov_path):
_, fname = os.path.split(mov_path)
mov_name = os.path.splitext(fname)[0]
subprocess.call([
'avconv', '-y', '-i', mov_path, ('/tmp/{}%06d.png').format(mov_name)])
'avconv', '-y', '-i', mov_path, ('/tmp/{}%06d.png').format(mov_name)])
imgs_list = glob.glob(('/tmp/{}*.png').format(mov_name))
imgs_list.sort()
pixels = [ img_to_pix(img_name) for img_name in imgs_list ]
pixels = [img_to_pix(img_name) for img_name in imgs_list]
for img_name in imgs_list:
subprocess.call(['rm', img_name])

Expand All @@ -53,8 +59,8 @@ def _wav_for_file(mov_path):
wav_name = os.path.splitext(mov_name)[0] + '.wav'
wav_loc = os.path.join(config.get_sounds_path(), wav_name)
ret = subprocess.call([
'avconv', '-y', '-i', mov_path, '-vn', '-ar', '48000', '-ac', '2',
'-ab', '192', '-f', 'wav', wav_loc])
'avconv', '-y', '-i', mov_path, '-vn', '-ar', '48000', '-ac', '2',
'-ab', '192', '-f', 'wav', wav_loc])
if ret:
raise RuntimeError(('Unable to convert {} to wav at {}.').format(mov_path, wav_loc))
return wav_name
Expand All @@ -67,7 +73,7 @@ def _add_pixel_ring(width, height, count, radius, angle):
for i in range(count):
a = float(angle) + float(i) * 2 * np.pi / float(count)
pixels.append((int(x - float(radius) * np.cos(a) + 0.5),
int(y - float(radius) * np.sin(a) + 0.5)))
int(y - float(radius) * np.sin(a) + 0.5)))

return pixels

Expand All @@ -84,4 +90,4 @@ def pixel_positions():
def img_to_pix(fname):
pixels = pixel_positions()
img = Image.open(fname)
return [ img.getpixel(p) for p in pixels ]
return [img.getpixel(p) for p in pixels]
2 changes: 1 addition & 1 deletion kuri_api/src/kuri_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .listener import Listener
from .power import PowerMonitor
from .voice import Voice
from .volume import Volume
from .volume import Volume
8 changes: 5 additions & 3 deletions kuri_api/src/kuri_api/alive.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import random
from threading import Lock, RLock
import time
from kuri_api.utils.timeouts import EventTimeout
from threading import Lock, RLock

from kuri_api.anim import AnimationPlayer
from kuri_api.anim.library.blink_animations import BlinkAnimations
from kuri_api.utils.timeouts import EventTimeout


class Alive(object):
"""
Expand Down Expand Up @@ -127,4 +129,4 @@ def _kill_timer(self, blocking=False):
if self._blink_timer:
self._blink_timer.shutdown(blocking=blocking)
self._blink_timer = None
return
return
4 changes: 2 additions & 2 deletions kuri_api/src/kuri_api/anim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .track import Track, TrackPlayer
from .animation_group import AnimationGroup
from .player import AnimationPlayer, LoopingAnimationPlayer
from .player import AnimationPlayer, LoopingAnimationPlayer
from .track import Track, TrackPlayer
7 changes: 4 additions & 3 deletions kuri_api/src/kuri_api/anim/animation_group.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from kuri_api.anim.primitives.head import HeadMotions
from kuri_api.anim.primitives.wheels import WheelMotions
from kuri_api.anim.primitives.light import Light
from kuri_api.anim.primitives.sound import Sound
from kuri_api.anim.primitives.movies import Movies
from kuri_api.anim.primitives.sound import Sound
from kuri_api.anim.primitives.wheels import WheelMotions


class AnimationGroup(object):
"""
Expand All @@ -24,4 +25,4 @@ def __init__(self, head=None, wheels=None, chest_leds=None, sound_srcs=None, mov
self.movies = Movies(lights=self.lights_mot, sound=self.sound_mot)
else:
self.movies = None
return
return
14 changes: 9 additions & 5 deletions kuri_api/src/kuri_api/anim/animator.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import logging
import threading

from gizmo.utils.animation import AnimationParser
from gizmo.utils.animation import AnimationTrackAssembler
from kuri_api.anim import Track
import logging

logger = logging.getLogger(__name__)


class Animator(object):

def __init__(self, comm_interface, head=None, wheels=None, sound_srcs=None, chest_leds=None):
self._lock = threading.RLock()
self.animation_assembler = AnimationTrackAssembler(head=head, wheels=wheels, sound_srcs=sound_srcs, chest_leds=chest_leds)
self.animation_assembler = AnimationTrackAssembler(head=head, wheels=wheels, sound_srcs=sound_srcs,
chest_leds=chest_leds)
self.currentTrackPlayer = None
return

Expand Down Expand Up @@ -37,8 +41,8 @@ def cancel(self, timeout=1.0):
return

def play_live_animation(self, command):
animationCommand = command
animation = AnimationParser.parse_animation(animationCommand.json)
animation_command = command
animation = AnimationParser.parse_animation(animation_command.json)
if animation is not None and not animation.hasParseErrors:
track = Track()
self.animation_assembler.add_animation_to_track(animation, track)
Expand All @@ -52,4 +56,4 @@ def play_animation_from_container_json(self, container_json, done_cb=None):
self._play_track(track, done_cb)

def shutdown(self):
self.cancel()
self.cancel()
Loading