提交 eff56252 authored 作者: Iban Harlouchet's avatar Iban Harlouchet 提交者: Iban Harlouchet

flake8 for theano/misc/gh_api.py

上级 d40710cd
...@@ -19,31 +19,31 @@ token = None ...@@ -19,31 +19,31 @@ token = None
def get_auth_token(): def get_auth_token():
global token global token
if token is not None: if token is not None:
return token return token
import keyring import keyring
token = keyring.get_password('github', fake_username) token = keyring.get_password('github', fake_username)
if token is not None: if token is not None:
return token return token
print("Please enter your github username and password. These are not " print("Please enter your github username and password. These are not "
"stored, only used to get an oAuth token. You can revoke this at " "stored, only used to get an oAuth token. You can revoke this at "
"any time on Github.") "any time on Github.")
user = input("Username: ") user = input("Username: ")
pw = getpass.getpass("Password: ") pw = getpass.getpass("Password: ")
auth_request = { auth_request = {
"scopes": [ "scopes": [
"public_repo", "public_repo",
"gist" "gist"
], ],
"note": "IPython tools", "note": "IPython tools",
"note_url": "https://github.com/ipython/ipython/tree/master/tools", "note_url": "https://github.com/ipython/ipython/tree/master/tools",
} }
response = requests.post('https://api.github.com/authorizations', response = requests.post('https://api.github.com/authorizations',
auth=(user, pw), data=json.dumps(auth_request)) auth=(user, pw), data=json.dumps(auth_request))
response.raise_for_status() response.raise_for_status()
token = json.loads(response.text)['token'] token = json.loads(response.text)['token']
keyring.set_password('github', fake_username, token) keyring.set_password('github', fake_username, token)
...@@ -57,40 +57,40 @@ def make_auth_header(): ...@@ -57,40 +57,40 @@ def make_auth_header():
def post_issue_comment(project, num, body): def post_issue_comment(project, num, body):
url = 'https://api.github.com/repos/{project}/issues/{num}/comments'.format(project=project, num=num) url = 'https://api.github.com/repos/{project}/issues/{num}/comments'.format(project=project, num=num)
payload = json.dumps({'body': body}) payload = json.dumps({'body': body})
r = requests.post(url, data=payload, headers=make_auth_header()) r = requests.post(url, data=payload, headers=make_auth_header()) # noqa
def post_gist(content, description='', filename='file', auth=False): def post_gist(content, description='', filename='file', auth=False):
"""Post some text to a Gist, and return the URL.""" """Post some text to a Gist, and return the URL."""
post_data = json.dumps({ post_data = json.dumps({
"description": description, "description": description,
"public": True, "public": True,
"files": { "files": {
filename: { filename: {
"content": content "content": content
}
} }
}
}).encode('utf-8') }).encode('utf-8')
headers = make_auth_header() if auth else {} headers = make_auth_header() if auth else {}
response = requests.post("https://api.github.com/gists", data=post_data, headers=headers) response = requests.post("https://api.github.com/gists", data=post_data, headers=headers)
response.raise_for_status() response.raise_for_status()
response_data = json.loads(response.text) response_data = json.loads(response.text)
return response_data['html_url'] return response_data['html_url']
def get_pull_request(project, num, github_api=3): def get_pull_request(project, num, github_api=3):
"""get pull request info by number """get pull request info by number
github_api : version of github api to use github_api : version of github api to use
""" """
if github_api == 2 : if github_api == 2:
url = "http://github.com/api/v2/json/pulls/{project}/{num}".format(project=project, num=num) url = "http://github.com/api/v2/json/pulls/{project}/{num}".format(project=project, num=num)
elif github_api == 3: elif github_api == 3:
url = "https://api.github.com/repos/{project}/pulls/{num}".format(project=project, num=num) url = "https://api.github.com/repos/{project}/pulls/{num}".format(project=project, num=num)
response = requests.get(url) response = requests.get(url)
response.raise_for_status() response.raise_for_status()
if github_api == 2 : if github_api == 2:
return json.loads(response.text)['pull'] return json.loads(response.text)['pull']
return json.loads(response.text) return json.loads(response.text)
...@@ -100,12 +100,12 @@ def get_pulls_list(project, github_api=3): ...@@ -100,12 +100,12 @@ def get_pulls_list(project, github_api=3):
github_api : version of github api to use github_api : version of github api to use
""" """
if github_api == 3 : if github_api == 3:
url = "https://api.github.com/repos/{project}/pulls".format(project=project) url = "https://api.github.com/repos/{project}/pulls".format(project=project)
else : else:
url = "http://github.com/api/v2/json/pulls/{project}".format(project=project) url = "http://github.com/api/v2/json/pulls/{project}".format(project=project)
response = requests.get(url) response = requests.get(url)
response.raise_for_status() response.raise_for_status()
if github_api == 2 : if github_api == 2:
return json.loads(response.text)['pulls'] return json.loads(response.text)['pulls']
return json.loads(response.text) return json.loads(response.text)
...@@ -184,7 +184,6 @@ whitelist_flake8 = [ ...@@ -184,7 +184,6 @@ whitelist_flake8 = [
"scan_module/scan_opt.py", "scan_module/scan_opt.py",
"scan_module/tests/test_scan.py", "scan_module/tests/test_scan.py",
"scan_module/tests/test_scan_opt.py", "scan_module/tests/test_scan_opt.py",
"misc/gh_api.py",
"misc/check_blas.py", "misc/check_blas.py",
"misc/latence_gpu_transfert.py", "misc/latence_gpu_transfert.py",
"misc/cudamat_utils.py", "misc/cudamat_utils.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论