I want to a private package via
%pip install -r /dbfs/requirements.txt
Inside this requirements.txt is give:
git+https://<user>:$token@<gitprovider>.com/<path/to/repo>
If i give user and token inside the requirements.txt it works like a charm, but I want to pass user and token via dbutils.secrets. Is this doable without manipulating the requirements.txt before?
I thought it would be possible to create environment variables, but this did not work for me.
%env GIT_USERNAME= ...
%env GIT_TOKEN= ...
2
Answers
The way is using python
I believe the simplest way would be to use a
~/.netrc
file, that way you don’t pollute yourrequirements.txt
with usernames/passwords.If you’ve never used a
~/.netrc
file, thentouch ~/.netrc
first, otherwise add this line (either programmatically or manually)Now your requests should pick up the authentication without you having to manually specify it, i.e. this is what your
requirement.txt
line isNote: If this is running in a pipeline, etc. you can also use a
~/.netrc
, and clear it up when the pipeline ends or rely on whatever sort of garbage collection exists.