Skip to content

Commit

Permalink
Allow specifying custom rosdep paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
peci1 committed Dec 30, 2022
1 parent f1412cd commit ad7fdbb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/catkin_lint/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class PackageType:


class CatkinEnvironment(object):
def __init__(self, os_env=None, use_rosdep=True, use_rosdistro=True, use_cache=True, quiet=False):
def __init__(self, os_env=None, use_rosdep=True, use_rosdistro=True, use_cache=True, quiet=False,
rosdep_sources_list_dir=None, rosdep_init=False, rosdep_sources_cache_dir=None, rosdep_update=False):
self.package_path_order = []
self.searched_paths = {}
self.known_catkin_pkgs = set()
Expand All @@ -135,7 +136,8 @@ def __init__(self, os_env=None, use_rosdep=True, use_rosdistro=True, use_cache=T
if use_rosdep:
try:
gc.disable()
self.rosdep = get_rosdep(quiet=self.quiet)
self.rosdep = get_rosdep(quiet=self.quiet, sources_list_dir=rosdep_sources_list_dir, init=rosdep_init,
sources_cache_dir=rosdep_sources_cache_dir, update=rosdep_update)
except Exception as err:
if not self.quiet:
sys.stderr.write("catkin_lint: cannot load rosdep database: %s\n" % str(err))
Expand Down
18 changes: 17 additions & 1 deletion src/catkin_lint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def prepare_arguments(parser):
parser.add_argument("--disable-cache", action="store_true", help=argparse.SUPPRESS)
parser.add_argument("--dump-cache", action="store_true", help=argparse.SUPPRESS)
parser.add_argument("--list-check-ids", action="store_true", help=argparse.SUPPRESS)
parser.add_argument("--rosdep-sources-list-dir", metavar="ROSDEP_SOURCES_LIST_DIR", help="override the default rosdep sources list directory location.")
parser.add_argument("--rosdep-init", action="store_true", default=None, help="initialize rosdep sources list if it is not already initialized (use --rosdep-sources-list-dir to specify a writable location)")
parser.add_argument("--rosdep-sources-cache-dir", metavar="ROSDEP_SOURCES_CACHE_DIR", help="override the default rosdep sources cache directory location.")
parser.add_argument("--rosdep-update", action="store_true", default=None, help="update rosdep cache before checking for valid packages")
return parser


Expand Down Expand Up @@ -184,6 +188,14 @@ def run_linter(args):
config["catkin_lint"]["severity_level"] = str(args.severity_level)
if args.resolve_env is not None:
config["catkin_lint"]["resolve_env"] = "yes" if args.resolve_env else "no"
if args.rosdep_sources_list_dir:
config["catkin_lint"]["rosdep_sources_list_dir"] = args.rosdep_sources_list_dir
if args.rosdep_init is not None:
config["catkin_lint"]["rosdep_init"] = "yes" if args.rosdep_init else "no"
if args.rosdep_sources_cache_dir:
config["catkin_lint"]["rosdep_sources_cache_dir"] = args.rosdep_sources_cache_dir
if args.rosdep_update is not None:
config["catkin_lint"]["rosdep_update"] = "yes" if args.rosdep_update else "no"

for config_file in args.config:
try:
Expand Down Expand Up @@ -217,7 +229,11 @@ def run_linter(args):
os_env=os.environ if config["catkin_lint"].getboolean("resolve_env", False) else None,
use_rosdistro=not config["catkin_lint"].getboolean("offline", False),
use_cache=not config["catkin_lint"].getboolean("disable_cache", False),
quiet=quiet
quiet=quiet,
rosdep_sources_list_dir=config["catkin_lint"].get("rosdep_sources_list_dir", None),
rosdep_init=config["catkin_lint"].getboolean("rosdep_init", False),
rosdep_sources_cache_dir=config["catkin_lint"].get("rosdep_sources_cache_dir", None),
rosdep_update=config["catkin_lint"].getboolean("rosdep_update", False),
)
if not args.path and not args.pkg:
if os.path.isfile("package.xml"):
Expand Down
37 changes: 34 additions & 3 deletions src/catkin_lint/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,43 @@ def has_key(self, name):
return self.view is not None and name in self.view.keys()


def get_rosdep(quiet):
def get_rosdep(quiet, sources_list_dir=None, init=False, sources_cache_dir=None, update=False):
from rosdep2.lookup import RosdepLookup
from rosdep2.rospkg_loader import DEFAULT_VIEW_KEY
from rosdep2.sources_list import SourcesListLoader
from rosdep2.sources_list import SourcesListLoader, update_sources_list, SOURCE_PATH_ENV,\
get_default_sources_list_file
from rosdep2.main import command_init
from rosdep2.rosdistrohelper import PreRep137Warning

if sources_list_dir is not None:
if not os.path.exists(sources_list_dir):
os.makedirs(sources_list_dir)
os.environ[SOURCE_PATH_ENV] = sources_list_dir

if init and not os.path.exists(get_default_sources_list_file()):
# command_init() writes to stdout, so we silence it
try:
# Python 2
from StringIO import StringIO
except ImportError:
# Python 3
from io import StringIO
stdout = sys.stdout
sys.stdout = StringIO()
try:
command_init(None)
finally:
sys.stdout = stdout

if update:
import warnings
warnings.filterwarnings('ignore', category=PreRep137Warning)
update_sources_list(sources_list_dir=sources_list_dir, sources_cache_dir=sources_cache_dir,
ros_distro=os.environ.get("ROS_DISTRO", None), skip_eol_distros=True, quiet=True)
warnings.filterwarnings('always', category=PreRep137Warning)

dummy = DummyRospkg()
sources_loader = SourcesListLoader.create_default()
sources_loader = SourcesListLoader.create_default(sources_cache_dir=sources_cache_dir)
lookup = RosdepLookup.create_from_rospkg(rospack=dummy, rosstack=dummy, sources_loader=sources_loader)
return Rosdep(view=lookup.get_rosdep_view(DEFAULT_VIEW_KEY), quiet=quiet)

Expand Down

0 comments on commit ad7fdbb

Please sign in to comment.