#16 Add an action to retrieve the SPDX license string from a crate
Closed by decathorpe. Opened by ozbenh.
fedora-rust/ ozbenh/cargo2rpm add-action-license  into  main

This is useful for a script I'm writing to collect all the bundled
crate licenses for centos-style vendored crates

Signed-off-by: Benjamin Herrenschmidt benh@amazon.com

Sorry for the late response.

I'm wondering if it wouldn't be easier if you used a short Python script directly?

Using cargo2rpm for what you're describing here just adds two layers of indirection:

  • using cargo to read metadata and re-output it in JSON format
  • using cargo2rpm to parse that JSON format and print results

You could do both with plain Python 3.11 and the tomllib module from the Python standard library in probably three lines of Python code, without adding both cargo and cargo2rpm to your script's dependencies.

Ok, depending on how you do it, four lines of dependency-free Python 3.11 code:

import tomllib
with file = open("Cargo.toml"):
    toml = tomllib.loads(file.read())
license = toml["package"]["license"]

Pull-Request has been closed by decathorpe