Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Cloudml Branch Merge From Master #222

Merged
merged 20 commits into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
320ced1
Add gcs_copy_file() that is missing but is referenced in a couple of …
qimingj Dec 9, 2016
7320b39
Flake8 configuration. Set max line length to 100. Ignore E111, E114 (…
parthea Dec 11, 2016
f77abd6
Add datalab user agent to CloudML trainer and predictor requests. (#112)
qimingj Dec 13, 2016
9124c5e
Update oauth2client to 2.2.0 to satisfy cloudml in Cloud Datalab (#111)
parthea Dec 19, 2016
7a3399b
Update README.md (#114)
yebrahim Dec 31, 2016
4c18e19
Generate reST documentation for magic commands (#113)
yebrahim Dec 31, 2016
94c7313
Fix an issue that %%chart failed with UDF query. (#116)
qimingj Jan 1, 2017
23e9e21
Fix "%%bigquery schema" issue -- the command generates nothing in ou…
qimingj Jan 4, 2017
3a6f471
Add some missing dependencies, remove some unused ones (#122)
eyadsibai Jan 12, 2017
75fb7e3
Cleanup (#123)
eyadsibai Jan 12, 2017
57dbbc5
Fix query_metadata tests (#128)
yebrahim Jan 17, 2017
c67ac4f
Make the library pip-installable (#125)
yebrahim Jan 17, 2017
2395c61
Set command description so it is displayed in --help. argparser's for…
qimingj Jan 18, 2017
31e7486
Fix an issue that setting project id from datalab does not set gcloud…
qimingj Jan 20, 2017
220d804
Add future==0.16.0 as a dependency since it's required by CloudML SDK…
yebrahim Jan 30, 2017
15abddf
Remove tensorflow and CloudML SDK from setup.py (#144)
qimingj Feb 1, 2017
62716e9
Fix project_id from `gcloud config` in py3 (#194)
jdanbrown Feb 14, 2017
7ff0b3c
Use http Keep-Alive, else BigQuery queries are ~seconds slower than n…
jdanbrown Feb 14, 2017
6a6344e
cast string to int (#217)
benrif Feb 21, 2017
6c80eb2
Merge branch 'master' into cloudml
qimingj Feb 22, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datalab/bigquery/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def insert_data(self, data, include_index=False, index_name=None):
self._info = self._api.tables_get(self._name_parts)
if 'streamingBuffer' not in self._info or \
'estimatedRows' not in self._info['streamingBuffer'] or \
self._info['streamingBuffer']['estimatedRows'] > 0:
int(self._info['streamingBuffer']['estimatedRows']) > 0:
break
time.sleep(2)

Expand Down
2 changes: 1 addition & 1 deletion datalab/context/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_project_id():
proc = subprocess.Popen(['gcloud', 'config', 'list', '--format', 'value(core.project)'],
stdout=subprocess.PIPE)
stdout, _ = proc.communicate()
value = stdout.strip()
value = stdout.decode().strip()
if proc.poll() == 0 and value:
return value
except:
Expand Down
21 changes: 12 additions & 9 deletions datalab/utils/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class Http(object):
"""A helper class for making HTTP requests.
"""

# Reuse one Http object across requests to take advantage of Keep-Alive, e.g.
# for BigQuery queries that requires at least ~5 sequential http requests.
#
# TODO(nikhilko):
# SSL cert validation seemingly fails, and workarounds are not amenable
# to implementing in library code. So configure the Http object to skip
# doing so, in the interim.
http = httplib2.Http()
http.disable_ssl_certificate_validation = True

def __init__(self):
pass

Expand Down Expand Up @@ -109,15 +119,8 @@ def request(url, args=None, data=None, headers=None, method=None,
if method is None:
method = 'GET'

# Create an Http object to issue requests. Associate the credentials
# with it if specified to perform authorization.
#
# TODO(nikhilko):
# SSL cert validation seemingly fails, and workarounds are not amenable
# to implementing in library code. So configure the Http object to skip
# doing so, in the interim.
http = httplib2.Http()
http.disable_ssl_certificate_validation = True
# Authorize with credentials if given.
http = Http.http
if credentials is not None:
http = credentials.authorize(http)
if stats is not None:
Expand Down
16 changes: 8 additions & 8 deletions tests/_util/http_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class TestCases(unittest.TestCase):

@mock.patch('httplib2.Response')
@mock.patch('httplib2.Http.request')
@mock.patch('datalab.utils._http.Http.http.request')
def test_get_request_is_invoked(self, mock_request, mock_response):
TestCases._setup_mocks(mock_request, mock_response, '{}')

Expand All @@ -32,23 +32,23 @@ def test_get_request_is_invoked(self, mock_request, mock_response):
self.assertEqual(mock_request.call_args[1]['method'], 'GET')

@mock.patch('httplib2.Response')
@mock.patch('httplib2.Http.request')
@mock.patch('datalab.utils._http.Http.http.request')
def test_post_request_is_invoked(self, mock_request, mock_response):
TestCases._setup_mocks(mock_request, mock_response, '{}')

Http.request('http://www.example.org', data={})
self.assertEqual(mock_request.call_args[1]['method'], 'POST')

@mock.patch('httplib2.Response')
@mock.patch('httplib2.Http.request')
@mock.patch('datalab.utils._http.Http.http.request')
def test_explicit_post_request_is_invoked(self, mock_request, mock_response):
TestCases._setup_mocks(mock_request, mock_response, '{}')

Http.request('http://www.example.org', method='POST')
self.assertEqual(mock_request.call_args[1]['method'], 'POST')

@mock.patch('httplib2.Response')
@mock.patch('httplib2.Http.request')
@mock.patch('datalab.utils._http.Http.http.request')
def test_query_string_format(self, mock_request, mock_response):
TestCases._setup_mocks(mock_request, mock_response, '{}')

Expand All @@ -59,7 +59,7 @@ def test_query_string_format(self, mock_request, mock_response):
self.assertTrue('b=a+b+c' in parts[1:])

@mock.patch('httplib2.Response')
@mock.patch('httplib2.Http.request')
@mock.patch('datalab.utils._http.Http.http.request')
def test_formats_json_request(self, mock_request, mock_response):
TestCases._setup_mocks(mock_request, mock_response, '{}')

Expand All @@ -71,7 +71,7 @@ def test_formats_json_request(self, mock_request, mock_response):
'application/json')

@mock.patch('httplib2.Response')
@mock.patch('httplib2.Http.request')
@mock.patch('datalab.utils._http.Http.http.request')
def test_supports_custom_content(self, mock_request, mock_response):
TestCases._setup_mocks(mock_request, mock_response, '{}')

Expand All @@ -83,15 +83,15 @@ def test_supports_custom_content(self, mock_request, mock_response):
self.assertEqual(mock_request.call_args[1]['headers']['Content-Type'], 'text/plain')

@mock.patch('httplib2.Response')
@mock.patch('httplib2.Http.request')
@mock.patch('datalab.utils._http.Http.http.request')
def test_parses_json_response(self, mock_request, mock_response):
TestCases._setup_mocks(mock_request, mock_response, '{"abc":123}')

data = Http.request('http://www.example.org')
self.assertEqual(data['abc'], 123)

@mock.patch('httplib2.Response')
@mock.patch('httplib2.Http.request')
@mock.patch('datalab.utils._http.Http.http.request')
def test_raises_http_error(self, mock_request, mock_response):
TestCases._setup_mocks(mock_request, mock_response, 'Not Found', 404)

Expand Down