From d353631c56c37769eb4e78352626805738b223f6 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Mon, 8 Jan 2018 18:27:58 +0100 Subject: [PATCH 01/10] CI with Ubuntu 16 --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index c41c171e5..98a169624 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: python +os: linux +dist: xenial + python: - "2.7" - "3.5" From c5cbee9194a4e94b84ad54413108ba38d5849127 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Mon, 8 Jan 2018 18:41:02 +0100 Subject: [PATCH 02/10] Require pylint to pass without warnings --- .travis.yml | 2 +- PythonClient/.pylintrc | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 98a169624..664e105a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ install: - pip install pylint script: - - pylint --errors-only --rcfile=PythonClient/.pylintrc PythonClient/carla PythonClient/*.py + - pylint --disable=R,C --rcfile=PythonClient/.pylintrc PythonClient/carla PythonClient/*.py diff --git a/PythonClient/.pylintrc b/PythonClient/.pylintrc index f369d5bde..acb22ba72 100644 --- a/PythonClient/.pylintrc +++ b/PythonClient/.pylintrc @@ -1,3 +1,4 @@ [TYPECHECK] -ignored-modules=ConfigParser,numpy,pygame,shutil +ignore=carla_server_pb2.py +ignored-modules=ConfigParser,numpy,numpy.random,pygame,shutil ignored-classes=_socketobject From 0d05d70b5e54150ce32c1be5bdc1ecbac30dca74 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Tue, 9 Jan 2018 13:00:07 +0100 Subject: [PATCH 03/10] Testing ci configurations --- .travis.yml | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 664e105a1..161e7ce28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,28 @@ language: python os: linux -dist: xenial +dist: trusty # xenial is not yet supported. +python: "3.5" -python: - - "2.7" - - "3.5" - - "3.6" +matrix: + include: -install: - - pip install -r PythonClient/requirements.txt - - pip install pylint + - env: TEST="Pylint" + python: + - "2.7" + - "3.5" + - "3.6" + install: + - pip install -r PythonClient/requirements.txt + - pip install pylint + script: + - pylint --disable=R,C --rcfile=PythonClient/.pylintrc PythonClient/carla PythonClient/*.py + + - env: TEST="CppCheck" + addons: + apt: + packages: + - cppcheck + script: + - cppcheck Unreal/CarlaUE4/Source Unreal/CarlaUE4/Plugins/Carla/Source Util/ -iUtil/Build -iUtil/CarlaServer/source/carla/server/carla_server.pb.cc --quiet --error-exitcode=1 --enable=warning -script: - - pylint --disable=R,C --rcfile=PythonClient/.pylintrc PythonClient/carla PythonClient/*.py From a7e3fef096356a09b6b23e06cd886b723a865f03 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Tue, 9 Jan 2018 13:20:53 +0100 Subject: [PATCH 04/10] Testing ci configurations --- .travis.yml | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 161e7ce28..00bd90b42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,22 +2,21 @@ language: python os: linux dist: trusty # xenial is not yet supported. -python: "3.5" + +env: TEST="Pylint" +python: + - "3.5" + - "3.6" + - "2.7" +install: + - pip install -r PythonClient/requirements.txt + - pip install pylint +script: + - pylint --disable=R,C --rcfile=PythonClient/.pylintrc PythonClient/carla PythonClient/*.py matrix: include: - - env: TEST="Pylint" - python: - - "2.7" - - "3.5" - - "3.6" - install: - - pip install -r PythonClient/requirements.txt - - pip install pylint - script: - - pylint --disable=R,C --rcfile=PythonClient/.pylintrc PythonClient/carla PythonClient/*.py - - env: TEST="CppCheck" addons: apt: @@ -25,4 +24,3 @@ matrix: - cppcheck script: - cppcheck Unreal/CarlaUE4/Source Unreal/CarlaUE4/Plugins/Carla/Source Util/ -iUtil/Build -iUtil/CarlaServer/source/carla/server/carla_server.pb.cc --quiet --error-exitcode=1 --enable=warning - From 2e76bb32734951f8d91023be4753e8eee8c95eb3 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Tue, 9 Jan 2018 13:24:33 +0100 Subject: [PATCH 05/10] Skip ci installation step --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 00bd90b42..62d7b54af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ matrix: include: - env: TEST="CppCheck" + install: true addons: apt: packages: From bd8c12089d3219e81e79f816b204bffb15f03a0b Mon Sep 17 00:00:00 2001 From: nsubiron Date: Tue, 9 Jan 2018 15:52:09 +0100 Subject: [PATCH 06/10] Fix pylint warnings --- PythonClient/.pylintrc | 2 +- PythonClient/carla/client.py | 5 ++--- PythonClient/carla/sensor.py | 2 +- PythonClient/carla/settings.py | 11 +++++++---- PythonClient/carla/tcp.py | 13 ++++++------- PythonClient/carla/util.py | 6 +++--- PythonClient/client_example.py | 5 ----- PythonClient/manual_control.py | 6 ++---- 8 files changed, 22 insertions(+), 28 deletions(-) diff --git a/PythonClient/.pylintrc b/PythonClient/.pylintrc index acb22ba72..dd0ef806f 100644 --- a/PythonClient/.pylintrc +++ b/PythonClient/.pylintrc @@ -1,4 +1,4 @@ [TYPECHECK] ignore=carla_server_pb2.py ignored-modules=ConfigParser,numpy,numpy.random,pygame,shutil -ignored-classes=_socketobject +ignored-classes=_socketobject,EpisodeReady diff --git a/PythonClient/carla/client.py b/PythonClient/carla/client.py index fedf0e490..1f969d3f0 100644 --- a/PythonClient/carla/client.py +++ b/PythonClient/carla/client.py @@ -17,7 +17,6 @@ from . import util try: from . import carla_server_pb2 as carla_protocol - from carla_protocol import EpisodeReady except ImportError: raise RuntimeError('cannot import "carla_server_pb2.py", run the protobuf compiler to generate this file') @@ -97,7 +96,7 @@ class CarlaClient(object): data = self._world_client.read() if not data: raise RuntimeError('failed to read data from server') - pb_message = EpisodeReady() + pb_message = carla_protocol.EpisodeReady() pb_message.ParseFromString(data) if not pb_message.ready: raise RuntimeError('cannot start episode: server failed to start episode') @@ -160,7 +159,7 @@ class CarlaClient(object): raise RuntimeError('failed to read data from server') pb_message = carla_protocol.SceneDescription() pb_message.ParseFromString(data) - self._sensor_names = settings._get_sensor_names(carla_settings) + self._sensor_names = settings.get_sensor_names(carla_settings) self._is_episode_requested = True return pb_message diff --git a/PythonClient/carla/sensor.py b/PythonClient/carla/sensor.py index e8cccb9e9..f4e14333a 100644 --- a/PythonClient/carla/sensor.py +++ b/PythonClient/carla/sensor.py @@ -113,7 +113,7 @@ class Image(SensorData): size=(self.width, self.height), data=self.raw_data, decoder_name='raw') - b, g, r, a = image.split() + b, g, r, _ = image.split() image = PImage.merge("RGB", (r, g, b)) folder = os.path.dirname(filename) diff --git a/PythonClient/carla/settings.py b/PythonClient/carla/settings.py index 0fcc98767..f0eb50218 100644 --- a/PythonClient/carla/settings.py +++ b/PythonClient/carla/settings.py @@ -122,18 +122,21 @@ class CarlaSettings(object): return text.getvalue().replace(' = ', '=') -def _get_sensor_names(settings): +def get_sensor_names(settings): """ Return a list with the names of the sensors defined in the settings object. The settings object can be a CarlaSettings or an INI formatted string. """ if isinstance(settings, CarlaSettings): + # pylint: disable=protected-access return [camera.CameraName for camera in settings._cameras] ini = ConfigParser() - if sys.version_info >= (3, 0): - ini.readfp(io.StringIO(settings)) + if sys.version_info >= (3, 2): + ini.read_string(settings) + elif sys.version_info >= (3, 0): + ini.readfp(io.StringIO(settings)) # pylint: disable=deprecated-method else: - ini.readfp(io.BytesIO(settings)) + ini.readfp(io.BytesIO(settings)) # pylint: disable=deprecated-method section_name = 'CARLA/SceneCapture' option_name = 'Cameras' diff --git a/PythonClient/carla/tcp.py b/PythonClient/carla/tcp.py index b9ca34b6a..5dd9ed9ef 100644 --- a/PythonClient/carla/tcp.py +++ b/PythonClient/carla/tcp.py @@ -39,19 +39,18 @@ class TCPClient(object): try: self._socket = socket.create_connection(address=(self._host, self._port), timeout=self._timeout) self._socket.settimeout(self._timeout) - logging.debug(self._logprefix + 'connected') + logging.debug('%sconnected', self._logprefix) return - except Exception as exception: + except OSError as exception: error = exception - logging.debug(self._logprefix + 'connection attempt %d: %s', attempt, error) + logging.debug('%sconnection attempt %d: %s', self._logprefix, attempt, error) time.sleep(1) - continue self._reraise_exception_as_tcp_error('failed to connect', error) def disconnect(self): """Disconnect any active connection.""" if self._socket is not None: - logging.debug(self._logprefix + 'disconnecting') + logging.debug('%sdisconnecting', self._logprefix) self._socket.close() self._socket = None @@ -66,7 +65,7 @@ class TCPClient(object): header = struct.pack(' 0: try: data = self._socket.recv(length) - except Exception as exception: + except OSError as exception: self._reraise_exception_as_tcp_error('failed to read data', exception) if not data: raise TCPConnectionError(self._logprefix + 'connection closed') diff --git a/PythonClient/carla/util.py b/PythonClient/carla/util.py index 02fb4db8e..ce668235c 100644 --- a/PythonClient/carla/util.py +++ b/PythonClient/carla/util.py @@ -53,9 +53,9 @@ else: # Workaround for older Python versions. def print_over_same_line(text): - line_length = max(print_over_same_line._last_line_length, len(text)) + line_length = max(print_over_same_line.last_line_length, len(text)) empty_space = max(0, line_length - len(text)) sys.stdout.write('\r' + text + empty_space * ' ') sys.stdout.flush() - print_over_same_line._last_line_length = line_length - print_over_same_line._last_line_length = 0 + print_over_same_line.last_line_length = line_length + print_over_same_line.last_line_length = 0 diff --git a/PythonClient/client_example.py b/PythonClient/client_example.py index 9be0c4301..2b687313d 100755 --- a/PythonClient/client_example.py +++ b/PythonClient/client_example.py @@ -13,7 +13,6 @@ from __future__ import print_function import argparse import logging import random -import sys import time from carla.client import make_carla_client @@ -213,14 +212,10 @@ def main(): settings_filepath=args.carla_settings) print('Done.') - return except TCPConnectionError as error: logging.error(error) time.sleep(1) - except Exception as exception: - logging.exception(exception) - sys.exit(1) if __name__ == '__main__': diff --git a/PythonClient/manual_control.py b/PythonClient/manual_control.py index 329d831a0..dfca225db 100755 --- a/PythonClient/manual_control.py +++ b/PythonClient/manual_control.py @@ -30,7 +30,6 @@ from __future__ import print_function import argparse import logging import random -import sys import time try: @@ -131,6 +130,8 @@ class CarlaGame(object): self._map = CarlaMap(city_name) if city_name is not None else None self._map_shape = self._map.map_image.shape if city_name is not None else None self._map_view = self._map.get_map(WINDOW_HEIGHT) if city_name is not None else None + self._position = None + self._agent_positions = None def execute(self): """Launch the PyGame.""" @@ -363,9 +364,6 @@ def main(): except TCPConnectionError as error: logging.error(error) time.sleep(1) - except Exception as exception: - logging.exception(exception) - sys.exit(1) if __name__ == '__main__': From 1252dd80e851f3216c1e3aa3c3de8141b5cbb480 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Tue, 9 Jan 2018 15:58:50 +0100 Subject: [PATCH 07/10] Fix more pylint warnings --- PythonClient/carla/planner/map.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/PythonClient/carla/planner/map.py b/PythonClient/carla/planner/map.py index 22c651118..8779bb169 100644 --- a/PythonClient/carla/planner/map.py +++ b/PythonClient/carla/planner/map.py @@ -38,14 +38,14 @@ class CarlaMap(object): city_map_file = os.path.join(dir_path, city + '.png') city_map_file_lanes = os.path.join(dir_path, city + 'Lanes.png') - with open(city_file, 'r') as file: + with open(city_file, 'r') as file_object: - linewordloffset = file.readline() + linewordloffset = file_object.readline() # The offset of the world from the zero coordinates ( The # coordinate we consider zero) self.worldoffset = string_to_floats(linewordloffset) - lineworldangles = file.readline() + lineworldangles = file_object.readline() self.angles = string_to_floats(lineworldangles) self.worldrotation = np.array([ @@ -55,14 +55,14 @@ class CarlaMap(object): # Ignore for now, these are offsets for map coordinates and scale # (not used). - _ = file.readline() - linemapoffset = file.readline() + _ = file_object.readline() + linemapoffset = file_object.readline() # The offset of the map zero coordinate. self.mapoffset = string_to_floats(linemapoffset) # the graph resolution. - linegraphres = file.readline() + linegraphres = file_object.readline() self.resolution = string_to_node(linegraphres) # The number of game units per pixel. From 80a3c26cabb7771ea42756493e4600963dfccc95 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Tue, 9 Jan 2018 16:13:20 +0100 Subject: [PATCH 08/10] Verbose Cppcheck command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 62d7b54af..360dbf880 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,4 +24,4 @@ matrix: packages: - cppcheck script: - - cppcheck Unreal/CarlaUE4/Source Unreal/CarlaUE4/Plugins/Carla/Source Util/ -iUtil/Build -iUtil/CarlaServer/source/carla/server/carla_server.pb.cc --quiet --error-exitcode=1 --enable=warning + - cppcheck Unreal/CarlaUE4/Source Unreal/CarlaUE4/Plugins/Carla/Source Util/ -iUtil/Build -iUtil/CarlaServer/source/carla/server/carla_server.pb.cc --error-exitcode=1 --enable=warning From e1847f2001b6da1092169e7d6529275edd7f85e7 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Tue, 9 Jan 2018 16:23:50 +0100 Subject: [PATCH 09/10] Fix warning and make Cppcheck quiet again --- .travis.yml | 2 +- .../Plugins/Carla/Source/Carla/MapGen/CityMapMeshHolder.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 360dbf880..62d7b54af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,4 +24,4 @@ matrix: packages: - cppcheck script: - - cppcheck Unreal/CarlaUE4/Source Unreal/CarlaUE4/Plugins/Carla/Source Util/ -iUtil/Build -iUtil/CarlaServer/source/carla/server/carla_server.pb.cc --error-exitcode=1 --enable=warning + - cppcheck Unreal/CarlaUE4/Source Unreal/CarlaUE4/Plugins/Carla/Source Util/ -iUtil/Build -iUtil/CarlaServer/source/carla/server/carla_server.pb.cc --quiet --error-exitcode=1 --enable=warning diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/CityMapMeshHolder.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/CityMapMeshHolder.h index ea646cf55..9cad7d854 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/CityMapMeshHolder.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/CityMapMeshHolder.h @@ -102,7 +102,7 @@ private: USceneComponent *SceneRootComponent; UPROPERTY(Category = "Map Generation", VisibleAnywhere) - float MapScale; + float MapScale = 1.0f; UPROPERTY(Category = "Meshes", EditAnywhere) TMap StaticMeshes; From 84b20488d13657733f54da60fc8d9349a240d0ed Mon Sep 17 00:00:00 2001 From: nsubiron Date: Wed, 10 Jan 2018 13:29:52 +0100 Subject: [PATCH 10/10] Update coding standard --- Docs/CONTRIBUTING.md | 44 ++++++++++++++++++++++++++--------- Util/ImageConverter/Makefile | 2 +- Util/ImageConverter/README.md | 4 ++-- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Docs/CONTRIBUTING.md b/Docs/CONTRIBUTING.md index 85055e9f6..3438010e1 100644 --- a/Docs/CONTRIBUTING.md +++ b/Docs/CONTRIBUTING.md @@ -15,7 +15,7 @@ Reporting bugs -------------- Use our [issue section](issueslink) on GitHub. Please check before that the -issue was not already added. +issue is not already reported. [issueslink]: https://github.com/carla-simulator/carla/issues @@ -31,10 +31,14 @@ your request as a new issue. Code contributions ------------------ +So you are considering making a code contribution, great! we love to have +contributions from the community. + Before starting hands-on on coding, please check out the -[projects page][projectslink] to see if we are already working on that. In case -of doubt or to discuss how to proceed, please contact one of us (or send an -email to carla.simulator@gmail.com). +[projects page][projectslink] to see if we are already working on that, it would +be a pity putting an effort into something just to discover that someone else +was already working on that. In case of doubt or to discuss how to proceed, +please contact one of us (or send an email to carla.simulator@gmail.com). [projectslink]: https://github.com/carla-simulator/carla/projects/1 @@ -42,22 +46,40 @@ email to carla.simulator@gmail.com). Check out the ["CARLA Design"](carla_design.md) document to get an idea on the different modules that compose CARLA, and chose the most appropriate one to hold -the new feature. +the new feature. We are aware the developers documentation is still scarce, +please ask us in case of doubt, and of course don't hesitate to improve the +current documentation if you feel confident enough. -#### Coding style +#### Coding standard Please follow the current coding style when submitting new code. +###### General + * Use spaces, not tabs. - * Comments should not exceed 80 columns, code may exceed this limit a bit in rare -occasions if it results in clearer code. + * Avoid adding trailing whitespace as it creates noise in the diffs. + * Comments should not exceed 80 columns, code may exceed this limit a bit in rare occasions if it results in clearer code. + +###### Python + + * All code must be compatible with Python 2.7, 3.5, and 3.6. + * [Pylint](https://www.pylint.org/) should not give any error or warning (few exceptions apply with external classes like `numpy`, see our `.pylintrc`). * Python code follows [PEP8 style guide](https://www.python.org/dev/peps/pep-0008/) (use `autopep8` whenever possible). - * Unreal C++ code, CarlaUE4 and Carla plugin, follow the [Unreal Engine's Coding Standard](https://docs.unrealengine.com/latest/INT/Programming/Development/CodingStandard/) with the exception of using spaces instead of tabs. + +###### C++ + + * Compilation should not give any error or warning (`clang++ -Wall -Wextra -std=C++14`). + * Unreal C++ code (CarlaUE4 and Carla plugin) follow the [Unreal Engine's Coding Standard](https://docs.unrealengine.com/latest/INT/Programming/Development/CodingStandard/) with the exception of using spaces instead of tabs. * CarlaServer uses [Google's style guide](https://google.github.io/styleguide/cppguide.html). -#### Pull request +#### Pull-requests Once you think your contribution is ready to be added to CARLA, please submit a -pull request and one of our team members will take a look at it. +pull-request to the `dev` branch. Try to be as descriptive as possible when filling the pull-request description. + +Please note that there are some checks that the new code is required to pass +before we can do the merge. The checks are automatically run by the continuous +integration system, you will see a green tick mark if all the checks succeeded. +If you see a red mark, please correct your code accordingly. diff --git a/Util/ImageConverter/Makefile b/Util/ImageConverter/Makefile index 011da4c42..c4c0013e0 100644 --- a/Util/ImageConverter/Makefile +++ b/Util/ImageConverter/Makefile @@ -1,4 +1,4 @@ -CXX=g++ +CXX=clang++ FLAGS=-Wall -Wextra -std=c++14 -fopenmp LIBS=-lboost_system -lboost_filesystem -lboost_program_options -lpng -ljpeg -ltiff HEADERS=*.h diff --git a/Util/ImageConverter/README.md b/Util/ImageConverter/README.md index fa73b7f93..979d87503 100644 --- a/Util/ImageConverter/README.md +++ b/Util/ImageConverter/README.md @@ -4,9 +4,9 @@ Image Converter Converts output images of depth and semantic segmentation to a prettier format. Requires boost_system, boost_filesystem, boost_program_options, libpng, libtiff, -libjpeg and openmp. +libjpeg and libomp. -Compile with `g++ -std=c++14 -fopenmp`, for the default compilation just run +Compile with `clang++ -std=c++14 -fopenmp`, for the default compilation just run make make