Permalink
Browse files

man - reorganized Python packages and imports

  The update required many changes throughout cmake files, directories, and
  Python sources.  In general, the changes are as follows:
    * Directory changes:
      * Removed duplicated Python source directories (i.e.
        'man/skull/noggin/noggin') and moved Python sources and subpackages
        into the main directory (with C++ files and headers)
      * Added some new package initilization modules, some bare, some with
        sparse import attempt and warning code
    * CMake changes:
      * Added MAN_PYTHON_TARGET_DIR and XXX_PYTHON_TARGET_DIR variables,
        along with XXX_PYTHON_SRCS if it didn't exist
      * Changed Python source location settings to mimic the man/ structure
      * Used above variables to install Python sources
      * In some packages, added some __init__.py or other new source files to
        the XXX_PYTHON_SRCS
    * In Python sources:
      * Changed Python import scheme across many files.  The full format will
        be posted online.  This consisted of:
        * Changing imports to account for new package structure ('motion' is
          now 'man.motion', 'sensors' is now 'man.corpus.sensors')
        * Changing imports to use approriate relative or absolute imports
        * Occasionally, changing import code to properly distinguish between
          package, module, and attribute imports

   The code will now install to a specified directory with the fully realized
   design structure specified by our initial discussions.  Python package
   directories and extension modules install coordinatedly, when shared
   extension modules are specified.  All the low-level C++/C code is contained
   in the libman.so or man executable, in lib/ or bin/ respectively, and, when
   shared extension modules are not specified, this contains all the module
   insertion code and Python embedding as well.
  • Loading branch information...
