aws / aws/aws-cli

codeartifact login should pick appropriate environment

Open
#7,085 9 comments 8 reactions 0 assignees View on GitHub
codeartifact login customization feature-request p2
Dominant language
Python
Stars
17.3k
Forks
4.6k
Avg merge
1d 2h
Merged PRs (30d)
13

Description

### Describe the feature

Running
```bash
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](https://pip.pypa.io/en/latest/cli/pip_config/) 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`](https://docs.python.org/3/library/venv.html) 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
```python
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
```python
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`:
```bash
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
```bash
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.