Last active
May 19, 2022 11:38
-
-
Save esdandreu/41ebc58277e5bfad3aba58c611347aea to your computer and use it in GitHub Desktop.
Pip install from github release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import requests | |
import sys | |
import os | |
# If it is a private repository you'll need to add Basic Authentication | |
# to the requests with your username and Personal Access Token | |
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token | |
# auth = requests.auth.HTTPBasicAuth('', GITHUB_TOKEN) | |
response = requests.get( | |
"https://api.github.com/repos/esdandreu/python-extension-cpp/releases/latest" | |
) | |
response.raise_for_status() | |
headers = {'Accept': 'application/octet-stream'} | |
for asset in response.json()['assets']: | |
r = requests.get(asset['url'], allow_redirects=True, headers=headers) | |
r.raise_for_status() | |
wheel_name = asset['name'] | |
with open(wheel_name, 'wb') as f: | |
f.write(r.content) | |
try: | |
result = subprocess.check_output([ | |
sys.executable, '-m', 'pip', 'install', wheel_name | |
]) | |
print(f'Installed {wheel_name}') | |
break | |
except subprocess.CalledProcessError as e: | |
pass | |
finally: | |
os.remove(wheel_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment