Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 74 additions & 2 deletions buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"

"github.com/BurntSushi/toml"
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/container/strategies"

"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/setup"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
Expand Down Expand Up @@ -1161,6 +1162,49 @@ func getCommandName(orgArgs []string) (string, []string) {
return "", cmdArgs
}

// getPrimarySourceFromToml reads pyproject.toml and returns the name of the primary source
// Returns (sourceName, isPrimary) where isPrimary indicates if source has priority='primary'
func getPrimarySourceFromToml() (string, bool) {
type PyProjectSource struct {
Name string `toml:"name"`
URL string `toml:"url"`
Priority string `toml:"priority"`
}

type PyProject struct {
Tool struct {
Poetry struct {
Source []PyProjectSource `toml:"source"`
} `toml:"poetry"`
} `toml:"tool"`
}

tomlPath := filepath.Join(".", "pyproject.toml")
tomlData, err := os.ReadFile(tomlPath)
if err != nil {
return "", false
}

var pyproject PyProject
if err := toml.Unmarshal(tomlData, &pyproject); err != nil {
return "", false
}

// Look for primary source
for _, source := range pyproject.Tool.Poetry.Source {
if source.Priority == "primary" {
return source.Name, true
}
}

// If no primary, use first source
if len(pyproject.Tool.Poetry.Source) > 0 {
return pyproject.Tool.Poetry.Source[0].Name, false
}

return "", false
}

