示例#1
0
 def do_environment(self):
     env = catkin_lint.environment.CatkinEnvironment(use_rosdep=False)
     mock_packages = {}
     mock_packages[os.path.normpath("/mock_catkin")] = create_manifest(
         "mock_catkin")
     mock_packages[os.path.normpath("/mock_other")] = create_manifest(
         "mock_other")
     mock_packages[os.path.normpath("/mock_other")].exports += [
         Export("random_tag"),
         Export("build_type", "cmake")
     ]
     old_find = catkin_lint.environment.find_packages
     catkin_lint.environment.find_packages = lambda x, use_cache: mock_packages
     result = env.add_path(os.path.normpath("/"))
     self.assertEqual(1, len(result))
     self.assertTrue(env.is_catkin_pkg("mock_catkin"))
     self.assertFalse(env.is_catkin_pkg("mock_other"))
     self.assertFalse(env.is_system_pkg("mock_catkin"))
     self.assertTrue(env.is_system_pkg("mock_other"))
     result = env.add_path(os.path.normpath("/"))
     self.assertEqual(1, len(result))
     self.assertTrue(env.is_catkin_pkg("mock_catkin"))
     self.assertFalse(env.is_catkin_pkg("mock_other"))
     self.assertFalse(env.is_system_pkg("mock_catkin"))
     self.assertTrue(env.is_system_pkg("mock_other"))
     result = env.add_path(os.path.normpath("/missing"))
     self.assertEqual([], result)
     catkin_lint.environment.find_packages = old_find
示例#2
0
    def test_environment(self):
        """Test catkin environment"""
        env = catkin_lint.environment.CatkinEnvironment(use_rosdep=False)
        mock_packages = {}
        mock_packages[os.path.normpath("/mock_catkin")] = create_manifest(
            "mock_catkin")
        mock_packages[os.path.normpath("/mock_other")] = create_manifest(
            "mock_other")
        mock_packages[os.path.normpath("/mock_other")].exports += [
            Export("random_tag"),
            Export("build_type", "cmake")
        ]
        with patch("catkin_lint.environment.find_packages",
                   lambda x, use_cache: mock_packages):
            result = env.add_path(os.path.normpath("/"))
            self.assertEqual(1, len(result))
            self.assertTrue(env.is_catkin_pkg("mock_catkin"))
            self.assertFalse(env.is_catkin_pkg("mock_other"))
            result = env.add_path(os.path.normpath("/"))
            self.assertEqual(1, len(result))
            self.assertTrue(env.is_catkin_pkg("mock_catkin"))
            self.assertFalse(env.is_catkin_pkg("mock_other"))
            result = env.add_path(os.path.normpath("/missing"))
            self.assertEqual([], result)
            self.assertFalse(env.is_catkin_pkg("invalid"))

        def raiseError():
            raise RuntimeError()

        with open(os.devnull, "w") as devnull:
            with patch("catkin_lint.environment.get_rosdep", raiseError):
                with patch("sys.stderr", devnull):
                    env = catkin_lint.environment.CatkinEnvironment()
                    self.assertFalse(env.ok)
        self.assertFalse(catkin_lint.environment.is_catkin_package(None))
示例#3
0
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
示例#4
0
def parse_package(path):
    if not package_exists_at(path):
        return None
    cmakelists = os.path.join(path, 'CMakeLists.txt')
    data = extract_data(cmakelists)
    pkg = Package(filename=cmakelists, **data)
    pkg.exports = [Export('build_type', content='cmake')]
    return pkg
示例#5
0
def parse_package(path):
    if not package_exists_at(path):
        return None
    setuppy = os.path.join(path, 'setup.py')
    kwargs = get_setup_arguments(setuppy)
    data = extract_data(**kwargs)
    pkg = Package(filename=setuppy, **data)
    pkg.exports = [Export('build_type', content='ament_python')]
    return pkg
示例#6
0
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 []
    )
