Skip to content

Commit

Permalink
Adds metadata to spk convert pip generated packages to record that th…
Browse files Browse the repository at this point in the history
…ey were generated and what command was used.

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
  • Loading branch information
dcookspi committed Feb 15, 2024
1 parent 1ea1eb6 commit b75fe61
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/spk-convert-pip/spk-convert-pip
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ def main() -> int:
metavar="NAME[VERSION]",
help="The pip packages to import (eg: pytest, PySide2>=5)",
)
original_cmd_and_args = " ".join(sys.argv)
args = pip_cmd.parse_args()

specs = []
importer = PipImporter().recursive(args.deps)
importer = PipImporter().with_cli_args(original_cmd_and_args).recursive(args.deps)
if args.python_version:
importer.with_python_version(args.python_version)
if args.python_abi:
Expand Down Expand Up @@ -127,6 +128,11 @@ class PipImporter:
self._python_abi: Optional[str] = "cp37m"
self._follow_deps = True
self._visited: Dict[str, VisitedPackage] = {}
self._cli_args = ""

def with_cli_args(self, cli_args: str) -> "PipImporter":
self._cli_args = cli_args
return self

def with_python_version(self, version: str) -> "PipImporter":
assert (
Expand Down Expand Up @@ -247,9 +253,22 @@ class PipImporter:
assert not info.requires_external, "No support for external requirements"
assert not info.supported_platforms, "No support for supported platforms field"

package_license = "Unknown"
if hasattr(info, 'license'):
if info.license is not None:
package_license = info.license

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,
},
},

"build": {
"options": [
{"var": "os"},
Expand Down

0 comments on commit b75fe61

Please sign in to comment.