@@ -59,6 +59,11 @@ class Recipe(metaclass=RecipeMeta):
5959 if you want.
6060 '''
6161
62+ _github_access_token = None
63+ '''Used to access a private git repository. Specify the github-supplied
64+ access token in order to download the private repository files.
65+ '''
66+
6267 _version = None
6368 '''A string giving the version of the software the recipe describes,
6469 e.g. ``2.0.3`` or ``master``.'''
@@ -170,6 +175,11 @@ def versioned_url(self):
170175 return None
171176 return self .url .format (version = self .version )
172177
178+ @property
179+ def github_access_token (self ):
180+ key = "GITHUB_ACCESS_TOKEN_" + self .name
181+ return environ .get (key , self ._github_access_token )
182+
173183 def download_file (self , url , target , cwd = None ):
174184 """
175185 (internal) Download an ``url`` to a ``target``.
@@ -205,6 +215,9 @@ def report_hook(index, blksize, size):
205215 # jqueryui.com returns a 403 w/ the default user agent
206216 # Mozilla/5.0 doesnt handle redirection for liblzma
207217 url_opener .addheaders = [('User-agent' , 'Wget/1.0' )]
218+ if self .github_access_token :
219+ url_opener .addheaders += [('Authorization' , f'token { self .github_access_token } ' ),
220+ ('Accept' , 'application/vnd.github.v3.raw' )]
208221 urlretrieve (url , target , report_hook )
209222 except OSError as e :
210223 attempts += 1
0 commit comments