示例#7
0
    def do_plugins(self):
        from catkin_pkg.package import Export
        env = create_env()
        pkg = create_manifest("mock", run_depends=[ "other_catkin" ])
        plugin = Export("other_catkin")
        plugin.attributes = { "plugin": "${prefix}/config.xml" }
        pkg.exports += [ plugin ]
        result = mock_lint(env, pkg, "install(FILES config.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})", checks=cc.plugins)
        self.assertEqual([], result)

        result = mock_lint(env, pkg, "", checks=cc.plugins)
        self.assertEqual([ "PLUGIN_MISSING_INSTALL" ], result)

        result = mock_lint(env, pkg, "install(FILES config.xml DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})", checks=cc.plugins)
        self.assertEqual([ "PLUGIN_MISSING_INSTALL" ], result)

        pkg = create_manifest("mock", run_depends=[ "other_catkin" ])
        plugin = Export("other_catkin")
        plugin.attributes = { "plugin": "config.xml" }
        pkg.exports += [ plugin ]
        result = mock_lint(env, pkg, "install(FILES config.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})", checks=cc.plugins)
        self.assertEqual([ "PLUGIN_EXPORT_PREFIX" ], result)

        pkg = create_manifest("mock")
        plugin = Export("other_catkin")
        plugin.attributes = { "plugin": "${prefix}/config.xml" }
        pkg.exports += [ plugin ]
        result = mock_lint(env, pkg, "install(FILES config.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})", checks=cc.plugins)
        self.assertEqual([ "PLUGIN_DEPEND" ], result)

        pkg = create_manifest("mock", run_depends=[ "other_catkin" ])
        plugin = Export("other_catkin")
        plugin.attributes = { "plugin": "${prefix}/missing_config.xml" }
        pkg.exports += [ plugin ]
        result = mock_lint(env, pkg, "install(FILES missing_config.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})", checks=cc.plugins)
        self.assertEqual([ "PLUGIN_MISSING_FILE" ], result)
示例#8
0
    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)
示例#9
0
文件: create.py 项目: seanyen/ros2cli
    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)))
示例#10
0
def convert_manifest_export(man_export):
    e = Export(man_export.tag, man_export.str)
    e.attributes = man_export.attrs
    return e
示例#11
0
    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)
示例#12
0
    def do_plugins(self):
        from catkin_pkg.package import Export
        env = create_env()
        pkg = create_manifest("mock", run_depends=["other_catkin"])
        plugin = Export("other_catkin")
        plugin.attributes = {"plugin": "${prefix}/config.xml"}
        pkg.exports += [plugin]
        result = mock_lint(
            env,
            pkg,
            "install(FILES config.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})",
            checks=cc.plugins)
        self.assertEqual([], result)

        result = mock_lint(env, pkg, "", checks=cc.plugins)
        self.assertEqual(["PLUGIN_MISSING_INSTALL"], result)

        result = mock_lint(
            env,
            pkg,
            "install(FILES config.xml DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})",
            checks=cc.plugins)
        self.assertEqual(["PLUGIN_MISSING_INSTALL"], result)

        pkg = create_manifest("mock", run_depends=["other_catkin"])
        plugin = Export("other_catkin")
        plugin.attributes = {"plugin": "config.xml"}
        pkg.exports += [plugin]
        result = mock_lint(
            env,
            pkg,
            "install(FILES config.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})",
            checks=cc.plugins)
        self.assertEqual(["PLUGIN_EXPORT_PREFIX"], result)

        pkg = create_manifest("mock")
        plugin = Export("other_catkin")
        plugin.attributes = {"plugin": "${prefix}/config.xml"}
        pkg.exports += [plugin]
        result = mock_lint(
            env,
            pkg,
            "install(FILES config.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})",
            checks=cc.plugins)
        self.assertEqual(["PLUGIN_DEPEND"], result)

        pkg = create_manifest("mock", run_depends=["other_catkin"])
        plugin = Export("other_catkin")
        plugin.attributes = {"plugin": "${prefix}/missing_config.xml"}
        pkg.exports += [plugin]
        result = mock_lint(
            env,
            pkg,
            "install(FILES missing_config.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})",
            checks=cc.plugins)
        self.assertEqual(["PLUGIN_MISSING_FILE"], result)
示例#13
0
文件: create.py 项目: ruffsl/ros2cli
    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)
示例#14
0
def convert_manifest_export(man_export):
    e = Export(man_export.tag, man_export.str)
    e.attributes = man_export.attrs
    return e
示例#15
0
    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)