Skip to content

Commit

Permalink
Merge pull request #2020 from davidmarin/gcs-upgrade
Browse files Browse the repository at this point in the history
upgrade google-cloud-services to 1.11.0, remove shim (fixes #2019)
  • Loading branch information
David Marin committed Mar 15, 2019
2 parents 0b871c1 + ae7d9a0 commit bcaa0f4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
1 change: 0 additions & 1 deletion mrjob/dataproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ def fs(self):

self._fs.add_fs('gcs', GCSFilesystem(
credentials=self._credentials,
local_tmp_dir=self._get_local_tmp_dir(),
project_id=self._project_id,
))

Expand Down
7 changes: 1 addition & 6 deletions mrjob/fs/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,7 @@ def create_bucket(self, name,
and time-to-live."""
bucket = self.client.bucket(name)

# as of google-cloud 0.32.0, there isn't a direct way to set location
if location:
bucket._changes.add('location')
bucket._properties['location'] = location

bucket.create()
bucket.create(location=location)

bucket.lifecycle_rules = [
dict(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'PyYAML>=3.08',
'google-cloud-dataproc>=0.2.0',
'google-cloud-logging>=1.5.0',
'google-cloud-storage>=1.9.0',
'google-cloud-storage>=1.11.0',
],
'provides': ['mrjob'],
'test_suite': 'tests',
Expand Down
4 changes: 2 additions & 2 deletions tests/mock_google/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def setUp(self):
# mock project ID, returned by mock google.auth.default()
self.mock_project_id = 'mock-project-12345'

# Maps bucket name to a dictionary with the key
# *blobs*. *blobs* maps object name to
# Maps bucket name to a dictionary with the keys
# *blobs* and *location*. *blobs* maps object name to
# a dictionary with the key *data*, which is
# a bytestring.
self.mock_gcs_fs = {}
Expand Down
19 changes: 10 additions & 9 deletions tests/mock_google/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ def blob(self, blob_name, chunk_size=None):
# always returns something whether it exists or not
return MockGoogleStorageBlob(blob_name, self, chunk_size=chunk_size)

def create(self):
def create(self, location=None):
if self.exists():
raise Conflict(
'POST https://www.googleapis.com/storage/v1'
'/b?project=%s: Sorry, that name is not available.'
' Please try a different one.')

if 'location' in self._changes and 'location' in self._properties:
location = self._properties['location'].upper()
if location:
location = location.upper()
else:
location = 'US'
location = 'US' # default bucket location

self.client.mock_gcs_fs[self.name] = dict(
blobs={}, lifecycle_rules=[], location=location)
Expand All @@ -92,10 +92,11 @@ def lifecycle_rules(self):
fs = self.client.mock_gcs_fs

if self.name in fs:
return deepcopy(fs[self.name]['lifecycle_rules'])
else:
# google-cloud-sdk silently ignores missing buckets
return []
# as of google-cloud-storage 1.11.0, this is a generator
for rule in fs[self.name]['lifecycle_rules']:
yield deepcopy(rule)

# if bucket doesn't exist, yield nothing

@lifecycle_rules.setter
def lifecycle_rules(self, rules):
Expand Down Expand Up @@ -126,7 +127,7 @@ def location(self):
return fs[self.name]['location']
else:
# google-cloud-sdk silently ignores missing buckets
return []
return None


class MockGoogleStorageBlob(object):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dataproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def assert_new_tmp_bucket(self, location, **runner_kwargs):
self.assertEqual(current_bucket.location, location.upper())

# Verify that we setup bucket lifecycle rules of 28-day retention
first_lifecycle_rule = current_bucket.lifecycle_rules[0]
first_lifecycle_rule = list(current_bucket.lifecycle_rules)[0]
self.assertEqual(first_lifecycle_rule['action'], dict(type='Delete'))
self.assertEqual(first_lifecycle_rule['condition'],
dict(age=_DEFAULT_CLOUD_TMP_DIR_OBJECT_TTL_DAYS))
Expand Down

0 comments on commit bcaa0f4

Please sign in to comment.