Skip to content

Commit

Permalink
CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino committed Sep 18, 2024
1 parent 3f25abf commit 8106d1f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions utils/pythonutils/piputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func getPackageDetailsFromSetuppy(srcPath string) (packageName string, packageVe
}

// Extract package name from setup.py.
packageName, packageVersion, err = ExtractPackageNameFromSetupPy(filePath)
packageName, packageVersion, err = extractPackageNameFromSetupPy(filePath)
if err != nil {
// If setup.py egg_info command failed we use build name as module name and continue to pip-install execution
return "", "", errors.New("couldn't determine module-name after running the 'egg_info' command: " + err.Error())
Expand All @@ -96,7 +96,7 @@ func getSetupPyFilePath(srcPath string) (string, error) {
}

// Get the project name and version by running 'egg_info' command on setup.py and extracting it from 'PKG-INFO' file.
func ExtractPackageNameFromSetupPy(setuppyFilePath string) (string, string, error) {
func extractPackageNameFromSetupPy(setuppyFilePath string) (string, string, error) {
// Execute egg_info command and return PKG-INFO content.
content, err := getEgginfoPkginfoContent(setuppyFilePath)
if err != nil {
Expand Down Expand Up @@ -184,7 +184,7 @@ func extractPackageNameFromEggBase(eggBase string) ([]byte, error) {
// If pattern of package name of version not found, return an error.
func getProjectNameAndVersionFromFileContent(content []byte) (string, string, error) {
// Create package-name regexp.
packageNameRegexp := regexp.MustCompile(`(?m)^Name:\s` + _packageNameRegexp)
packageNameRegexp := regexp.MustCompile(`(?m)^Name:\s` + packageNameRegexp)

// Find first nameMatch of packageNameRegexp.
nameMatch := packageNameRegexp.FindStringSubmatch(string(content))
Expand All @@ -193,7 +193,7 @@ func getProjectNameAndVersionFromFileContent(content []byte) (string, string, er
}

// Create package-version regexp.
packageVersionRegexp := regexp.MustCompile(`(?m)^Version:\s` + _packageNameRegexp)
packageVersionRegexp := regexp.MustCompile(`(?m)^Version:\s` + packageNameRegexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / Go-Sec

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)) (typecheck)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / Go-Sec

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)) (typecheck)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / Go-Sec

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp) (typecheck)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest, node 14, python 3.8

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / Static-Check

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / Static-Check

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest, node 16, python 3.9

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest, node 16.9, python 3.x

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / windows-latest, node 14, python 3.8

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / windows-latest, node 16, python 3.9

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / windows-latest, node 16.9, python 3.x

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / macos-latest, node 16, python 3.9

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / macos-latest, node 16.9, python 3.x

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / macos-14-large, node 14, python 3.8

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / macos-14-large, node 16, python 3.9

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

Check failure on line 196 in utils/pythonutils/piputils.go

View workflow job for this annotation

GitHub Actions / macos-14-large, node 16.9, python 3.x

invalid operation: `(?m)^Version:\s` + packageNameRegexp (mismatched types untyped string and *regexp.Regexp)

// Find first match of packageNameRegexp.
versionMatch := packageVersionRegexp.FindStringSubmatch(string(content))
Expand All @@ -205,8 +205,8 @@ func getProjectNameAndVersionFromFileContent(content []byte) (string, string, er
}

// Try getting the name and version from pyproject.toml or from setup.py, if those exist.
func GetPipProjectNameAndVersion(srcPath string) (projectName string, projectVersion string, err error) {
projectName, projectVersion, err = GetPipProjectDetailsFromPyProjectToml(srcPath)
func getPipProjectNameAndVersion(srcPath string) (projectName string, projectVersion string, err error) {
projectName, projectVersion, err = getPipProjectDetailsFromPyProjectToml(srcPath)
if err != nil || projectName != "" {
return
}
Expand All @@ -215,15 +215,15 @@ func GetPipProjectNameAndVersion(srcPath string) (projectName string, projectVer

// Returns project ID based on name and version from pyproject.toml or setup.py, if found.
func getPipProjectId(srcPath string) (string, error) {
projectName, projectVersion, err := GetPipProjectNameAndVersion(srcPath)
projectName, projectVersion, err := getPipProjectNameAndVersion(srcPath)
if err != nil || projectName == "" {
return "", err
}
return projectName + ":" + projectVersion, nil
}

// Try getting the name and version from pyproject.toml.
func GetPipProjectDetailsFromPyProjectToml(srcPath string) (projectName string, projectVersion string, err error) {
func getPipProjectDetailsFromPyProjectToml(srcPath string) (projectName string, projectVersion string, err error) {
filePath, err := getPyProjectFilePath(srcPath)
if err != nil || filePath == "" {
return
Expand Down
2 changes: 1 addition & 1 deletion utils/pythonutils/twineutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func getArtifactsParser(artifactsPaths *[]string) (parser *gofrogcmd.CmdOutputPa

// Create artifacts entities from the artifacts paths that were found during the upload.
func CreateArtifactsFromPaths(artifactsPaths []string) (artifacts []entities.Artifact, err error) {
projectName, projectVersion, err := GetPipProjectNameAndVersion("")
projectName, projectVersion, err := getPipProjectNameAndVersion("")
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions utils/pythonutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
startUsingCachedPattern = `^\s*Using\scached\s`
usingCacheCaptureGroup = `[\S]+`
endPattern = `\s\(`
_packageNameRegexp = `(\w[\w-.]+)`
packageNameRegexp = `(\w[\w-.]+)`
)

type PythonTool string
Expand Down Expand Up @@ -277,7 +277,7 @@ func InstallWithLogParsing(tool PythonTool, commandArgs []string, log utils.Log,

// Extract downloaded package name.
parsers = append(parsers, &gofrogcmd.CmdOutputPattern{
RegExp: regexp.MustCompile(`^Collecting\s` + _packageNameRegexp),
RegExp: regexp.MustCompile(`^Collecting\s` + packageNameRegexp),
ExecFunc: func(pattern *gofrogcmd.CmdOutputPattern) (string, error) {
// If this pattern matched a second time before downloaded-file-name was found, prompt a message.
if expectingPackageFilePath {
Expand Down Expand Up @@ -330,7 +330,7 @@ func InstallWithLogParsing(tool PythonTool, commandArgs []string, log utils.Log,

// Extract already installed packages names.
parsers = append(parsers, &gofrogcmd.CmdOutputPattern{
RegExp: regexp.MustCompile(`^Requirement\salready\ssatisfied:\s` + _packageNameRegexp),
RegExp: regexp.MustCompile(`^Requirement\salready\ssatisfied:\s` + packageNameRegexp),
ExecFunc: func(pattern *gofrogcmd.CmdOutputPattern) (string, error) {
// Check for out of bound results.
if len(pattern.MatchedResults)-1 < 0 {
Expand Down

0 comments on commit 8106d1f

Please sign in to comment.