我有一个带有
install
命令,用于从专用Pypi存储库安装Python包。
install:
python3 -m pip install --extra-index-url https://${USERNAME}:${PASSWORD}@company.com/artifactory/api/pypi/simple -r requirements.txt
目前,我的证件都是硬编码的,这很有效。但我不能像那样将代码签入版本控制。但是,我不想每次运行这个命令时都输入用户名和密码。最好是让Makefile从我的环境变量中读取这些值。这可能吗?
我尝试过不同的用户名设置,比如
export USERNAME=`id -u -n`
然后读取密码,比如:
PASSWORD ?= $(shell stty -echo; read -p "Password: " pwd; stty echo; echo $$pwd)
但我不能让它工作。
编辑
它以什么方式不起作用?
比如我
$ source .env
$ echo $USERNAME
biogeek # OK, as expected
$ make install
Looking in indexes: https://pypi.org/simple, https://:****@company.com/artifactory/api/pypi/simple, https://%24%7USER%7D:****@company.com/artifactory/api/pypi/simple,
Collecting git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI (from -r docker/environments/tf2/requirements.txt (line 3))
Cloning https://github.com/philferriere/cocoapi.git to /tmp/pip-req-build-bngt4yfh
User for company.com:
注意
${USER}
被替换为
%24%7USER%7D
而不是我的用户名。(可能与
this issue
)。它也无法登录pypi,因此它会显示我想要避免的密码提示。