Skip to content

Commit

Permalink
Improve upload archive progress bar
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Jan 6, 2025
1 parent 2733b60 commit 3a8cfe5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
21 changes: 6 additions & 15 deletions artifactory/commands/python/pip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package python

import (
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/common/project"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -50,21 +49,13 @@ func (pc *PipCommand) SetCommandName(commandName string) *PipCommand {
return pc
}

// Configure the repository URL for pipenv to use Artifactory as a repository.
func RunPipConfig(repoWithCredsUrl string) error {
// If PIP_CONFIG_FILE is set, write the configuration to the custom config file manually.
// Using 'pip config set' native command is not supported together with PIP_CONFIG_FILE.
if customPipConfigPath := os.Getenv("PIP_CONFIG_FILE"); customPipConfigPath != "" {
if err := os.MkdirAll(filepath.Dir(customPipConfigPath), os.ModePerm); err != nil {
return err
}
// Write the configuration to pip.conf.
configContent := fmt.Sprintf("[global]\nindex-url = %s\n", repoWithCredsUrl)
return os.WriteFile(customPipConfigPath, []byte(configContent), 0644)
func CreatePipConfigManually(customPipConfigPath, repoWithCredsUrl string) error {
if err := os.MkdirAll(filepath.Dir(customPipConfigPath), os.ModePerm); err != nil {
return err
}

// If PIP_CONFIG_FILE is not set, use 'pip config set' native command.
return runConfigCommand(project.Pip, []string{"set", "global.index-url", repoWithCredsUrl})
// Write the configuration to pip.conf.
configContent := fmt.Sprintf("[global]\nindex-url = %s\n", repoWithCredsUrl)
return os.WriteFile(customPipConfigPath, []byte(configContent), 0644)
}

func (pc *PipCommand) CommandName() string {
Expand Down
26 changes: 26 additions & 0 deletions artifactory/commands/python/pip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package python

import (
"github.com/stretchr/testify/assert"
"os"
"path/filepath"
"testing"
)

func TestCreatePipConfigManually(t *testing.T) {
// Define the test parameters
customConfigPath := filepath.Join(t.TempDir(), "/tmp/test/pip.conf")
repoWithCredsUrl := "https://example.com/simple/"
expectedContent := "[global]\nindex-url = https://example.com/simple/\n"

// Call the function under test
err := CreatePipConfigManually(customConfigPath, repoWithCredsUrl)

// Assert no error occurred
assert.NoError(t, err)

// Verify the file exists and has the correct content
fileContent, err := os.ReadFile(customConfigPath)
assert.NoError(t, err)
assert.Equal(t, expectedContent, string(fileContent))
}
4 changes: 2 additions & 2 deletions artifactory/commands/python/poetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ func ConfigPoetryRepo(url, username, password, configRepoName string) error {
func RunPoetryConfig(url, username, password, configRepoName string) error {
// Add the poetry repository config
// poetry config repositories.<repo-name> https://<your-artifactory-url>/artifactory/api/pypi/<repo-name>/simple
err := runConfigCommand(project.Poetry, []string{poetryConfigRepoPrefix + configRepoName, url})
err := RunConfigCommand(project.Poetry, []string{poetryConfigRepoPrefix + configRepoName, url})
if err != nil {
return err
}

// Set the poetry repository credentials
// poetry config http-basic.<repo-name> <user> <password/token>
return runConfigCommand(project.Poetry, []string{poetryConfigAuthPrefix + configRepoName, username, password})
return RunConfigCommand(project.Poetry, []string{poetryConfigAuthPrefix + configRepoName, username, password})
}

func poetryUpdate() (err error) {
Expand Down
2 changes: 1 addition & 1 deletion artifactory/commands/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func GetPypiRepoUrl(serverDetails *config.ServerDetails, repository string, isCu
return rtUrl.String(), err
}

func runConfigCommand(buildTool project.ProjectType, args []string) error {
func RunConfigCommand(buildTool project.ProjectType, args []string) error {
log.Debug("Running", buildTool.String(), "config command...")
configCmd := gofrogcmd.NewCommand(buildTool.String(), "config", args)
if err := gofrogcmd.RunCmd(configCmd); err != nil {
Expand Down
8 changes: 7 additions & 1 deletion artifactory/commands/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/jfrog/jfrog-client-go/utils/log"
"golang.org/x/exp/maps"
"net/url"
"os"
"slices"
)

Expand Down Expand Up @@ -181,7 +182,12 @@ func (sc *SetupCommand) configurePip() error {
if err != nil {
return err
}
return pythoncommands.RunPipConfig(repoWithCredsUrl)
// If PIP_CONFIG_FILE is set, write the configuration to the custom config file manually.
// Using 'pip config set' native command is not supported together with PIP_CONFIG_FILE.
if customPipConfigPath := os.Getenv("PIP_CONFIG_FILE"); customPipConfigPath != "" {
return pythoncommands.CreatePipConfigManually(customPipConfigPath, repoWithCredsUrl)
}
return pythoncommands.RunConfigCommand(project.Pip, []string{"set", "global.index-url", repoWithCredsUrl})
}

// configurePoetry configures Poetry to use the specified repository and authentication credentials.
Expand Down

0 comments on commit 3a8cfe5

Please sign in to comment.