Skip to content

Instantly share code, notes, and snippets.

@esdandreu
Last active May 19, 2022 11:38
Show Gist options
  • Save esdandreu/41ebc58277e5bfad3aba58c611347aea to your computer and use it in GitHub Desktop.
Save esdandreu/41ebc58277e5bfad3aba58c611347aea to your computer and use it in GitHub Desktop.
Pip install from github release
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