def test_init_dependency(self): dep = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=5) self.assertEquals('foo', dep.name) self.assertEquals(1, dep.version_lt) self.assertEquals(2, dep.version_lte) self.assertEquals(3, dep.version_eq) self.assertEquals(4, dep.version_gte) self.assertEquals(5, dep.version_gt) self.assertRaises(TypeError, Dependency, 'foo', unknownattribute=42) d = {} d[dep] = None dep2 = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=5) d[dep2] = None self.assertEquals(len(d), 1) dep3 = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=6) d[dep3] = None self.assertEquals(len(d), 2)
def create_manifest(name, description="", buildtool_depends=[ "catkin" ], build_depends=[], run_depends=[], test_depends=[], meta=False): return Package( name=name, version="0.0.0", package_format=1, description=description, maintainers=[ Person("John Foo", "*****@*****.**") ], buildtool_depends=[ Dependency(d) for d in buildtool_depends ], build_depends=[ Dependency(d) for d in build_depends ], run_depends=[ Dependency(d) for d in run_depends ], test_depends=[ Dependency(d) for d in test_depends ], exports=[ Export("metapackage") ] if meta else [] )
def _get_and_parse_distribution_cache(index, rosdistro_name, pkg_names): from catkin_pkg.package import parse_package_string from catkin_pkg.package import Dependency dist_cache = get_distribution_cache(index, rosdistro_name) pkg_names = set(['ros_workspace']).union(pkg_names) cached_pkgs = { pkg_name: parse_package_string(pkg_xml) for pkg_name, pkg_xml in dist_cache.release_package_xmls.items() if pkg_name in pkg_names } condition_context = get_package_condition_context(index, rosdistro_name) for pkg in cached_pkgs.values(): pkg.evaluate_conditions(condition_context) for pkg in cached_pkgs.values(): for group_depend in pkg.group_depends: if group_depend.evaluated_condition is not False: group_depend.extract_group_members(cached_pkgs.values()) # for ROS 2 distributions bloom injects a dependency on ros_workspace # into almost all packages (except its dependencies) # therefore the same dependency needs to to be injected here distribution_type = index.distributions[rosdistro_name].get( 'distribution_type') if distribution_type == 'ros2' and 'ros_workspace' in cached_pkgs: no_ros_workspace_dep = set(['ros_workspace']).union( get_direct_dependencies('ros_workspace', cached_pkgs, pkg_names)) for pkg_name, pkg in cached_pkgs.items(): if pkg_name not in no_ros_workspace_dep: pkg.exec_depends.append(Dependency('ros_workspace')) return cached_pkgs
def test_dependency_repr(self): dep = Dependency('foo', condition='$foo == 2') assert repr(dep) == "Dependency(name='foo', condition='$foo == 2')" self.assertTrue(dep.evaluate_condition({'foo': 2})) assert repr(dep) == "Dependency(name='foo', condition='$foo == 2', evaluated_condition=True)" self.assertFalse(dep.evaluate_condition({'foo': 3})) assert repr(dep) == "Dependency(name='foo', condition='$foo == 2', evaluated_condition=False)"
def fake_gitlab_package(project, name, version="0.0.0", depends=[]): m = Manifest(name, name=name, version=version, depends=[Dependency(d) for d in depends]) pkg = gl.GitlabPackage(manifest=m, project=project) project.packages.append(pkg) return pkg
def test_init_dependency(self): dep = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=5, condition='$foo == 23 and $bar != 42') self.assertEquals('foo', dep.name) self.assertEquals(1, dep.version_lt) self.assertEquals(2, dep.version_lte) self.assertEquals(3, dep.version_eq) self.assertEquals(4, dep.version_gte) self.assertEquals(5, dep.version_gt) self.assertFalse(dep.evaluate_condition({'foo': 23, 'bar': 42})) self.assertFalse(dep.evaluated_condition) self.assertTrue(dep.evaluate_condition({'foo': 23, 'bar': 43})) self.assertTrue(dep.evaluated_condition) self.assertRaises(TypeError, Dependency, 'foo', unknownattribute=42) d = {} d[dep] = None dep2 = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=5, condition='$foo == 23 and $bar != 42') dep2.evaluate_condition({'foo': 23, 'bar': 43}) d[dep2] = None self.assertEquals(len(d), 1) dep3 = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=6) d[dep3] = None self.assertEquals(len(d), 2) dep = Dependency('foo', condition='foo > bar and bar < baz') self.assertTrue(dep.evaluate_condition({})) dep = Dependency('foo', condition='foo <= bar or bar >= baz') self.assertFalse(dep.evaluate_condition({}))
def create_manifest2(name, description="", buildtool_depends=["catkin"], build_depends=[], depends=[], buildtool_export_depends=[], build_export_depends=[], exec_depends=[], test_depends=[], meta=False): package = Package( name=name, version="0.0.0", package_format=2, description=description, maintainers=[Person("John Foo", "*****@*****.**")], depends=[Dependency(d) for d in depends], buildtool_depends=[Dependency(d) for d in buildtool_depends], build_depends=[Dependency(d) for d in build_depends], buildtool_export_depends=[ Dependency(d) for d in buildtool_export_depends ], build_export_depends=[Dependency(d) for d in build_export_depends], exec_depends=[Dependency(d) for d in exec_depends], test_depends=[Dependency(d) for d in test_depends], exports=[Export("metapackage")] if meta else []) if hasattr(package, "evaluate_conditions"): package.evaluate_conditions({}) return package
def test_evaluate_conditions(self): """Test if dependency conditions are properly evaluated""" env = create_env(system_pkgs=['python-yaml']) pkg = Package( name="mock", package_format=3, exec_depends=[ Dependency('python-yaml', condition='$ROS_PYTHON_VERSION == 2'), Dependency('python3-yaml', condition='$ROS_PYTHON_VERSION == 3') ], ) pkg.evaluate_conditions({'ROS_PYTHON_VERSION': 2}) result = mock_lint(env, pkg, "", checks=cc.depends) self.assertEqual([], result) pkg.evaluate_conditions({'ROS_PYTHON_VERSION': 3}) result = mock_lint(env, pkg, "", checks=cc.depends) self.assertEqual(["UNKNOWN_PACKAGE"], result)
def test_init_dependency(self): dep = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=5) self.assertEquals('foo', dep.name) self.assertEquals(1, dep.version_lt) self.assertEquals(2, dep.version_lte) self.assertEquals(3, dep.version_eq) self.assertEquals(4, dep.version_gte) self.assertEquals(5, dep.version_gt) self.assertRaises(TypeError, Dependency, 'foo', unknownattribute=42)
def extract_data(cmakelists): with open(cmakelists, 'r') as h: content = h.read() content = remove_cmake_comments(content) data = {} data['name'] = extract_project_name(content) if not data['name']: raise RuntimeError("Failed to extract project name from '%s'" % cmakelists) build_depends = extract_build_dependencies(content) data['build_depends'] = [Dependency(name) for name in build_depends] return data
def extract_data(**kwargs): if 'name' not in kwargs: raise RuntimeError( "setup() function invoked without the keyword argument 'name'") data = {'name': kwargs['name']} if 'install_requires' in kwargs: data['build_depends'] = [] for install_require in kwargs['install_requires']: # split of version specifiers name = re.split(r'<|>|<=|>=|==|!=', install_require)[0] # map from Python package name to ROS package name convention name = name.rstrip().replace('-', '_') data['build_depends'].append(Dependency(name)) return data
def test_validate_package(self): maint = self.get_maintainer() pack = Package('foo', name='bar_2go', package_format='1', version='0.0.0', version_abi='pabi', description='pdesc', licenses=['BSD'], maintainers=[maint]) pack.validate() # check invalid names pack.name = '2bar' pack.validate() pack.name = 'bar bza' self.assertRaises(InvalidPackage, Package.validate, pack) pack.name = 'bar-bza' # valid for now because for backward compatibility only #self.assertRaises(InvalidPackage, Package.validate, pack) pack.name = 'BAR' pack.validate() # check authors emails pack.name = 'bar' auth1 = Mock() auth2 = Mock() auth2.validate.side_effect = InvalidPackage('foo') pack.authors = [auth1, auth2] self.assertRaises(InvalidPackage, Package.validate, pack) pack.authors = [] pack.validate() # check maintainer required with email pack.maintainers = [] self.assertRaises(InvalidPackage, Package.validate, pack) pack.maintainers = [maint] maint.email = None self.assertRaises(InvalidPackage, Package.validate, pack) maint.email = '*****@*****.**' for dep_type in [ pack.build_depends, pack.buildtool_depends, pack.build_export_depends, pack.buildtool_export_depends, pack.exec_depends, pack.test_depends, pack.doc_depends ]: pack.validate() depend = Dependency(pack.name) dep_type.append(depend) self.assertRaises(InvalidPackage, Package.validate, pack) dep_type.remove(depend)
def test_validate_package(self): maint = self.get_maintainer() pack = Package('foo', name='bar_2go', package_format='1', version='0.0.1', description='pdesc', licenses=['BSD'], maintainers=[maint]) pack.validate() # names that should error pack.name = 'bar bza' self.assertRaises(InvalidPackage, Package.validate, pack) pack.name = 'foo%' self.assertRaises(InvalidPackage, Package.validate, pack) # names that should throw warnings pack.name = '2bar' warnings = [] pack.validate(warnings=warnings) self.assertIn('naming conventions', warnings[0]) pack.name = 'bar-bza' warnings = [] pack.validate(warnings=warnings) self.assertEquals(warnings, []) pack.name = 'BAR' warnings = [] pack.validate(warnings=warnings) self.assertIn('naming conventions', warnings[0]) # dashes are permitted for a non-catkin package pack.exports.append(Export('build_type', 'other')) pack.name = 'bar-bza' warnings = [] pack.validate(warnings=warnings) self.assertEquals(warnings, []) pack.exports.pop() # check authors emails pack.name = 'bar' auth1 = Mock() auth2 = Mock() auth2.validate.side_effect = InvalidPackage('foo') pack.authors = [auth1, auth2] self.assertRaises(InvalidPackage, Package.validate, pack) pack.authors = [] pack.validate() # check maintainer required with email pack.maintainers = [] self.assertRaises(InvalidPackage, Package.validate, pack) pack.maintainers = [maint] maint.email = None self.assertRaises(InvalidPackage, Package.validate, pack) maint.email = '*****@*****.**' for dep_type in [ pack.build_depends, pack.buildtool_depends, pack.build_export_depends, pack.buildtool_export_depends, pack.exec_depends, pack.test_depends, pack.doc_depends ]: pack.validate() depend = Dependency(pack.name) dep_type.append(depend) self.assertRaises(InvalidPackage, Package.validate, pack) dep_type.remove(depend)
def main(self, *, args): available_licenses = {} for shortname, entry in ament_copyright.get_licenses().items(): available_licenses[entry.spdx] = entry.license_files if args.license == '?': print('Supported licenses:\n%s' % ('\n'.join(available_licenses))) sys.exit(0) maintainer = Person(args.maintainer_name) if args.maintainer_email: maintainer.email = args.maintainer_email else: # try getting the email from the global git config git = shutil.which('git') if git is not None: p = subprocess.Popen([git, 'config', 'user.email'], stdout=subprocess.PIPE) resp = p.communicate() email = resp[0].decode().rstrip() if email: maintainer.email = email if not maintainer.email: maintainer.email = maintainer.name + '@todo.todo' node_name = None library_name = None if args.library_name: library_name = args.library_name if args.node_name: node_name = args.node_name if args.node_name == args.library_name: node_name = args.node_name + '_node' print( '[WARNING] node name can not be equal to the library name', file=sys.stderr) print('[WARNING] renaming node to %s' % node_name, file=sys.stderr) buildtool_depends = [] if args.build_type == 'ament_cmake': if args.library_name: buildtool_depends = ['ament_cmake_ros'] else: buildtool_depends = ['ament_cmake'] test_dependencies = [] if args.build_type == 'ament_cmake': test_dependencies = ['ament_lint_auto', 'ament_lint_common'] if args.build_type == 'ament_python': test_dependencies = [ 'ament_copyright', 'ament_flake8', 'ament_pep257', 'python3-pytest' ] if args.build_type == 'ament_python' and args.package_name == 'test': # If the package name is 'test', there will be a conflict between # the directory the source code for the package goes in and the # directory the tests for the package go in. return "Aborted since 'ament_python' packages can't be named 'test'. Please " + \ 'choose a different package name.' package = Package( package_format=args.package_format, name=args.package_name, version='0.0.0', description=args.description, maintainers=[maintainer], licenses=[args.license], buildtool_depends=[Dependency(dep) for dep in buildtool_depends], build_depends=[Dependency(dep) for dep in args.dependencies], test_depends=[Dependency(dep) for dep in test_dependencies], exports=[Export('build_type', content=args.build_type)]) package_path = os.path.join(args.destination_directory, package.name) if os.path.exists(package_path): return '\nAborted!\nThe directory already exists: ' + package_path + '\nEither ' + \ 'remove the directory or choose a different destination directory or package name' print('going to create a new package') print('package name:', package.name) print('destination directory:', os.path.abspath(args.destination_directory)) print('package format:', package.package_format) print('version:', package.version) print('description:', package.description) print('maintainer:', [str(maintainer) for maintainer in package.maintainers]) print('licenses:', package.licenses) print('build type:', package.get_build_type()) print('dependencies:', [str(dependency) for dependency in package.build_depends]) if node_name: print('node_name:', node_name) if library_name: print('library_name:', library_name) package_directory, source_directory, include_directory = \ create_package_environment(package, args.destination_directory) if not package_directory: return 'unable to create folder: ' + args.destination_directory if args.build_type == 'cmake': populate_cmake(package, package_directory, node_name, library_name) if args.build_type == 'ament_cmake': populate_ament_cmake(package, package_directory, node_name, library_name) if args.build_type == 'ament_python': if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_ament_python(package, package_directory, source_directory, node_name) if node_name: populate_python_node(package, source_directory, node_name) if library_name: populate_python_libary(package, source_directory, library_name) if args.build_type == 'ament_cmake' or args.build_type == 'cmake': if node_name: if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_cpp_node(package, source_directory, node_name) if library_name: if not source_directory or not include_directory: return 'unable to create source or include folder in ' + \ args.destination_directory populate_cpp_library(package, source_directory, include_directory, library_name) if args.license in available_licenses: with open(os.path.join(package_directory, 'LICENSE'), 'w') as outfp: for lic in available_licenses[args.license]: outfp.write(lic) else: print( "\n[WARNING]: Unknown license '%s'. This has been set in the package.xml, but " 'no LICENSE file has been created.\nIt is recommended to use one of the ament ' 'license identitifers:\n%s' % (args.license, '\n'.join(available_licenses)))
def _create_package_template(package_name, description=None, licenses=None, maintainer_names=None, author_names=None, version=None, catkin_deps=None, system_deps=None, boost_comps=None): """ alternative factory method mapping CLI args to argument for Package class :param package_name: :param description: :param licenses: :param maintainer_names: :param authors: :param version: :param catkin_deps: """ # Sort so they are alphebetical licenses = list(licenses or ["TODO"]) licenses.sort() if not maintainer_names: maintainer_names = [getpass.getuser()] maintainer_names = list(maintainer_names or []) maintainer_names.sort() maintainers = [] for maintainer_name in maintainer_names: maintainers.append( Person(maintainer_name, '*****@*****.**' % maintainer_name.split()[-1])) author_names = list(author_names or []) author_names.sort() authors = [] for author_name in author_names: authors.append(Person(author_name)) catkin_deps = list(catkin_deps or []) catkin_deps.sort() pkg_catkin_deps = [] build_depends = [] run_depends = [] buildtool_depends = [Dependency('catkin')] for dep in catkin_deps: if dep.lower() == 'catkin': catkin_deps.remove(dep) continue if dep.lower() == 'genmsg': sys.stderr.write( 'WARNING: Packages with messages or services should not depend on genmsg, but on message_generation and message_runtime\n' ) buildtool_depends.append(Dependency('genmsg')) continue if dep.lower() == 'message_generation': if not 'message_runtime' in catkin_deps: sys.stderr.write( 'WARNING: Packages with messages or services should depend on both message_generation and message_runtime\n' ) build_depends.append(Dependency('message_generation')) continue if dep.lower() == 'message_runtime': if not 'message_generation' in catkin_deps: sys.stderr.write( 'WARNING: Packages with messages or services should depend on both message_generation and message_runtime\n' ) run_depends.append(Dependency('message_runtime')) continue pkg_catkin_deps.append(Dependency(dep)) for dep in pkg_catkin_deps: build_depends.append(dep) run_depends.append(dep) if boost_comps: if not system_deps: system_deps = ['boost'] elif not 'boost' in system_deps: system_deps.append('boost') for dep in system_deps or []: if not dep.lower().startswith('python-'): build_depends.append(Dependency(dep)) run_depends.append(Dependency(dep)) package_temp = PackageTemplate(name=package_name, version=version or '0.0.0', description=description or 'The %s package' % package_name, buildtool_depends=buildtool_depends, build_depends=build_depends, run_depends=run_depends, catkin_deps=catkin_deps, system_deps=system_deps, boost_comps=boost_comps, licenses=licenses, authors=authors, maintainers=maintainers, urls=[]) return package_temp
def test_parse_generated_multi(self): # test with multiple attributes filled maint = self.get_maintainer() pack = PackageTemplate( name='bar', package_format=2, version='0.0.1', version_compatibility='0.0.0', description='pdesc', maintainers=[maint, maint], authors=[maint, maint], licenses=['BSD', 'MIT'], urls=[Url('foo', 'bugtracker'), Url('bar')], build_depends=[Dependency('dep1')], buildtool_depends=[Dependency('dep2'), Dependency('dep3')], run_depends=[Dependency('dep4', version_lt='4')], test_depends=[Dependency('dep5', version_gt='4', version_lt='4')], conflicts=[Dependency('dep6')], replaces=[Dependency('dep7'), Dependency('dep8')], exports=[ Export('architecture_independent'), Export('meta_package') ]) def assertEqualDependencies(deplist1, deplist2): if len(deplist1) != len(deplist1): return False for depx, depy in zip(deplist1, deplist2): for attr in [ 'name', 'version_lt', 'version_lte', 'version_eq', 'version_gte', 'version_gt' ]: if getattr(depx, attr) != getattr(depy, attr): return False return True try: rootdir = tempfile.mkdtemp() file1 = os.path.join(rootdir, 'CMakeLists.txt') file2 = os.path.join(rootdir, PACKAGE_MANIFEST_FILENAME) create_package_files(rootdir, pack, 'groovy') self.assertTrue(os.path.isfile(file1)) self.assertTrue(os.path.isfile(file2)) pack_result = parse_package(file2) self.assertEqual(pack.name, pack_result.name) self.assertEqual(pack.package_format, pack_result.package_format) self.assertEqual(pack.version, pack_result.version) self.assertEqual(pack.version_compatibility, pack_result.version_compatibility) self.assertEqual(pack.description, pack_result.description) self.assertEqual(len(pack.maintainers), len(pack_result.maintainers)) self.assertEqual(len(pack.authors), len(pack_result.authors)) self.assertEqual(len(pack.urls), len(pack_result.urls)) self.assertEqual(pack.urls[0].url, pack_result.urls[0].url) self.assertEqual(pack.urls[0].type, pack_result.urls[0].type) self.assertEqual(pack.licenses, pack_result.licenses) self.assertTrue( assertEqualDependencies(pack.build_depends, pack_result.build_depends)) self.assertTrue( assertEqualDependencies(pack.build_depends, pack_result.build_depends)) self.assertTrue( assertEqualDependencies(pack.buildtool_depends, pack_result.buildtool_depends)) self.assertTrue( assertEqualDependencies(pack.run_depends, pack_result.run_depends)) self.assertTrue( assertEqualDependencies(pack.test_depends, pack_result.test_depends)) self.assertTrue( assertEqualDependencies(pack.conflicts, pack_result.conflicts)) self.assertTrue( assertEqualDependencies(pack.replaces, pack_result.replaces)) self.assertEqual(pack.exports[0].tagname, pack_result.exports[0].tagname) self.assertEqual(pack.exports[1].tagname, pack_result.exports[1].tagname) rdict = generate_distutils_setup(package_xml_path=file2) self.assertEqual( { 'name': 'bar', 'maintainer': u('John Foo <*****@*****.**>, John Foo <*****@*****.**>'), 'description': 'pdesc', 'license': 'BSD, MIT', 'version': '0.0.1', 'author': u('John Foo <*****@*****.**>, John Foo <*****@*****.**>'), 'url': 'bar' }, rdict) finally: shutil.rmtree(rootdir)
def fake_ws_package(project, name, version="0.0.0", depends=[]): m = Manifest(name, name=name, version=version, depends=[Dependency(d) for d in depends]) return ws.Package(manifest=m, workspace_path=name, project=project)
def test_init_dependency(self): dep = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=5, condition='$foo == 23 and $bar != 42') self.assertEqual('foo', dep.name) self.assertEqual(1, dep.version_lt) self.assertEqual(2, dep.version_lte) self.assertEqual(3, dep.version_eq) self.assertEqual(4, dep.version_gte) self.assertEqual(5, dep.version_gt) self.assertFalse(dep.evaluate_condition({'foo': 23, 'bar': 42})) self.assertFalse(dep.evaluated_condition) self.assertTrue(dep.evaluate_condition({'foo': 23, 'bar': 43})) self.assertTrue(dep.evaluated_condition) self.assertRaises(TypeError, Dependency, 'foo', unknownattribute=42) d = {} d[dep] = None dep2 = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=5, condition='$foo == 23 and $bar != 42') dep2.evaluate_condition({'foo': 23, 'bar': 43}) d[dep2] = None self.assertEqual(len(d), 1) dep3 = Dependency('foo', version_lt=1, version_lte=2, version_eq=3, version_gte=4, version_gt=6) d[dep3] = None self.assertEqual(len(d), 2) dep = Dependency('foo', condition='foo > bar and bar < baz') self.assertTrue(dep.evaluate_condition({})) dep = Dependency('foo', condition='foo <= bar or bar >= baz') self.assertFalse(dep.evaluate_condition({})) dep = Dependency('foo', condition='$foo == ""') self.assertTrue(dep.evaluate_condition({})) self.assertFalse(dep.evaluate_condition({'foo': 'foo'})) dep = Dependency('foo', condition='$foo == "foo \' bar"') self.assertTrue(dep.evaluate_condition({'foo': "foo ' bar"})) self.assertFalse(dep.evaluate_condition({})) dep = Dependency('foo', condition="$foo == ''") self.assertTrue(dep.evaluate_condition({})) self.assertFalse(dep.evaluate_condition({'foo': 'foo'})) dep = Dependency('foo', condition="$foo == 'foo \" bar'") self.assertTrue(dep.evaluate_condition({'foo': 'foo " bar'})) self.assertFalse(dep.evaluate_condition({})) # Testing for more than 1 conditions dep = Dependency('foo', condition='foo > bar and bar < baz and foo > bar') self.assertTrue(dep.evaluate_condition({})) dep = Dependency('foo', condition='foo <= bar and bar >= baz and foo > bar') self.assertFalse(dep.evaluate_condition({})) dep = Dependency('foo', condition='foo > bar or bar < baz or foo <= bar') self.assertTrue(dep.evaluate_condition({})) dep = Dependency('foo', condition='foo <= bar or bar >= baz or foo <= bar') self.assertFalse(dep.evaluate_condition({})) dep = Dependency('foo', condition='foo <= bar and bar < baz or foo > bar') self.assertTrue(dep.evaluate_condition({})) dep = Dependency('foo', condition='foo <= bar or bar < baz and foo < bar') self.assertFalse(dep.evaluate_condition({})) dep = Dependency('foo', condition='foo > bar and bar >= baz or foo > bar') self.assertTrue(dep.evaluate_condition({})) dep = Dependency('foo', condition='foo <= bar or bar >= baz and foo < bar') self.assertFalse(dep.evaluate_condition({}))
def main(self, *, args): # when a package-type extension exists, delegate package creation to it. extension = get_package_type_extension(args.build_type) if extension: return extension.create_package(args) maintainer = Person(args.maintainer_name) if args.maintainer_email: maintainer.email = args.maintainer_email else: # try getting the email from the global git config git = shutil.which('git') if git is not None: p = subprocess.Popen([git, 'config', '--global', 'user.email'], stdout=subprocess.PIPE) resp = p.communicate() email = resp[0].decode().rstrip() if email: maintainer.email = email if not maintainer.email: maintainer.email = maintainer.name + '@todo.todo' node_name = None library_name = None if args.library_name: library_name = args.library_name if args.node_name: node_name = args.node_name if args.node_name == args.library_name: node_name = args.node_name + '_node' print( '[WARNING] node name can not be equal to the library name', file=sys.stderr) print('[WARNING] renaming node to %s' % node_name, file=sys.stderr) buildtool_depends = [] if args.build_type == 'ament_cmake': if args.library_name: buildtool_depends = ['ament_cmake_ros'] else: buildtool_depends = ['ament_cmake'] test_dependencies = [] if args.build_type == 'ament_cmake': test_dependencies = ['ament_lint_auto', 'ament_lint_common'] if args.build_type == 'ament_python': test_dependencies = [ 'ament_copyright', 'ament_flake8', 'ament_pep257', 'python3-pytest' ] if args.build_type == 'ament_python' and args.package_name == 'test': # If the package name is 'test', there will be a conflict between # the directory the source code for the package goes in and the # directory the tests for the package go in. return "Aborted since 'ament_python' packages can't be named 'test'. Please " + \ 'choose a different package name.' package = Package( package_format=args.package_format, name=args.package_name, version='0.0.0', description=args.description, maintainers=[maintainer], licenses=[args.license], buildtool_depends=[Dependency(dep) for dep in buildtool_depends], build_depends=[Dependency(dep) for dep in args.dependencies], test_depends=[Dependency(dep) for dep in test_dependencies], exports=[Export('build_type', content=args.build_type)]) package_path = os.path.join(args.destination_directory, package.name) if os.path.exists(package_path): return '\nAborted!\nThe directory already exists: ' + package_path + '\nEither ' + \ 'remove the directory or choose a different destination directory or package name' print('going to create a new package') print('package name:', package.name) print('destination directory:', os.path.abspath(args.destination_directory)) print('package format:', package.package_format) print('version:', package.version) print('description:', package.description) print('maintainer:', [str(maintainer) for maintainer in package.maintainers]) print('licenses:', package.licenses) print('build type:', package.get_build_type()) print('dependencies:', [str(dependency) for dependency in package.build_depends]) if node_name: print('node_name:', node_name) if library_name: print('library_name:', library_name) package_directory, source_directory, include_directory = \ create_package_environment(package, args.destination_directory) if not package_directory: return 'unable to create folder: ' + args.destination_directory if args.build_type == 'cmake': populate_cmake(package, package_directory, node_name, library_name) if args.build_type == 'ament_cmake': populate_ament_cmake(package, package_directory, node_name, library_name) if args.build_type == 'ament_python': if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_ament_python(package, package_directory, source_directory, node_name) if node_name: populate_python_node(package, source_directory, node_name) if library_name: populate_python_libary(package, source_directory, library_name) if args.build_type == 'ament_cmake' or args.build_type == 'cmake': if node_name: if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_cpp_node(package, source_directory, node_name) if library_name: if not source_directory or not include_directory: return 'unable to create source or include folder in ' + \ args.destination_directory populate_cpp_library(package, source_directory, include_directory, library_name)
def main(self, *, args): maintainer = Person(args.maintainer_name) if args.maintainer_email: maintainer.email = args.maintainer_email else: # try getting the email from the global git config git = shutil.which('git') if git is not None: p = subprocess.Popen([git, 'config', '--global', 'user.email'], stdout=subprocess.PIPE) resp = p.communicate() email = resp[0].decode().rstrip() if email: maintainer.email = email if not maintainer.email: maintainer.email = maintainer.name + '@todo.todo' cpp_node_name = None if args.cpp_node_name: cpp_node_name = args.cpp_node_name if args.cpp_node_name == args.cpp_library_name: cpp_node_name = args.cpp_node_name + '_node' print( '[WARNING] node name can not be equal to the library name', file=sys.stderr) print('[WARNING] renaming node to %s' % cpp_node_name, file=sys.stderr) buildtool_depends = args.build_type if args.build_type == 'ament_cmake' and args.cpp_library_name: buildtool_depends = 'ament_cmake_ros' test_dependencies = [] if args.build_type == 'ament_cmake': test_dependencies = ['ament_lint_auto', 'ament_lint_common'] package = Package( package_format=args.package_format, name=args.package_name, version='0.0.0', description=args.description, maintainers=[maintainer], licenses=[args.license], buildtool_depends=[Dependency(buildtool_depends)], build_depends=[Dependency(dep) for dep in args.dependencies], test_depends=[Dependency(dep) for dep in test_dependencies], exports=[Export('build_type', content=args.build_type)]) package_path = os.path.join(args.destination_directory, package.name) if os.path.exists(package_path): return '\nAborted!\nThe directory already exists: ' + package_path + '\nEither ' + \ 'remove the directory or choose a different destination directory or package name' print('going to create a new package') print('package name:', package.name) print('destination directory:', os.path.abspath(args.destination_directory)) print('package format:', package.package_format) print('version:', package.version) print('description:', package.description) print('maintainer:', [str(maintainer) for maintainer in package.maintainers]) print('licenses:', [license_ for license_ in package.licenses]) print('build type:', package.get_build_type()) print('dependencies:', [str(dependency) for dependency in package.build_depends]) if args.cpp_node_name: print('cpp_node_name:', cpp_node_name) if args.cpp_library_name: print('cpp_library_name:', args.cpp_library_name) package_directory, source_directory, include_directory = \ create_package_environment(package, args.destination_directory) if not package_directory: return 'unable to create folder: ' + args.destination_directory if args.build_type == 'cmake': populate_cmake(package, package_directory, cpp_node_name, args.cpp_library_name) if args.build_type == 'ament_cmake': populate_ament_cmake(package, package_directory, cpp_node_name, args.cpp_library_name) if cpp_node_name: if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_cpp_node(package, source_directory, cpp_node_name) if args.cpp_library_name: if not source_directory or not include_directory: return 'unable to create source or include folder in ' + args.destination_directory populate_cpp_library(package, source_directory, include_directory, args.cpp_library_name)