Skip to content

Commit

Permalink
🧹 improve python author (#2638)
Browse files Browse the repository at this point in the history
* 🧹 improve author for python package

* 🧹 use separate field for python author email
  • Loading branch information
chris-rock authored Nov 27, 2023
1 parent b5d26ea commit f9e7048
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions providers/os/resources/os.lr
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,8 @@ python.package @defaults("name version") {
license() string
// Author of the package
author() string
// Author email of the package
authorEmail() string
// Short package description
summary() string
// Package URL
Expand Down
14 changes: 14 additions & 0 deletions providers/os/resources/os.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions providers/os/resources/os.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ resources:
python.package:
fields:
author: {}
authorEmail: {}
cpe: {}
cpes: {}
dependencies: {}
Expand Down
2 changes: 2 additions & 0 deletions providers/os/resources/python/mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type PackageDetails struct {
File string
License string
Author string
AuthorEmail string
Summary string
Version string
Dependencies []string
Expand Down Expand Up @@ -66,6 +67,7 @@ func ParseMIME(r io.Reader, pythonMIMEFilepath string) (*PackageDetails, error)
Name: mimeData.Get("Name"),
Summary: mimeData.Get("Summary"),
Author: mimeData.Get("Author"),
AuthorEmail: mimeData.Get("Author-email"),
License: mimeData.Get("License"),
Version: mimeData.Get("Version"),
Dependencies: deps,
Expand Down
2 changes: 2 additions & 0 deletions providers/os/resources/python/mine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ License-File: LICENSE
pkg, err := ParseMIME(strings.NewReader(content), "/usr/lib/python3.11/site-packages/pyftpdlib-1.5.7-py3.11.egg-info/PKG-INFO")
require.NoError(t, err)

assert.Equal(t, "Giampaolo Rodola'", pkg.Author)
assert.Equal(t, "[email protected]", pkg.AuthorEmail)
assert.Equal(t, "pyftpdlib", pkg.Name)
assert.Equal(t, "1.5.7", pkg.Version)
assert.Equal(t, "MIT", pkg.License)
Expand Down
10 changes: 10 additions & 0 deletions providers/os/resources/python_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func (k *mqlPythonPackage) author() (string, error) {
return k.Author.Data, nil
}

func (k *mqlPythonPackage) authorEmail() (string, error) {
err := k.populateData()
if err != nil {
return "", err
}
return k.AuthorEmail.Data, nil
}

func (k *mqlPythonPackage) summary() (string, error) {
err := k.populateData()
if err != nil {
Expand Down Expand Up @@ -126,6 +134,7 @@ func (k *mqlPythonPackage) populateData() error {
k.Name = plugin.TValue[string]{Data: ppd.Name, State: plugin.StateIsSet}
k.Version = plugin.TValue[string]{Data: ppd.Version, State: plugin.StateIsSet}
k.Author = plugin.TValue[string]{Data: ppd.Author, State: plugin.StateIsSet}
k.AuthorEmail = plugin.TValue[string]{Data: ppd.AuthorEmail, State: plugin.StateIsSet}
k.Summary = plugin.TValue[string]{Data: ppd.Summary, State: plugin.StateIsSet}
k.License = plugin.TValue[string]{Data: ppd.License, State: plugin.StateIsSet}
k.Dependencies = plugin.TValue[[]interface{}]{Data: convert.SliceAnyToInterface(ppd.Dependencies), State: plugin.StateIsSet}
Expand Down Expand Up @@ -171,6 +180,7 @@ func newMqlPythonPackage(runtime *plugin.Runtime, ppd python.PackageDetails, dep
"name": llx.StringData(ppd.Name),
"version": llx.StringData(ppd.Version),
"author": llx.StringData(ppd.Author),
"authorEmail": llx.StringData(ppd.AuthorEmail),
"summary": llx.StringData(ppd.Summary),
"license": llx.StringData(ppd.License),
"file": llx.ResourceData(f, f.MqlName()),
Expand Down

0 comments on commit f9e7048

Please sign in to comment.