Skip to content

Commit

Permalink
Fix the reported by Viktor ssues
Browse files Browse the repository at this point in the history
  • Loading branch information
droideck committed Jan 25, 2024
1 parent 5483c77 commit 1dd303b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions rpm/bundle-rust-npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""Add 'Provides: bundled(crate(foo)) = version' 'Provides: bundled(npm(bar)) = version' to a Fedora based specfile.
Additionally, add a helper comment with a comulated License metainfo which is based on Cargo.lock and Package-lock.json files content.
You need to have 'cargo install cargo-license' and 'npm install -g license-checker' to be able to run this script.""")
You need to have 'cargo install cargo-license' and 'dnf install npm' to be able to run this script.""")

parser.add_argument('-v', '--verbose',
help="Display verbose operation tracing during command execution",
Expand Down Expand Up @@ -95,6 +95,11 @@ def process_npm_packages(output: str) -> Dict[str, Tuple[str, str]]:
package_name, package_version = PACKAGE_REGEX.match(package).groups()
if package_name not in IGNORED_NPM_PACKAGES:
npm_license = process_npm_license(data['licenses'])
# Check if the package is 'pause-stream' and if the license is 'Apache2'
# If so, replace it with 'Apache-2.0' to match the license in Upstream
# It is a workaround till the pause-stream's fix is released
if package_name == "pause-stream" and "Apache2" in npm_license:
npm_license = npm_license.replace("Apache2", "Apache-2.0")
processed_packages[package_name] = (npm_license, package_version)

return processed_packages
Expand Down Expand Up @@ -227,15 +232,23 @@ def write_provides_bundled(provides_lines: List[str], spec_file: str, cleaned: b
log.error(f"Path {args.npm_path} does not exist or is not a directory")
sys.exit(1)

cleaned = clean_specfile(args.spec_file)
if shutil.which("cargo-license") is None:
log.error("cargo-license is not installed. Please install it with 'cargo install cargo-license' and try again.")
sys.exit(1)
if shutil.which("npm") is None:
log.error("npm is not installed. Please install it with 'dnf install npm' and try again.")
sys.exit(1)

rust_output = run_cmd(["cargo", "license", "--json", "--current-dir", args.cargo_path])
npm_output = run_cmd(["license-checker", "--json", "--start", args.npm_path])
npm_output = run_cmd(["npx", "license-checker", "--json", "--start", args.npm_path])

if rust_output is None or npm_output is None:
log.error("Failed to process dependencies. Ensure cargo-license and license-checker are installed and accessible.")
log.error("Failed to process dependencies. Ensure cargo-license and license-checker are installed and accessible. "
"Also, ensure that Cargo.lock and Package-lock.json files exist in the respective directories.")
sys.exit(1)

cleaned = clean_specfile(args.spec_file)

rust_crates = process_rust_crates(rust_output)
npm_packages = process_npm_packages(npm_output)
provides_lines = build_provides_lines(rust_crates, npm_packages)
Expand Down

0 comments on commit 1dd303b

Please sign in to comment.