Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate LICENSE files on ros2 pkg create. #650

Merged
merged 3 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ros2pkg/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
<depend>python3-importlib-resources</depend>
<depend>ros2cli</depend>

<exec_depend>ament_copyright</exec_depend>
<exec_depend>ament_index_python</exec_depend>
<exec_depend>python3-catkin-pkg-modules</exec_depend>
<exec_depend>python3-empy</exec_depend>
<exec_depend>python3-pkg-resources</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>ament_xmllint</test_depend>
Expand Down
23 changes: 22 additions & 1 deletion ros2pkg/ros2pkg/verb/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import subprocess
import sys

import ament_copyright

from catkin_pkg.package import Dependency
from catkin_pkg.package import Export
from catkin_pkg.package import Package
Expand Down Expand Up @@ -56,7 +58,9 @@ def add_arguments(self, parser, cli_name):
parser.add_argument(
'--license',
default='TODO: License declaration',
help='The license attached to this package')
help='The license attached to this package; this can be an arbitrary string, but a '
'LICENSE file will only be generated if it is one of the supported licenses '
"(pass '?' to get a list)")
parser.add_argument(
'--destination-directory',
default=os.curdir,
Expand Down Expand Up @@ -85,6 +89,14 @@ def add_arguments(self, parser, cli_name):
help='name of the empty library')

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:
Expand Down Expand Up @@ -203,3 +215,12 @@ def main(self, *, args):
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)))
7 changes: 4 additions & 3 deletions ros2pkg/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_create_package(self):
'create', 'a_test_package',
'--package-format', '3',
'--description', 'A test package dummy description',
'--license', 'Apache License 2.0',
'--license', 'Apache License, Version 2.0',
'--build-type', 'ament_cmake',
'--dependencies', 'ros2pkg',
'--maintainer-email', 'nobody@nowhere.com',
Expand All @@ -146,7 +146,7 @@ def test_create_package(self):
'version: 0.0.0',
'description: A test package dummy description',
"maintainer: ['Nobody <nobody@nowhere.com>']",
"licenses: ['Apache License 2.0']",
"licenses: ['Apache License, Version 2.0']",
'build type: ament_cmake',
"dependencies: ['ros2pkg']",
'node_name: test_node',
Expand Down Expand Up @@ -179,6 +179,7 @@ def test_create_package(self):
assert os.path.isdir(os.path.join(tmpdir, 'a_test_package'))
assert os.path.isfile(os.path.join(tmpdir, 'a_test_package', 'package.xml'))
assert os.path.isfile(os.path.join(tmpdir, 'a_test_package', 'CMakeLists.txt'))
assert os.path.isfile(os.path.join(tmpdir, 'a_test_package', 'LICENSE'))
assert os.path.isfile(
os.path.join(tmpdir, 'a_test_package', 'src', 'test_node.cpp')
)
Expand All @@ -200,6 +201,6 @@ def test_create_package(self):
assert root.find('description').text == 'A test package dummy description'
assert root.find('maintainer').text == 'Nobody'
assert root.find('maintainer').attrib['email'] == 'nobody@nowhere.com'
assert root.find('license').text == 'Apache License 2.0'
assert root.find('license').text == 'Apache License, Version 2.0'
clalancette marked this conversation as resolved.
Show resolved Hide resolved
assert root.find('depend').text == 'ros2pkg'
assert root.find('.//build_type').text == 'ament_cmake'