Skip to content

Commit

Permalink
license creation failing because of wrong path (#58)
Browse files Browse the repository at this point in the history
* changed doc string of generate_copyright_file

---------

Signed-off-by: Anton Utz <[email protected]>
Co-authored-by: Christian Henkel <[email protected]>
  • Loading branch information
ant-u and ct2034 committed Mar 28, 2024
1 parent f40b8bb commit 4febc86
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"gitpython",
"rospkg",
"scancode-toolkit>=32.0.8",
"spdx-tools"
"spdx-tools<=0.7.1"
]
requires-python = ">=3.7"

Expand Down
28 changes: 21 additions & 7 deletions src/ros_license_toolkit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ def main(args: Optional[Sequence[str]] = None) -> int:
results_per_package.update(
process_one_pkg(rll_print, package))

# Generate copyright file
if parsed_args.generate_copyright_file:
if len(packages) == 1:
package = packages[0]
package.write_copyright_file(
os.path.join(os.getcwd(), 'copyright'))
if max(results_per_package.values()) != Status.FAILURE:
if parsed_args.generate_copyright_file:
generate_copyright_file(packages, rll_print)
else:
rll_print(red(
"Can only generate copyright file for single package"),
"Copyright file will not be generated "
+ "because there were linter errors."),
Verbosity.QUIET)

stop = timeit.default_timer()
Expand All @@ -123,6 +121,22 @@ def main(args: Optional[Sequence[str]] = None) -> int:
return os.EX_DATAERR


def generate_copyright_file(packages, rll_print):
"""Generate copyright file. In case more than one package
is provided, display error message."""
if len(packages) == 1:
package = packages[0]
try:
package.write_copyright_file(
os.path.join(os.getcwd(), 'copyright'))
except AssertionError as error:
rll_print(red(str(error)))
else:
rll_print(red(
"Can only generate copyright file for single package"),
Verbosity.QUIET)


def process_one_pkg(rll_print, package):
"""Perform checks on one package, print results and return them."""
results_per_package = {}
Expand Down
12 changes: 7 additions & 5 deletions src/ros_license_toolkit/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ def get_copyright_file_contents(self) -> str:
cpr_str += f"\nLicense: {pkg_license.id}\n"
assert pkg_license.license_text_file, \
"License text file must be defined."
with open(os.path.join(
self.abspath,
pkg_license.license_text_file),
encoding="utf-8"
) as f:
license_path = os.path.join(self.abspath,
pkg_license.license_text_file)
if not os.path.exists(license_path):
raise FileExistsError(
('Cannot create copyright file.'
f'File {license_path} does not exist.'))
with open(license_path, encoding="utf-8") as f:
license_lines = f.readlines()
for line in license_lines:
cpr_str += f" {line}"
Expand Down

0 comments on commit 4febc86

Please sign in to comment.