1 parent d18423d commit 6057b0baa82bfc6432d2397aa89030c41e2a915e Jeremy R. Fishman committed Aug 5, 2008
Showing with 278 additions and 194 deletions.
  1. +3 −1 Makefile
  2. 0 {skull/noggin/noggin → }/__init__.py
  3. +29 −19 cmake.man/CMakeLists.txt
  4. +17 −8 cmake/FindNBCOMMON.cmake
  5. +8 −0 comm/__init__.py
  6. +10 −4 comm/cmake.comm/CMakeLists.txt
  7. 0 {skull/noggin/noggin/playBook → corpus}/__init__.py
  8. +5 −4 corpus/cmake.man.corpus/CMakeLists.txt
  9. +5 −1 corpus/leds.py
  10. +6 −6 corpus/sensors.py
  11. +6 −6 motion/{motion → }/MotionConstants.py
  12. 0 motion/{motion → }/SweetMoves.py
  13. +2 −0 motion/__init__.py
  14. +31 −30 motion/cmake.man.motion/CMakeLists.txt
  15. +0 −1 motion/{motion/__init__.py → walk.py}
  16. 0 skull/__init__.py
  17. +19 −17 skull/noggin/{noggin → }/Brain.py
  18. +5 −4 skull/noggin/{noggin → }/EKF.py
  19. +4 −5 skull/noggin/{noggin → }/GameController.py
  20. 0 skull/noggin/{noggin → }/GameStates.py
  21. +3 −3 skull/noggin/{noggin → }/HeadTracking.py
  22. +1 −1 skull/noggin/Makefile
  23. 0 skull/noggin/{noggin → }/NaoOutput.py
  24. 0 skull/noggin/{noggin → }/NavConstants.py
  25. +2 −2 skull/noggin/{noggin → }/NavStates.py
  26. +4 −4 skull/noggin/{noggin → }/Navigator.py
  27. 0 skull/noggin/{noggin → }/NogginConstants.py
  28. 0 skull/noggin/{noggin → }/PanningStates.py
  29. +2 −2 skull/noggin/{noggin → }/TrackingStates.py
  30. +8 −2 skull/noggin/{noggin → }/TypeDefs.py
  31. 0 skull/noggin/__init__.py
  32. +32 −10 skull/noggin/cmake.noggin/CMakeLists.txt
  33. +0 −2 skull/noggin/noggin/players/Switch.py.in
  34. +3 −3 skull/noggin/{noggin → }/playBook/Formations.py
  35. +12 −5 skull/noggin/{noggin → }/playBook/GoTeam.py
  36. +1 −1 skull/noggin/{noggin → }/playBook/PBConstants.py
  37. +2 −2 skull/noggin/{noggin → }/playBook/PBDefs.py
  38. +3 −3 skull/noggin/{noggin → }/playBook/Roles.py
  39. +3 −3 skull/noggin/{noggin → }/playBook/Strategies.py
  40. +1 −1 skull/noggin/{noggin → }/playBook/SubRoles.py
  41. 0 skull/noggin/playBook/__init__.py
  42. +3 −2 skull/noggin/{noggin → }/players/DistCalStates.py
  43. +2 −2 skull/noggin/{noggin → }/players/FirstGameStates.py
  44. 0 skull/noggin/{noggin → }/players/KeyControlStates.py
  45. +3 −3 skull/noggin/{noggin → }/players/NoneStates.py
  46. +3 −3 skull/noggin/{noggin → }/players/SecondGameStates.py
  47. 0 skull/noggin/{noggin → }/players/StandupStates.py
  48. 0 skull/noggin/{noggin → }/players/SuzhouConstants.py
  49. +7 −5 skull/noggin/{noggin → }/players/SuzhouStates.py
  50. +2 −0 skull/noggin/players/Switch.py.in
  51. 0 skull/noggin/{noggin → }/players/TrackBallStates.py
  52. 0 skull/noggin/{noggin → }/players/WalkLearning.py
  53. 0 skull/noggin/{noggin → }/players/__init__.py
  54. +1 −1 skull/noggin/{noggin → }/players/pBalance.py
  55. +2 −2 skull/noggin/{noggin → }/players/pControl.py
  56. 0 skull/noggin/{noggin → }/players/pDist.py
  57. +2 −2 skull/noggin/{noggin → }/players/pFirstGame.py
  58. 0 skull/noggin/{noggin → }/players/pKicker.py
  59. +3 −4 skull/noggin/{noggin → }/players/pNone.py
  60. 0 skull/noggin/{noggin → }/players/pOldWalker.py
  61. +1 −1 skull/noggin/{noggin → }/players/pRexec.py
  62. +3 −4 skull/noggin/{noggin → }/players/pSecondGame.py
  63. +2 −3 skull/noggin/{noggin → }/players/pStandup.py
  64. +4 −4 skull/noggin/{noggin → }/players/pSuzhou.py
  65. +2 −3 skull/noggin/{noggin → }/players/pTracker.py
  66. +2 −3 skull/noggin/{noggin → }/players/pWalker.py
  67. 0 skull/noggin/{noggin → }/robots/BirthCertificate.py
  68. +1 −1 skull/noggin/{noggin → }/robots/__init__.py
  69. 0 skull/{noggin/noggin/vision.py → vision/__init__.py}
  70. +8 −1 skull/vision/cmake.vision/CMakeLists.txt
