Skip to content

Commit

Permalink
Adds a length limited license value to the metadata to for spk conver…
Browse files Browse the repository at this point in the history
…t pip generated packages

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
  • Loading branch information
dcookspi committed Feb 15, 2024
1 parent 270f659 commit c75880f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/spk-convert-pip/spk-convert-pip
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.INFO)
_LOGGER = logging.getLogger()
BAKED_PYTHON_PACKAGES = ("setuptools", "pip", "wheel")

# Longest value this will put into the metadata -> license field
LICENSE_FIELD_LIMIT = 80
# Long license values are truncated to this number of characters to
# allow "..." to be added to the value so show it has been truncated.
LICENSE_FIELD_TRUNCATION_POINT = LICENSE_FIELD_LIMIT - 3
TRUNCATED_VALUE_INDICATOR = "..."

def spk_exe() -> str:
return os.environ.get("SPK_BIN_PATH", "spk")
Expand Down Expand Up @@ -253,10 +259,19 @@ class PipImporter:
assert not info.requires_external, "No support for external requirements"
assert not info.supported_platforms, "No support for supported platforms field"

# The spk default is "Unlicensed", which seems odd
package_license = "Unknown"
if hasattr(info, 'license'):
if info.license is not None:
package_license = str(info.license)
if len(package_license) > LICENSE_FIELD_TRUNCATION_POINT:
packackage_license = package_license[:LICENSE_FIELD_TRUNCATION_POINT] + TRUNCATED_VALUE_INDICATOR

spec = {
"pkg": f"{_to_spk_name(info.name)}/{_to_spk_version(info.version)}",
"sources": [],
"meta": {
"license": package_license,
"labels": {
"spk:generated_by": "spk-convert-pip",
"spk-convert-pip:cli": self._cli_args,
Expand Down

0 comments on commit c75880f

Please sign in to comment.