Skip to content

Commit

Permalink
support github api tokens in get_available_solc_versions
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Jul 30, 2019
1 parent e186f32 commit f61c661
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.5.0 (unreleased)
0.5.0
-----

- Support for github API tokens via environment var GITHUB_TOKEN
- Improved verbosity when get_available_solc_versions raises
- Remove interace flag (was removed from solc in 0.4.0)
- Raise on clone-bin and formal flags when using 0.5.x
Expand Down
12 changes: 11 additions & 1 deletion solcx/install.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Install solc
"""
from base64 import b64encode
from io import BytesIO
import os
from pathlib import Path
Expand Down Expand Up @@ -144,14 +145,23 @@ def install_solc_pragma(pragma_string, install=True):
def get_available_solc_versions(headers=None):
versions = []
pattern = VERSION_REGEX[_get_platform()]

# Github sometimes blocks CI from calling their API, if you are having issues try
# saving an API token to the environment variable GITHUB_TOKEN in your build environment
# https://github.blog/2013-05-16-personal-api-tokens/
if not headers and os.getenv('GITHUB_TOKEN'):
auth = b64encode(os.getenv('GITHUB_TOKEN').encode()).decode()
headers = {'Authorization': "Basic {}".format(auth)}

data = requests.get(ALL_RELEASES, headers=headers)
if data.status_code != 200:
raise ConnectionError(
"{} when getting solc versions from Github: '{}'".format(
"Status {} when getting solc versions from Github: '{}'".format(
data.status_code,
data.json()['message']
)
)

for release in data.json():
asset = next((i for i in release['assets'] if re.match(pattern, i['name'])), False)
if asset:
Expand Down
6 changes: 1 addition & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/python3

from base64 import b64encode
import os
import pytest
import sys

Expand All @@ -10,9 +8,7 @@
if sys.platform == "darwin":
VERSIONS = solcx.get_installed_solc_versions()
else:
auth = b64encode(os.environ['GITAUTH'].encode()).decode('ascii')
headers = {'Authorization': f"Basic {auth}"}
VERSIONS = solcx.get_available_solc_versions(headers=headers)
VERSIONS = solcx.get_available_solc_versions()


# auto-parametrize the all_versions fixture with all target solc versions
Expand Down

0 comments on commit f61c661

Please sign in to comment.