aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

codeartifact login should pick appropriate environment

Open jenstroeger opened this issue 3 years ago • 7 comments

Describe the feature

Running

aws codeartifact login --tool pip ...

updates the user’s pip configuration instead of the virtual environment’s if run inside a venv which doesn’t already have a configuration. (Bug?) The pip documentation states

If none of --user, --global and --site are passed, a virtual environment configuration file is used if one is active and the file exists. Otherwise, all modifications happen to the user file by default.

Note the “if … the file exists”. Looking at the code

https://github.com/aws/aws-cli/blob/88e8fabe20b18cd83c72955c0fb547ad35ffa55b/awscli/customizations/codeartifact/login.py#L382

none of these three options are passed. That behavior is actually pretty annoying because every other venv on my machine can then inherit that artifactory which was meant for just one venv.

Proposal: Either be more careful checking for an activated virtual environment by checking for VIRTUAL_ENV or give the user an option so she can select one of the three pip options.

Use Case

See above: running aws codertifact login --tool pip ... can quickly set the user’s pip configuration and ignores an activated venv. That’s created quite a mess for me across venvs.

Proposed Solution

Replace

https://github.com/aws/aws-cli/blob/88e8fabe20b18cd83c72955c0fb547ad35ffa55b/awscli/customizations/codeartifact/login.py#L382

with something like

if "VIRTUAL_ENV" in os.environ:
    return [['pip', 'config', '--site', 'set', 'global.index-url', pip_index_url]]
return [['pip', 'config', 'set', 'global.index-url', pip_index_url]] 

or

if "VIRTUAL_ENV" in os.environ:
    pip_conf = os.path.join(os.environ["VIRTUAL_ENV"], "pip.conf")
    if not os.path.isfile(pip_conf):
        open(pip_conf, "a").close()
return [['pip', 'config', 'set', 'global.index-url', pip_index_url]] 

or some such. Alternatively, add a command-line option to aws codeartifactory login (e.g. --pip-conf) which allows the aws user to pass one of the three pip options.

Other Information

To deal with the issue, I had to run the following commands after aws:

pip config debug
pip config --site set global.index-url `pip config get global.index-url`
pip config --user unset global.index-url

In the future, running

touch "${VIRTUAL_ENV}/pip.conf"

before aws also seems to work.

Acknowledgements

  • [X] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

CLI version used

aws-cli/2.7.8 Python/3.9.13 Darwin/18.7.0 source/x86_64 prompt/off

Environment details (OS name and version, etc.)

macOS Darwin 18.7.0 Darwin Kernel Version 18.7.0, Mojave 10.14.6

jenstroeger avatar Jul 04 '22 00:07 jenstroeger

Thanks @jenstroeger for the feature request. The CodeArtifact team owns this customization so I reached out to them regarding your request. I will update this issue when I hear back.

tim-finnigan avatar Jul 06 '22 17:07 tim-finnigan

P67449401

tim-finnigan avatar Jul 06 '22 17:07 tim-finnigan

@tim-finnigan this looks like an easy-enough change to make, happy to contribute if that’d help progress the issue.

jenstroeger avatar Jul 06 '22 21:07 jenstroeger

Thanks @jenstroeger for following up. The team seemed receptive to these changes and has a related backlog item but we haven't received any updates since that. If you're willing to create a PR for this I think it would increase the changes that the feature request gets implemented but I can't guarantee that. Edit - noting a related issue: https://github.com/aws/aws-cli/issues/5409.

tim-finnigan avatar Nov 10 '22 22:11 tim-finnigan

If you're willing to create a PR for this

Which one of the suggested solutions would be preferable?

jenstroeger avatar Nov 11 '22 02:11 jenstroeger

Hello, I'm also interested in this, so I'm bumping it

petterroea avatar May 17 '23 06:05 petterroea

Bumping this issue for either a recommended work around or update

louis-duncan avatar Jan 16 '24 16:01 louis-duncan