Skip to content

Instantly share code, notes, and snippets.

@cokeSchlumpf
Created March 23, 2023 10:42
Show Gist options
  • Save cokeSchlumpf/4380a3eb062396bc339221f2d3a0ad9c to your computer and use it in GitHub Desktop.
Save cokeSchlumpf/4380a3eb062396bc339221f2d3a0ad9c to your computer and use it in GitHub Desktop.
def install_requirements(requirements: Union[str, List[str]], space_token: Optional[str] = None) -> None:
"""
Instally Pip dependencies defined in requirements list.
Parameters
----------
:param requirements: If `str`, its interpreted as a path to `requirements.txt`, if it is a list, the list of dependencies will be added.
:param space_token: The personal accesss token to access artifacts from Space artifacts library (required if Zurich internal packages should be deployed).
"""
args = [
sys.executable,
"-m",
"pip",
"install"
]
if isinstance(requirements, str):
args = args + ["-r", requirements]
else:
for req in requirements:
args.append(req)
if space_token:
args = args + ['--extra-index-url', f'https://space:{space_token}@pkgs.dev.azure.com/zurichinsurance/_packaging/space/pypi/simple/']
subprocess.check_call(
args,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
print("Requirements installed.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment