codeartifact login should pick appropriate environment
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
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.
P67449401
@tim-finnigan this looks like an easy-enough change to make, happy to contribute if that’d help progress the issue.
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.
Hello, I'm also interested in this, so I'm bumping it
Bumping this issue for either a recommended work around or update