How to use the rospkg.environment function in rospkg

To help you get started, we’ve selected a few rospkg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ros / ros_comm / utilities / roswtf / src / roswtf / context.py View on Github external
def _load_env(ctx, env):
    """
    Utility for initializing WtfContext state

    @raise WtfException: if context state cannot be initialized
    """
    ctx.env = env
    try:
        ctx.ros_root = env[rospkg.environment.ROS_ROOT]
    except KeyError:
        raise WtfException("ROS_ROOT is not set")
    ctx.ros_package_path = env.get(rospkg.environment.ROS_PACKAGE_PATH, None)
    ctx.pythonpath = env.get('PYTHONPATH', None)
    ctx.ros_master_uri = env.get(rosgraph.ROS_MASTER_URI, None)
github ros / ros / core / roslib / src / roslib / packages.py View on Github external
# UNIXONLY
    # TODO: replace with non-rospack-based solution (e.g. os.walk())
    try:
        penv = os.environ.copy()
        if ros_root:
            ros_root = rospkg.environment._resolve_path(ros_root)
            penv[ROS_ROOT] = ros_root
        elif ROS_ROOT in os.environ:
            # record setting for _pkg_dir_cache
            ros_root = os.environ[ROS_ROOT]

        # determine rospack exe name
        rospack = 'rospack'

        if ros_package_path is not None:
            ros_package_path = rospkg.environment._resolve_paths(ros_package_path)
            penv[ROS_PACKAGE_PATH] = ros_package_path
        elif ROS_PACKAGE_PATH in os.environ:
            # record setting for _pkg_dir_cache
            ros_package_path = os.environ[ROS_PACKAGE_PATH]

        # update cache if we haven't. NOTE: we only get one cache
        if not _pkg_dir_cache:
            _read_rospack_cache(_pkg_dir_cache, ros_root, ros_package_path)

        # now that we've resolved the args, check the cache
        if package in _pkg_dir_cache:
            dir_, rr, rpp = _pkg_dir_cache[package]
            if rr == ros_root and rpp == ros_package_path:
                if os.path.isfile(os.path.join(dir_, MANIFEST_FILE)):
                    return dir_
                else:
github ros / ros_comm / utilities / roswtf / src / roswtf / context.py View on Github external
def _load_env(ctx, env):
    """
    Utility for initializing WtfContext state

    @raise WtfException: if context state cannot be initialized
    """
    ctx.env = env
    try:
        ctx.ros_root = env[rospkg.environment.ROS_ROOT]
    except KeyError:
        raise WtfException("ROS_ROOT is not set")
    ctx.ros_package_path = env.get(rospkg.environment.ROS_PACKAGE_PATH, None)
    ctx.pythonpath = env.get('PYTHONPATH', None)
    ctx.ros_master_uri = env.get(rosgraph.ROS_MASTER_URI, None)
github ros / ros / core / roslib / src / roslib / packages.py View on Github external
    @type  required: bool
    @param ros_root: if specified, override ROS_ROOT
    @type  ros_root: str
    @param ros_package_path: if specified, override ROS_PACKAGE_PATH
    @type  ros_package_path: str
    @return: directory containing package or None if package cannot be found and required is False.
    @rtype: str
    @raise InvalidROSPkgException: if required is True and package cannot be located
    """

    # UNIXONLY
    # TODO: replace with non-rospack-based solution (e.g. os.walk())
    try:
        penv = os.environ.copy()
        if ros_root:
            ros_root = rospkg.environment._resolve_path(ros_root)
            penv[ROS_ROOT] = ros_root
        elif ROS_ROOT in os.environ:
            # record setting for _pkg_dir_cache
            ros_root = os.environ[ROS_ROOT]

        # determine rospack exe name
        rospack = 'rospack'

        if ros_package_path is not None:
            ros_package_path = rospkg.environment._resolve_paths(ros_package_path)
            penv[ROS_PACKAGE_PATH] = ros_package_path
        elif ROS_PACKAGE_PATH in os.environ:
            # record setting for _pkg_dir_cache
            ros_package_path = os.environ[ROS_PACKAGE_PATH]

        # update cache if we haven't. NOTE: we only get one cache
github ros / ros_comm / clients / rospy / src / rospy / core.py View on Github external
def get_ros_root(required=False, env=None):
    """
    Get the value of ROS_ROOT.
    @param env: override environment dictionary
    @type  env: dict
    @param required: if True, fails with ROSException
    @return: Value of ROS_ROOT environment
    @rtype: str
    @raise ROSException: if require is True and ROS_ROOT is not set
    """
    if env is None:
        env = os.environ
    ros_root = rospkg.get_ros_root(env)
    if required and not ros_root:
        raise rospy.exceptions.ROSException('%s is not set'%rospkg.environment.ROS_ROOT)
    return ros_root
github ros / ros / core / roslib / src / roslib / packages.py View on Github external
import stat
import sys
from subprocess import PIPE
from subprocess import Popen

from catkin.find_in_workspaces import find_in_workspaces as catkin_find

import roslib.manifest  # noqa: F401

import rospkg

SRC_DIR = 'src'

# aliases
ROS_PACKAGE_PATH = rospkg.environment.ROS_PACKAGE_PATH
ROS_ROOT = rospkg.environment.ROS_ROOT


class ROSPkgException(Exception):
    """
    Base class of package-related errors.
    """
    pass


class InvalidROSPkgException(ROSPkgException):
    """
    Exception that indicates that a ROS package does not exist
    """
    pass
github ros / ros / core / roslib / src / roslib / stacks.py View on Github external
"""
Warning: do not use this library.  It is unstable and most of the routines
here have been superceded by other libraries (e.g. rospkg).  These
routines will likely be *deleted* in future releases.
"""

import os
import re

import roslib.packages
import roslib.stack_manifest

import rospkg

ROS_ROOT = rospkg.environment.ROS_ROOT
ROS_PACKAGE_PATH = rospkg.environment.ROS_PACKAGE_PATH

STACK_FILE = 'stack.xml'
ROS_STACK = 'ros'


class ROSStackException(Exception):
    pass


class InvalidROSStackException(ROSStackException):
    pass


def stack_of(pkg, env=None):
    """
github ros / ros / core / roslib / src / roslib / stacks.py View on Github external
"""
Warning: do not use this library.  It is unstable and most of the routines
here have been superceded by other libraries (e.g. rospkg).  These
routines will likely be *deleted* in future releases.
"""

import os
import re

import roslib.packages
import roslib.stack_manifest

import rospkg

ROS_ROOT = rospkg.environment.ROS_ROOT
ROS_PACKAGE_PATH = rospkg.environment.ROS_PACKAGE_PATH

STACK_FILE = 'stack.xml'
ROS_STACK = 'ros'


class ROSStackException(Exception):
    pass


class InvalidROSStackException(ROSStackException):
    pass


def stack_of(pkg, env=None):
    """
    @param env: override environment variables