Skip to content
代码片段 群组 项目
未验证 提交 b5dd562b 编辑于 作者: Leigh Johnson's avatar Leigh Johnson 提交者: GitHub
浏览文件

V1.0.8 flake8 (#4)

* lint donkey_car/, add flake8 to tox commands

* update credits in AUTHORS and setup.py, more flake8

* fix LICENSE autogen

* restrict flake8 to gym_donkeycar/

* more license + flake8 fixes
上级 2331a438
No related branches found
No related tags found
无相关合并请求
......@@ -2,13 +2,10 @@
Credits
=======
Release Engineer
----------------
* Leigh Johnson <leigh@data-literate.com>
Contributors
------------
* Tawn Kramer @tawnkramer (original source: https://github.com/tawnkramer/donkey_gym)
* Roma Sokolkov @r7vme (https://github.com/r7vme/donkey_gym)
* Leigh Johnson @leigh-johnson <leigh@data-literate.com>
......@@ -6,3 +6,14 @@ History
------------------
* First release on PyPI.
1.0.{1,7} (2019-08-04)
------------------
* Testing out deploy system
1.0.8 (2019-08-04)
------------------
* Update credits/authors
* flake8
\ No newline at end of file
MIT License
Copyright (c) 2019, Leigh Johnson
Copyright (c) 2018 Tawn Kramer
Copyright (c) 2018 Roma Sokolkov
Original Work Copyright (c) 2018 Tawn Kramer
Original Work Copyright (c) 2018 Roma Sokolkov
Modified Work Copyright (c) 2019, Leigh Johnson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
import time
class FPSTimer(object):
def __init__(self):
self.t = time.time()
......
......@@ -5,7 +5,6 @@ file: tcp_server.py
notes: a tcp socket server to talk to the unity donkey simulator
'''
import json
import time
import re
import asyncore
import socket
......@@ -57,36 +56,35 @@ class SimServer(asyncore.dispatcher):
def __init__(self, address, msg_handler):
asyncore.dispatcher.__init__(self)
#create a TCP socket to listen for connections
# create a TCP socket to listen for connections
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
#in case we have shutdown recently, allow the os to reuse this address. helps when restarting
# in case we have shutdown recently, allow the os to reuse this address.
# helps when restarting
self.set_reuse_addr()
#let TCP stack know that we'd like to sit on this address and listen for connections
# let TCP stack know that we'd like to sit on this address and listen for connections
self.bind(address)
#confirm for users what address we are listening on
# confirm for users what address we are listening on
self.address = self.socket.getsockname()
print('binding to', self.address)
#let tcp stack know we plan to process one outstanding request to connect request each loop
# let tcp stack know we plan to process one outstanding request to connect request each loop
self.listen(5)
#keep a pointer to our IMesgHandler handler
# keep a pointer to our IMesgHandler handler
self.msg_handler = msg_handler
def handle_accept(self):
# Called when a client connects to our socket
client_info = self.accept()
print('got a new client', client_info[1])
#make a new steering handler to communicate with the client
# make a new steering handler to communicate with the client
SimHandler(sock=client_info[0], msg_handler=self.msg_handler)
def handle_close(self):
print("server shutdown")
# Called then server is shutdown
......@@ -101,26 +99,25 @@ class SimHandler(asyncore.dispatcher):
Handles messages from a single TCP client.
"""
def __init__(self, sock, chunk_size=(16*1024), msg_handler=None):
#we call our base class init
def __init__(self, sock, chunk_size=(16 * 1024), msg_handler=None):
# we call our base class init
asyncore.dispatcher.__init__(self, sock=sock)
#msg_handler handles incoming messages
# msg_handler handles incoming messages
self.msg_handler = msg_handler
if msg_handler:
msg_handler.on_connect(self)
#chunk size is the max number of bytes to read per network packet
# chunk size is the max number of bytes to read per network packet
self.chunk_size = chunk_size
#we make an empty list of packets to send to the client here
# we make an empty list of packets to send to the client here
self.data_to_write = []
#and image bytes is an empty list of partial bytes of the image as it comes in
# and image bytes is an empty list of partial bytes of the image as it comes in
self.data_to_read = []
def writable(self):
"""
We want to write if we have received data.
......@@ -133,7 +130,6 @@ class SimHandler(asyncore.dispatcher):
json_msg = json.dumps(msg)
self.data_to_write.append(json_msg)
def handle_write(self):
"""
Write as much as possible of the most recent message we have received.
......@@ -141,22 +137,21 @@ class SimHandler(asyncore.dispatcher):
and when self.writable return true, that yes, we have data to send.
"""
#pop the first element from the list. encode will make it into a byte stream
# pop the first element from the list. encode will make it into a byte stream
data = self.data_to_write.pop(0).encode()
#send a slice of that data, up to a max of the chunk_size
# send a slice of that data, up to a max of the chunk_size
sent = self.send(data[:self.chunk_size])
#if we didn't send all the data..
# if we didn't send all the data..
if sent < len(data):
#then slice off the portion that remains to be sent
# then slice off the portion that remains to be sent
remaining = data[sent:]
#since we've popped it off the list, add it back to the list to send next
#probably should change this to a deque...
# since we've popped it off the list, add it back to the list to send next
# probably should change this to a deque...
self.data_to_write.insert(0, remaining)
def handle_read(self):
"""
Read an incoming message from the client and put it into our outgoing queue.
......@@ -164,13 +159,13 @@ class SimHandler(asyncore.dispatcher):
processed.
"""
#receive a chunk of data with the max size chunk_size from our client.
# receive a chunk of data with the max size chunk_size from our client.
data = self.recv(self.chunk_size)
if len(data) == 0:
#this only happens when the connection is dropped
self.handle_close()
return
# this only happens when the connection is dropped
self.handle_close()
return
self.data_to_read.append(data.decode("utf-8"))
......@@ -186,7 +181,6 @@ class SimHandler(asyncore.dispatcher):
else:
self.data_to_read.append(mesg)
def handle_json_message(self, chunk):
'''
We are expecing a json object
......@@ -195,10 +189,10 @@ class SimHandler(asyncore.dispatcher):
# Replace comma with dots for floats
# useful when using unity in a language different from English
chunk = replace_float_notation(chunk)
#convert data into a string with decode, and then load it as a json object
# convert data into a string with decode, and then load it as a json object
jsonObj = json.loads(chunk)
except Exception as e:
#something bad happened, usually malformed json packet. jump back to idle and hope things continue
# something bad happened, usually malformed json packet. jump back to idle and hope things continue
print(e, 'failed to read json ', chunk)
return
'''
......@@ -211,10 +205,8 @@ class SimHandler(asyncore.dispatcher):
if self.msg_handler:
self.msg_handler.on_recv_message(jsonObj)
def handle_close(self):
#when client drops or closes connection
# when client drops or closes connection
if self.msg_handler:
self.msg_handler.on_disconnect()
self.msg_handler = None
......
# flake8: noqa
from gym.envs.registration import register
from .donkey_env import GeneratedRoadsEnv, WarehouseEnv, AvcSparkfunEnv, GeneratedTrackEnv
......
......@@ -4,17 +4,15 @@ author: Tawn Kramer
date: 2018-08-31
'''
import os
from threading import Thread
import random
import time
import numpy as np
import gym
from gym import error, spaces, utils
from gym import spaces
from gym.utils import seeding
from gym_donkeycar.envs.donkey_sim import DonkeyUnitySimContoller
from gym_donkeycar.envs.donkey_proc import DonkeyUnityProcess
from gym_donkeycar.envs.donkey_ex import SimFailed
class DonkeyEnv(gym.Env):
......
class SimFailed(Exception):
pass
\ No newline at end of file
......@@ -6,6 +6,7 @@ date: 2018-09-12
import subprocess
import os
class DonkeyUnityProcess(object):
def __init__(self):
......@@ -24,7 +25,7 @@ class DonkeyUnityProcess(object):
# Launch Unity environment
if headless:
self.proc1 = subprocess.Popen(
[sim_path,'-nographics', '-batchmode'] + port_args)
[sim_path, '-nographics', '-batchmode'] + port_args)
else:
self.proc1 = subprocess.Popen(
[sim_path] + port_args)
......@@ -39,4 +40,3 @@ class DonkeyUnityProcess(object):
print("closing donkey sim subprocess")
self.proc1.kill()
self.proc1 = None
\ No newline at end of file
......@@ -4,23 +4,16 @@ author: Tawn Kramer
date: 2018-08-31
'''
import os
import json
import logging
import shutil
import base64
import random
import time
from io import BytesIO
import math
import logging
from threading import Thread
import asyncore
import base64
import numpy as np
from PIL import Image
from io import BytesIO
import base64
import datetime
import asyncore
from gym_donkeycar.core.fps import FPSTimer
from gym_donkeycar.core.tcp_server import IMesgHandler, SimServer
......@@ -39,9 +32,9 @@ class DonkeyUnitySimContoller():
self.address = (hostname, port)
self.handler = DonkeyUnitySimHandler(
level, time_step=time_step, max_cte=max_cte, cam_resolution=cam_resolution)
import pdb; pdb.set_trace()
level, time_step=time_step, max_cte=max_cte,
cam_resolution=cam_resolution)
try:
self.server = SimServer(self.address, self.handler)
except OSError:
......@@ -115,7 +108,7 @@ class DonkeyUnitySimHandler(IMesgHandler):
self.sock = None
def on_recv_message(self, message):
if not 'msg_type' in message:
if 'msg_type' not in message:
logger.error('expected msg_type field')
return
......
......@@ -2,7 +2,9 @@ pip==18.1
bumpversion==0.5.3
wheel==0.32.1
watchdog==0.9.0
flake8==3.5.0
flake8-debugger==3.1.0
tox==3.5.2
coverage==4.5.1
Sphinx==1.8.1
......
......@@ -27,8 +27,7 @@ setup_requirements = ['pytest-runner', ]
test_requirements = ['pytest', ]
setup(
author="Leigh Johnson",
author_email='leigh@data-literate.com',
author="Tawn Kramer",
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
......
......@@ -8,7 +8,9 @@ python =
[testenv:flake8]
basepython = python
deps = flake8
deps =
flake8
flake8-debugger
commands = flake8 gym_donkeycar
[testenv:pytest]
......@@ -27,5 +29,7 @@ deps =
commands =
pip install -U pip
py.test --basetemp={envtmpdir}
flake8 gym_donkeycar --ignore=E501,E722,E266
[pycodestyle]
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册