collect_requirements.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (GPL)
3 #
4 # \file collect_requirements.py
5 # \authors Paul Bovbel <pbovbel@locusrobotics.com>
6 # \copyright Copyright (c) (2017,), Locus Robotics, All rights reserved.
7 #
8 # This program is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation, either version 2 of the
11 # License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from __future__ import print_function
21 
22 import os
23 
24 from queue import Queue
25 from catkin.find_in_workspaces import find_in_workspaces
26 from catkin_pkg.package import parse_package
27 
28 
29 CATKIN_VIRTUALENV_TAGNAME = "pip_requirements"
30 
31 
32 def parse_exported_requirements(package, package_dir):
33  # type: (catkin_pkg.package.Package) -> List[str]
34  requirements_list = []
35  for export in package.exports:
36  if export.tagname == CATKIN_VIRTUALENV_TAGNAME:
37  requirements_list.append(os.path.join(package_dir, export.content))
38  return requirements_list
39 
40 
41 def process_package(package_name, soft_fail=True):
42  # type: (str) -> List[str], List[str]
43  try:
44  package_path = find_in_workspaces(project=package_name, path="package.xml", first_match_only=True,)[0]
45  except IndexError:
46  if not soft_fail:
47  raise RuntimeError("Unable to process package {}".format(package_name))
48  else:
49  # This is not a catkin dependency
50  return [], []
51  else:
52  package = parse_package(package_path)
53  dependencies = package.build_depends + package.test_depends
54  return parse_exported_requirements(package, os.path.dirname(package_path)), dependencies
55 
56 
57 def collect_requirements(package_name, no_deps=False):
58  # type: (str, bool) -> List[str]
59  """ Collect requirements inherited by a package. """
60  package_queue = Queue()
61  package_queue.put(package_name)
62  processed_packages = set()
63  requirements_list = []
64 
65  while not package_queue.empty():
66  queued_package = package_queue.get()
67 
68  if queued_package not in processed_packages:
69  processed_packages.add(queued_package)
70  requirements, dependencies = process_package(
71  package_name=queued_package, soft_fail=(queued_package != package_name)
72  )
73  requirements_list = requirements + requirements_list
74 
75  if not no_deps:
76  for dependency in dependencies:
77  package_queue.put(dependency.name)
78 
79  return requirements_list
def collect_requirements(package_name, no_deps=False)
def parse_exported_requirements(package, package_dir)
def process_package(package_name, soft_fail=True)


catkin_virtualenv
Author(s): Paul Bovbel
autogenerated on Thu Apr 1 2021 02:36:27