@@ -5,12 +5,13 @@ import (
55 "fmt"
66 "os"
77 "os/exec"
8+ "path/filepath"
89 "sort"
910 "strconv"
1011 "strings"
1112
13+ "github.com/BurntSushi/toml"
1214 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/container/strategies"
13-
1415 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
1516 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/setup"
1617 "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
@@ -1161,6 +1162,49 @@ func getCommandName(orgArgs []string) (string, []string) {
11611162 return "" , cmdArgs
11621163}
11631164
1165+ // getPrimarySourceFromToml reads pyproject.toml and returns the name of the primary source
1166+ // Returns (sourceName, isPrimary) where isPrimary indicates if source has priority='primary'
1167+ func getPrimarySourceFromToml () (string , bool ) {
1168+ type PyProjectSource struct {
1169+ Name string `toml:"name"`
1170+ URL string `toml:"url"`
1171+ Priority string `toml:"priority"`
1172+ }
1173+
1174+ type PyProject struct {
1175+ Tool struct {
1176+ Poetry struct {
1177+ Source []PyProjectSource `toml:"source"`
1178+ } `toml:"poetry"`
1179+ } `toml:"tool"`
1180+ }
1181+
1182+ tomlPath := filepath .Join ("." , "pyproject.toml" )
1183+ tomlData , err := os .ReadFile (tomlPath )
1184+ if err != nil {
1185+ return "" , false
1186+ }
1187+
1188+ var pyproject PyProject
1189+ if err := toml .Unmarshal (tomlData , & pyproject ); err != nil {
1190+ return "" , false
1191+ }
1192+
1193+ // Look for primary source
1194+ for _ , source := range pyproject .Tool .Poetry .Source {
1195+ if source .Priority == "primary" {
1196+ return source .Name , true
1197+ }
1198+ }
1199+
1200+ // If no primary, use first source
1201+ if len (pyproject .Tool .Poetry .Source ) > 0 {
1202+ return pyproject .Tool .Poetry .Source [0 ].Name , false
1203+ }
1204+
1205+ return "" , false
1206+ }
1207+
11641208func NpmInstallCmd (c * cli.Context ) error {
11651209 if show , err := cliutils .ShowGenericCmdHelpIfNeeded (c , c .Args (), "npminstallhelp" ); show || err != nil {
11661210 return err
@@ -1353,6 +1397,34 @@ func pythonCmd(c *cli.Context, projectType project.ProjectType) error {
13531397 }
13541398 cmdName , poetryArgs := getCommandName (filteredArgs )
13551399
1400+ // Extract --repository flag for artifact collection (if publishing)
1401+ deployerRepo := ""
1402+ for i , arg := range poetryArgs {
1403+ if strings .HasPrefix (arg , "--repository=" ) {
1404+ deployerRepo = strings .TrimPrefix (arg , "--repository=" )
1405+ } else if (arg == "--repository" || arg == "-r" ) && i + 1 < len (poetryArgs ) {
1406+ deployerRepo = poetryArgs [i + 1 ]
1407+ }
1408+ }
1409+
1410+ // Auto-add repository flag if not provided and we're publishing
1411+ if cmdName == "publish" && deployerRepo == "" {
1412+ // Try to get primary source from pyproject.toml (same as native Poetry behavior)
1413+ if repoName , isPrimary := getPrimarySourceFromToml (); repoName != "" {
1414+ if isPrimary {
1415+ log .Info (fmt .Sprintf ("No --repository flag specified. Using '%s' from pyproject.toml (priority='primary')" , repoName ))
1416+ } else {
1417+ log .Info (fmt .Sprintf ("No --repository flag specified. Using '%s' from pyproject.toml (first source)" , repoName ))
1418+ }
1419+ poetryArgs = append ([]string {"-r" , repoName }, poetryArgs ... )
1420+ deployerRepo = repoName
1421+ } else {
1422+ log .Warn ("No repository specified and no sources found in pyproject.toml. Poetry will attempt to publish to PyPI." )
1423+ }
1424+ } else if cmdName == "publish" && deployerRepo != "" {
1425+ log .Info (fmt .Sprintf ("Publishing to repository: %s (from --repository flag)" , deployerRepo ))
1426+ }
1427+
13561428 // Execute native poetry command directly (similar to Maven FlexPack)
13571429 log .Info (fmt .Sprintf ("Running Poetry %s." , cmdName ))
13581430 poetryCmd := exec .Command ("poetry" , append ([]string {cmdName }, poetryArgs ... )... )
@@ -1369,7 +1441,7 @@ func pythonCmd(c *cli.Context, projectType project.ProjectType) error {
13691441 workingDir , err := os .Getwd ()
13701442 if err != nil {
13711443 log .Warn ("Failed to get working directory, skipping build info collection: " + err .Error ())
1372- } else if err := buildinfo .GetPoetryBuildInfo (workingDir , buildConfiguration ); err != nil {
1444+ } else if err := buildinfo .GetPoetryBuildInfo (workingDir , buildConfiguration , deployerRepo ); err != nil {
13731445 log .Warn ("Failed to collect Poetry build info: " + err .Error ())
13741446 } else {
13751447 buildNumber , err := buildConfiguration .GetBuildNumber ()
0 commit comments