func NpmInstallCmd(c *cli.Context) error {
if show, err := cliutils.ShowGenericCmdHelpIfNeeded(c, c.Args(), "npminstallhelp"); show || err != nil {
return err
Expand Down Expand Up @@ -1353,6 +1397,34 @@ func pythonCmd(c *cli.Context, projectType project.ProjectType) error {
}
cmdName, poetryArgs := getCommandName(filteredArgs)

// Extract --repository flag for artifact collection (if publishing)
deployerRepo := ""
for i, arg := range poetryArgs {
if strings.HasPrefix(arg, "--repository=") {
deployerRepo = strings.TrimPrefix(arg, "--repository=")
} else if (arg == "--repository" || arg == "-r") && i+1 < len(poetryArgs) {
deployerRepo = poetryArgs[i+1]
}
}

// Auto-add repository flag if not provided and we're publishing
if cmdName == "publish" && deployerRepo == "" {
// Try to get primary source from pyproject.toml (same as native Poetry behavior)
if repoName, isPrimary := getPrimarySourceFromToml(); repoName != "" {
if isPrimary {
log.Info(fmt.Sprintf("No --repository flag specified. Using '%s' from pyproject.toml (priority='primary')", repoName))
} else {
log.Info(fmt.Sprintf("No --repository flag specified. Using '%s' from pyproject.toml (first source)", repoName))
}
poetryArgs = append([]string{"-r", repoName}, poetryArgs...)
deployerRepo = repoName
} else {
log.Warn("No repository specified and no sources found in pyproject.toml. Poetry will attempt to publish to PyPI.")
}
} else if cmdName == "publish" && deployerRepo != "" {
log.Info(fmt.Sprintf("Publishing to repository: %s (from --repository flag)", deployerRepo))
}

// Execute native poetry command directly (similar to Maven FlexPack)
log.Info(fmt.Sprintf("Running Poetry %s.", cmdName))
poetryCmd := exec.Command("poetry", append([]string{cmdName}, poetryArgs...)...)
Expand All @@ -1369,7 +1441,7 @@ func pythonCmd(c *cli.Context, projectType project.ProjectType) error {
workingDir, err := os.Getwd()
if err != nil {
log.Warn("Failed to get working directory, skipping build info collection: " + err.Error())
} else if err := buildinfo.GetPoetryBuildInfo(workingDir, buildConfiguration); err != nil {
} else if err := buildinfo.GetPoetryBuildInfo(workingDir, buildConfiguration, deployerRepo); err != nil {
log.Warn("Failed to collect Poetry build info: " + err.Error())
} else {
buildNumber, err := buildConfiguration.GetBuildNumber()
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ replace (
)

require (
github.com/BurntSushi/toml v1.5.0
github.com/agnivade/levenshtein v1.2.1
github.com/buger/jsonparser v1.1.1
github.com/docker/docker v28.5.2+incompatible
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/jfrog/archiver/v3 v3.6.1
github.com/jfrog/build-info-go v1.12.5-0.20251209031413-f5f0e93dc8db
github.com/jfrog/build-info-go v1.12.5-0.20251209120002-025bda5ff78b
github.com/jfrog/gofrog v1.7.6
github.com/jfrog/jfrog-cli-application v1.0.2-0.20251208114900-b3cc968c8e3d
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251209060234-c05dd4957894
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251209121625-98f7b22a08c1
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251125083543-e689762c4ff0
github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20251204144808-73fa744851c0
github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20251205121610-171eb9b0000e
github.com/jfrog/jfrog-cli-security v1.24.0
github.com/jfrog/jfrog-client-go v1.55.1-0.20251209032636-8966184db185
github.com/jszwec/csvutil v1.10.0
github.com/manifoldco/promptui v0.9.0
github.com/spf13/viper v1.21.0
github.com/stretchr/testify v1.11.1
github.com/testcontainers/testcontainers-go v0.35.0
github.com/urfave/cli v1.22.17
Expand All @@ -48,7 +50,6 @@ require (
dario.cat/mergo v1.0.2 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/BurntSushi/toml v1.5.0 // indirect
github.com/CycloneDX/cyclonedx-go v0.9.3 // indirect
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.3 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.30.0 // indirect
Expand Down Expand Up @@ -214,7 +215,6 @@ require (
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/spf13/viper v1.21.0 // indirect
github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect
github.com/stretchr/objx v0.5.3 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,8 @@ github.com/jellydator/ttlcache/v3 v3.4.0 h1:YS4P125qQS0tNhtL6aeYkheEaB/m8HCqdMMP
github.com/jellydator/ttlcache/v3 v3.4.0/go.mod h1:Hw9EgjymziQD3yGsQdf1FqFdpp7YjFMd4Srg5EJlgD4=
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
github.com/jfrog/build-info-go v1.12.5-0.20251209031413-f5f0e93dc8db h1:5q4hUqZVl7Xt+R+ono5lDH1/lkvV1spnfDtp0VtJqlo=
github.com/jfrog/build-info-go v1.12.5-0.20251209031413-f5f0e93dc8db/go.mod h1:9W4U440fdTHwW1HiB/R0VQvz/5q8ZHsms9MWcq+JrdY=
github.com/jfrog/build-info-go v1.12.5-0.20251209120002-025bda5ff78b h1:wf8u5g84GW8ZYsM59UGk+1vvcUOCaP75NiGZeOatkC8=
github.com/jfrog/build-info-go v1.12.5-0.20251209120002-025bda5ff78b/go.mod h1:9W4U440fdTHwW1HiB/R0VQvz/5q8ZHsms9MWcq+JrdY=
github.com/jfrog/froggit-go v1.20.6 h1:Xp7+LlEh0m1KGrQstb+u0aGfjRUtv1eh9xQBV3571jQ=
github.com/jfrog/froggit-go v1.20.6/go.mod h1:obSG1SlsWjktkuqmKtpq7MNTTL63e0ot+ucTnlOMV88=
github.com/jfrog/go-mockhttp v0.3.1 h1:/wac8v4GMZx62viZmv4wazB5GNKs+GxawuS1u3maJH8=
Expand All @@ -1187,8 +1187,8 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
github.com/jfrog/jfrog-cli-application v1.0.2-0.20251208114900-b3cc968c8e3d h1:0o6tj4nPP9uCscyfPbKBUcCaIYof42irwii6XsBB8zM=
github.com/jfrog/jfrog-cli-application v1.0.2-0.20251208114900-b3cc968c8e3d/go.mod h1:xum2HquWO5uExa/A7MQs3TgJJVEeoqTR+6Z4mfBr1Xw=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251209060234-c05dd4957894 h1:PCtFq128LZCCrMtQ/tzZViCDxvzwEvnjHQDzAA8ZVAw=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251209060234-c05dd4957894/go.mod h1:Jb2MTLteycwR+95MfcfLvguo/JcRqILdDpbdnMWveVA=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251209121625-98f7b22a08c1 h1:vT9QWrwW6pJPcHewSVsDWWoCHq+Nt3UqnEaJjyMqFMU=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251209121625-98f7b22a08c1/go.mod h1:b/Sf+FOjWwoQOZ00r+fXMbDqpts8L0q1lMNgS5cofAs=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251125083543-e689762c4ff0 h1:EsasTBE5i2MyCESS/icZxKIlObpGiOyW9K67MAaEWco=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251125083543-e689762c4ff0/go.mod h1:d9aADumiyjCBvZLffp8wldvP9XFHxcvk2PoOSUYms2g=
github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20251204144808-73fa744851c0 h1:8S1vE1PeVtrzWkKL0N39cX6XLLNV0It+f6xjRKjw7Ug=
Expand Down
Loading
Loading