def getPackageCategoryFromPath(projectRootDir): """ Returns the packageCategory (former known as "project start path") of a module, e.g.: getPackageCategoryFromPath( '/hri/sit/latest/Modules/BBCM/Food/FeedSnake/42.0' ) getPackageCategoryFromPath( 'Modules/BBCM/Food/FeedSnake/42.0' ) return both 'Modules/BBCM/Food'. """ Any.requireIsTextNonEmpty(projectRootDir) tmp = projectRootDir # first remove trailing project name and version from string search = os.sep + getPackageName(tmp) + os.sep + getPackageVersion(tmp) replace = '' tmp = tmp.replace(search, replace) # replace any values of ${HRI_GLOBAL_ROOT} or ${SIT} tmp = SIT.stripHGR(tmp) tmp = SIT.stripSIT(tmp) # remove trailing slashes (occurs if user provides a string with trailing slashes) while tmp.endswith('/'): tmp = tmp[0:-1] return tmp
def setEnv(): """ This function loads the pkgInfo.py of each dependency package. If environment settings are found there they will be loaded into the environment of the current Python process. Example: The pkgInfo.py of Matlab states MATLAB_ROOT, PATH and LD_LIBRARY_PATH settings in its pkgInfo.py. Before compiling such variables must be set. On Linux, alternatively, this can be achieved by sourcing the BashSrc files. Nevertheless this is not possible in all cases (especially Matlab because multiple versions are available) when used within CIA. With some modifications this setEnv() approach conceptually potentially could also work on Windows. Attention: This function should only be called once (at least not repeatedly when compiling the same package again from within Python) to not unnecessarily increase the length of PATH, LD_LIBRARY_PATH etc. """ try: p = PackageDetector() except AssertionError: # XIF packages are generated on-the-fly during configure-phase. # We don't consider such packages for now (experimental code). return p.retrieveMakefileInfo() for package in p.dependencies + p.buildDependencies: try: envVars = PkgInfo.getPkgInfoContent( SIT.stripSIT(package) )['envVars'] except ( AssertionError, KeyError ): envVars = [] # no envVars specified except ( IOError, OSError, SyntaxError ) as details: logging.error( details ) raise RuntimeError( 'unable to read pkgInfo.py of %s' % package ) if envVars: logging.debug( 'found environment settings:' ) logging.debug( envVars ) for varName, varValue in envVars: FastScript.setEnv_withExpansion( varName, varValue )