From c3de88b89f1fd923545832b06885bc07e4b7602f Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Wed, 10 Jun 2015 20:10:40 +0300 Subject: [PATCH] When dsdlc is running from source, it does not require pyuavcan anymore --- .gitmodules | 3 +++ libuavcan/dsdl_compiler/libuavcan_dsdlc | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/.gitmodules b/.gitmodules index 60890ac7a0..5cf2995db3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "dsdl"] path = dsdl url = https://github.com/UAVCAN/dsdl +[submodule "libuavcan/dsdl_compiler/pyuavcan"] + path = libuavcan/dsdl_compiler/pyuavcan + url = https://github.com/UAVCAN/pyuavcan diff --git a/libuavcan/dsdl_compiler/libuavcan_dsdlc b/libuavcan/dsdl_compiler/libuavcan_dsdlc index 38a7c3fb9c..a95c1313e9 100755 --- a/libuavcan/dsdl_compiler/libuavcan_dsdlc +++ b/libuavcan/dsdl_compiler/libuavcan_dsdlc @@ -9,6 +9,17 @@ from __future__ import division, absolute_import, print_function, unicode_literals import os, sys, logging, argparse +# This trickery allows to use the compiler even if pyuavcan is not installed in the system. +# This is extremely important, as it makes the compiler (and therefore libuavcan in general) +# totally dependency-free, except for the Python interpreter itself. +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +LOCAL_PYUAVCAN_DIR = os.path.join(SCRIPT_DIR, 'pyuavcan') +RUNNING_FROM_SRC_DIR = os.path.isdir(LOCAL_PYUAVCAN_DIR) +if RUNNING_FROM_SRC_DIR: + print('Running from the source directory') + sys.path.insert(0, SCRIPT_DIR) + sys.path.insert(0, LOCAL_PYUAVCAN_DIR) + def configure_logging(verbosity): fmt = '%(message)s' level = { 0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG }.get(verbosity or 0, logging.DEBUG)