View
@@ -14,6 +14,8 @@ CONFIG_FILE = manconfig.h
CROSS_FILE = $(BUILD_DIR)/cross
STRAIGHT_FILE = $(BUILD_DIR)/straight
+PYC_FILES = $(shell find . -name "*.pyc")
+
CROSS_TOOLCHAIN = $(abspath $(CURDIR)/cmake/geode.cmake)
CMAKE_DEFS = -DOE_CROSS_BUILD=OFF
CMAKE_CROSS_DEFS = -DCMAKE_TOOLCHAIN_FILE=$(CROSS_TOOLCHAIN) -DOE_CROSS_BUILD=ON
@@ -93,6 +95,6 @@ clean:
@$(MAKE) -C skull/noggin clean
@$(MAKE) -C skull/vision clean
@$(MAKE) -C comm clean
- $(RM) -r install/*
+ $(RM) -r install/* $(PYC_FILES)
File renamed without changes.
View
@@ -150,33 +150,43 @@ SET( MAN_SRCS ${MAN_INCLUDE_DIR}/Man
${MAN_INCLUDE_DIR}/_ledsmodule
)
+SET( MAN_PYTHON_SRCS ${MAN_INCLUDE_DIR}/__init__.py )
+SET( SKULL_PYTHON_SRCS ${SKULL_INCLUDE_DIR}/__init__.py )
############################ CHECK LIBRARY / EXECUTABLE OPTION
# Configure the output execuatable or shared library, and the install
# commands
GET_TARGET_PROPERTY( MAN_LOCATION ${MAN_TARGET} LOCATION )
-IF( ROBOT_NAO )
- IF( MAN_IS_REMOTE )
- ADD_EXECUTABLE(
- ${MAN_TARGET}
- ${MAN_SRCS}
- )
- ELSE( MAN_IS_REMOTE )
- ADD_LIBRARY(
- ${MAN_TARGET}
- SHARED
- ${MAN_SRCS}
- )
- ENDIF( MAN_IS_REMOTE )
- INSTALL(
- TARGETS ${MAN_TARGET}
- RUNTIME DESTINATION ${OUTPUT_ROOT_DIR_BIN}
- LIBRARY DESTINATION ${OUTPUT_ROOT_DIR_LIB}
- CONFIGURATIONS "" Debug Release
+IF( MAN_IS_REMOTE )
+ ADD_EXECUTABLE(
+ ${MAN_TARGET}
+ ${MAN_SRCS}
)
-ENDIF( ROBOT_NAO )
+ELSE( MAN_IS_REMOTE )
+ ADD_LIBRARY(
+ ${MAN_TARGET}
+ SHARED
+ ${MAN_SRCS}
+ )
+ENDIF( MAN_IS_REMOTE )
+INSTALL(
+ TARGETS ${MAN_TARGET}
+ RUNTIME DESTINATION ${OUTPUT_ROOT_DIR_BIN}
+ LIBRARY DESTINATION ${OUTPUT_ROOT_DIR_LIB}
+ CONFIGURATIONS "" Debug Release
+ )
+INSTALL(
+ FILES ${MAN_PYTHON_SRCS}
+ DESTINATION ${MAN_PYTHON_TARGET_DIR}
+ CONFIGURATIONS "" Debug Release
+ )
+INSTALL(
+ FILES ${SKULL_PYTHON_SRCS}
+ DESTINATION ${SKULL_PYTHON_TARGET_DIR}
+ CONFIGURATIONS "" Debug Release
+ )
############################ SET LIBRARIES TO LINK WITH
View
@@ -30,20 +30,21 @@ SET( NBCOMMON_INCLUDE_DIR "${TRUNK_PATH}/common/include" )
SET( NBCOMMON_LIBRARIES "" )
SET( NBCOMMON_LIB_DIR "${TRUNK_PATH}/common/lib" )
-SET( VISION_INCLUDE_DIR ${TRUNK_PATH}/skull/vision )
-SET( NOGGIN_INCLUDE_DIR ${TRUNK_PATH}/skull/noggin )
-SET( COMM_INCLUDE_DIR ${TRUNK_PATH}/comm )
-SET( CORPUS_INCLUDE_DIR ${TRUNK_PATH}/corpus )
-SET( MOTION_INCLUDE_DIR ${TRUNK_PATH}/motion )
+SET( MAN_INCLUDE_DIR ${TRUNK_PATH} )
+SET( COMM_INCLUDE_DIR ${MAN_INCLUDE_DIR}/comm )
+SET( CORPUS_INCLUDE_DIR ${MAN_INCLUDE_DIR}/corpus )
+SET( MOTION_INCLUDE_DIR ${MAN_INCLUDE_DIR}/motion )
+SET( SKULL_INCLUDE_DIR ${MAN_INCLUDE_DIR}/skull )
+SET( NOGGIN_INCLUDE_DIR ${SKULL_INCLUDE_DIR}/noggin )
+SET( VISION_INCLUDE_DIR ${SKULL_INCLUDE_DIR}/vision )
-SET( MAN_INCLUDE_DIR ${TRUNK_PATH} )
-SET( VISION_CMAKE_DIR ${VISION_INCLUDE_DIR}/cmake.vision )
-SET( NOGGIN_CMAKE_DIR ${NOGGIN_INCLUDE_DIR}/cmake.noggin )
SET( COMM_CMAKE_DIR ${COMM_INCLUDE_DIR}/cmake.comm )
SET( CORPUS_CMAKE_DIR ${CORPUS_INCLUDE_DIR}/cmake.man.corpus )
SET( MAN_CMAKE_DIR ${MAN_INCLUDE_DIR}/cmake.man )
SET( MOTION_CMAKE_DIR ${MOTION_INCLUDE_DIR}/cmake.man.motion )
+SET( NOGGIN_CMAKE_DIR ${NOGGIN_INCLUDE_DIR}/cmake.noggin )
+SET( VISION_CMAKE_DIR ${VISION_INCLUDE_DIR}/cmake.vision )
SET( COMM_TARGET _comm )
@@ -54,6 +55,14 @@ SET( NOGGIN_TARGET noggin )
SET( SENSORS_TARGET _sensors )
SET( VISION_TARGET vision )
+SET( MAN_PYTHON_TARGET_DIR ${OUTPUT_ROOT_DIR_LIB}/man )
+SET( COMM_PYTHON_TARGET_DIR ${MAN_PYTHON_TARGET_DIR}/comm )
+SET( CORPUS_PYTHON_TARGET_DIR ${MAN_PYTHON_TARGET_DIR}/corpus )
+SET( MOTION_PYTHON_TARGET_DIR ${MAN_PYTHON_TARGET_DIR}/motion )
+SET( SKULL_PYTHON_TARGET_DIR ${MAN_PYTHON_TARGET_DIR}/skull )
+SET( NOGGIN_PYTHON_TARGET_DIR ${SKULL_PYTHON_TARGET_DIR}/noggin )
+SET( VISION_PYTHON_TARGET_DIR ${SKULL_PYTHON_TARGET_DIR}/vision )
+
SET( TRUNK_REVISION r$ENV{TRUNK_REVISION} CACHE STRING "SVN Revision number" )
View
@@ -0,0 +1,8 @@
+
+try:
+ from _comm import *
+except ImportError:
+ import sys
+ print >>sys.stderr, "**** WARNING - No backend _comm module located ****"
+ inst = None
+
@@ -142,12 +142,13 @@ SET( COMM_SRCS ${COMM_INCLUDE_DIR}/Comm
${COMM_INCLUDE_DIR}/TOOLConnect
)
-IF( PYTHON_SHARED_COMM AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
+IF( PYTHON_SHARED_COMM )
LIST( APPEND COMM_SRCS ${CORPUS_INCLUDE_DIR}/Sensors
${CORPUS_INCLUDE_DIR}/NaoPose
)
-ENDIF( PYTHON_SHARED_COMM AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
+ENDIF( PYTHON_SHARED_COMM )
+SET( COMM_PYTHON_SRCS ${COMM_INCLUDE_DIR}/__init__.py )
############################ CHECK LIBRARY / EXECUTABLE OPTION
# Configure the output execuatable or shared library, and the install
@@ -165,8 +166,8 @@ IF( PYTHON_SHARED_COMM )
)
INSTALL(
FILES ${COMM_TARGET_LOCATION}
- DESTINATION ${OUTPUT_ROOT_DIR_LIB}
- CONFIGURATIONS Debug
+ DESTINATION ${COMM_PYTHON_TARGET_DIR}
+ CONFIGURATIONS "" Debug Release
RENAME ${COMM_TARGET}module.so
)
ELSE( PYTHON_SHARED_COMM )
@@ -178,6 +179,11 @@ ELSE( PYTHON_SHARED_COMM )
# No INSTALL target when static
ENDIF( PYTHON_SHARED_COMM )
+INSTALL(
+ FILES ${COMM_PYTHON_SRCS}
+ DESTINATION ${COMM_PYTHON_TARGET_DIR}
+ CONFIGURATIONS "" Debug Release
+ )
############################ SET LIBRARIES TO LINK WITH
IF( ROBOT_NAO )
File renamed without changes.
@@ -101,7 +101,8 @@ IF( PYTHON_SHARED_CORPUS )
)
ENDIF( PYTHON_SHARED_CORPUS )
-SET( CORPUS_PYTHON_SRCS ${CORPUS_INCLUDE_DIR}/leds.py
+SET( CORPUS_PYTHON_SRCS ${CORPUS_INCLUDE_DIR}/__init__.py
+ ${CORPUS_INCLUDE_DIR}/leds.py
${CORPUS_INCLUDE_DIR}/sensors.py
)
@@ -128,13 +129,13 @@ IF( PYTHON_SHARED_CORPUS )
# Install to TARGETmodule.so, instead of lib_TARGET.so
INSTALL(
FILES ${SENSORS_TARGET_LOCATION}
- DESTINATION ${OUTPUT_ROOT_DIR_LIB}
+ DESTINATION ${CORPUS_PYTHON_TARGET_DIR}
CONFIGURATIONS "" Debug Release
RENAME ${SENSORS_TARGET}module.so
)
INSTALL(
FILES ${LEDS_TARGET_LOCATION}
- DESTINATION ${OUTPUT_ROOT_DIR_LIB}
+ DESTINATION ${CORPUS_PYTHON_TARGET_DIR}
CONFIGURATIONS "" Debug Release
RENAME ${LEDS_TARGET}module.so
)
@@ -154,7 +155,7 @@ ENDIF( PYTHON_SHARED_CORPUS )
INSTALL(
FILES ${CORPUS_PYTHON_SRCS}
- DESTINATION ${OUTPUT_ROOT_DIR_LIB}
+ DESTINATION ${CORPUS_PYTHON_TARGET_DIR}
CONFIGURATIONS "" Debug Release
)
View
@@ -1,2 +1,6 @@
-import _leds
+try:
+ import _leds
+except ImportError:
+ import sys
+ print >>sys.stderr, "**** WARNING - no backend _leds module located ****"
View
@@ -1,15 +1,15 @@
import sys
-import _sensors
+try:
+ import _sensors
+except ImportError:
+ print >>sys.stderr,"**** WARNING - no backend _sensors module located ****"
+ _sensors = None
-if not hasattr(_sensors, "inst"):
+if _sensors and not hasattr(_sensors, "inst"):
raise ImportError("C++ _sensors backend is not initialized. Did you mean "
"to compile with USE_PYSENSORS_FAKE_BACKEND?")
-#class Sensors(_sensors.Sensors):
-# def __init__(self):
-# _sensors.Sensors.__init__(self, _sensors.inst)
-
def Sensors():
return _sensors.inst
@@ -3,12 +3,12 @@
"""
# Import all hard-coded C++ constants from extension module
-from _motion import (WALK_STRAIGHT,
- WALK_SIDEWAYS,
- WALK_TURN,
- WALK_ARC,
- DEFAULT_SAMPLES_PER_STEP,
- )
+#from _motion import (WALK_STRAIGHT,
+# WALK_SIDEWAYS,
+# WALK_TURN,
+# WALK_ARC,
+# DEFAULT_SAMPLES_PER_STEP,
+# )
#currently, there are 40 ms time steps
File renamed without changes.
View
@@ -0,0 +1,2 @@
+
+
@@ -105,7 +105,10 @@ IF( PYTHON_SHARED_MOTION AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
LIST( APPEND MOTION_SRCS ${MAN_INCLUDE_DIR}/Sensors )
ENDIF( PYTHON_SHARED_MOTION AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
-SET( MOTION_PYTHON_DIRS ${MOTION_INCLUDE_DIR}/motion )
+SET( MOTION_PYTHON_SRCS ${MOTION_INCLUDE_DIR}/__init__.py
+ ${MOTION_INCLUDE_DIR}/MotionConstants.py
+ ${MOTION_INCLUDE_DIR}/SweetMoves.py
+ )
SET( MOTION_TEST_DIR ${MOTION_INCLUDE_DIR}/test )
@@ -116,37 +119,35 @@ SET( MOTION_TEST_DIR ${MOTION_INCLUDE_DIR}/test )
GET_TARGET_PROPERTY( MOTION_LOCATION ${MOTION_TARGET} LOCATION )
-IF( ROBOT_NAO )
- IF( PYTHON_SHARED_MOTION )
- ADD_LIBRARY(
- ${MOTION_TARGET}
- SHARED
- ${MOTION_SRCS}
- )
- # Install to _motionmodule.so, instead of lib_motion.so
- GET_TARGET_PROPERTY(
- MOTION_TARGET_LOCATION ${MOTION_TARGET} LOCATION
- )
- INSTALL(
- FILES ${MOTION_TARGET_LOCATION}
- DESTINATION ${OUTPUT_ROOT_DIR_LIB}
- CONFIGURATIONS Debug
- RENAME ${MOTION_TARGET}module.so
- )
- ELSE( PYTHON_SHARED_MOTION )
- ADD_LIBRARY(
- ${MOTION_TARGET}
- STATIC
- ${MOTION_SRCS}
- )
- # No INSTALL target when static
- ENDIF( PYTHON_SHARED_MOTION )
-ENDIF( ROBOT_NAO )
+IF( PYTHON_SHARED_MOTION )
+ ADD_LIBRARY(
+ ${MOTION_TARGET}
+ SHARED
+ ${MOTION_SRCS}
+ )
+ # Install to _motionmodule.so, instead of lib_motion.so
+ GET_TARGET_PROPERTY(
+ MOTION_TARGET_LOCATION ${MOTION_TARGET} LOCATION
+ )
+ INSTALL(
+ FILES ${MOTION_TARGET_LOCATION}
+ DESTINATION ${MOTION_PYTHON_TARGET_DIR}
+ CONFIGURATIONS "" Debug Release
+ RENAME ${MOTION_TARGET}module.so
+ )
+ELSE( PYTHON_SHARED_MOTION )
+ ADD_LIBRARY(
+ ${MOTION_TARGET}
+ STATIC
+ ${MOTION_SRCS}
+ )
+ # No INSTALL target when static
+ENDIF( PYTHON_SHARED_MOTION )
+
INSTALL(
- DIRECTORY ${MOTION_PYTHON_DIRS}
- DESTINATION ${OUTPUT_ROOT_DIR_LIB}
+ FILES ${MOTION_PYTHON_SRCS}
+ DESTINATION ${MOTION_PYTHON_TARGET_DIR}
CONFIGURATIONS "" Debug Release
- PATTERN .svn EXCLUDE
)
INSTALL(
FILES ${MOTION_TEST_DIR}/test_motion.py
@@ -1,5 +1,4 @@
-
from _motion import (MotionInterface,
BodyJointCommand,
HeadJointCommand,
View
No changes.
@@ -1,23 +1,25 @@
import time
-import comm
-import sensors
-import motion
-import motion.MotionConstants as MotionConstants
-import leds
-import robots
-import vision
-
-import players.Switch as Switch
-import NogginConstants as Constants
-import NaoOutput
-import EKF
-import TypeDefs
-import HeadTracking
-import GameController
-import Navigator
-import playBook.GoTeam as GoTeam
+# Packages and modules from super-directories
+from man import comm
+from man import motion
+from man.corpus import leds, sensors
+from man.motion import MotionConstants
+from man.skull import vision
+# Modules from this directory
+from . import EKF
+from . import GameController
+from . import HeadTracking
+from . import Navigator
+from . import NaoOutput
+from . import NogginConstants as Constants
+from . import TypeDefs
+# Packages and modules from sub-directories
+from . import robots
+from .playBook import GoTeam
+from .players import Switch
+
DEBUG_OBJS = False
DEBUG_LOC = False
Oops, something went wrong.

0 comments on commit 6057b0b

Please sign in to comment.