Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: Add Blob.from_string and Bucket.from_string. #8424

Conversation

HemangChothani
Copy link
Contributor

Fixes #7693

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 19, 2019
@@ -821,3 +821,49 @@ def dummy_response():
self.assertEqual(page.remaining, 0)
self.assertIsInstance(bucket, Bucket)
self.assertEqual(bucket.name, blob_name)

def test_get_bucket_from_uri(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this testcase test_get_bucket_from_uri_w_valid_uri.

self.assertIs(bucket.client, client)
self.assertEqual(bucket.name, BUCKET_NAME)

def test_get_blob_from_uri(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this testcase test_get_blob_from_uri_w_valid_uri.

self.assertIs(blob.client, client)
self.assertEqual(blob.name, "/b/")

def test_get_bucket_with_invalid_uri(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this testcase test_get_bucket_from_uri_w_invalid_uri and move it above the test_get_object_w_valid_uri.

with pytest.raises(ValueError, match="URI scheme must be gs"):
client.get_bucket_from_uri("http://bucket_name")

def test_get_blob_with_invalid_uri(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this testcase test_get_blob_from_uri_w_invalid_uri.

@@ -477,6 +477,37 @@ def list_buckets(
extra_params=extra_params,
)

def get_blob_from_uri(self, uri):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this method below get_bucket_from_uri.

"""Get a constructor for blob object by URI.

:type uri: str
:param uri: The blob uri pass to get blob object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an example of the expected form of the uri, e.g.:

        """Construct a blob object from a URI.

         :type uri: str
         :param uri:
             The blob's URI, in the form
             "gs://<bucket-name>/<blob-name>".
        ...
        """

"""Get a constructor for bucket object by URI.

:type uri: str
:param uri: The bucket uri pass to get bucket object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an example of the expected form of the uri, e.g.:

        """Construct a bucket from a URI.

         :type uri: str
         :param uri:
             The bucket's URI, in the form
             "gs://<bucket-name>".
        ...
        """

raise ValueError("URI scheme must be gs")

bucket = Bucket(self, name=netloc)
return Blob(path[1:], bucket)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankyn, @tswast Given that the names for these methods start with get_, should we be making the API calls to load the objects?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. get_ implies actually making a GET request. This should call .reload().

@tseaver tseaver added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 19, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 19, 2019
@sduskis sduskis added the api: storage Issues related to the Cloud Storage API. label Jun 19, 2019
@tseaver tseaver changed the title Storage: Add methods to parse URI for blob and bucket Storage: Add 'Client.get_bucket_from_uri' and 'Client.get_blob_from_uri'. Jun 19, 2019
@tswast
Copy link
Contributor

tswast commented Jun 19, 2019

Note: this doesn't actually fix #7693 yet. I'd prefer you refactor this to have a Blob.from_string(uri, client=None) method and similar for Bucket. The get_ methods do make sense, though, assuming they actually make a GET request.

@tseaver
Copy link
Contributor

tseaver commented Jun 19, 2019

@tswast What is your expected usecase for having client default to None in a Blob.from_string / Bucket.from_string call? The objects themselves aren't very useful without a client.

@tswast
Copy link
Contributor

tswast commented Jun 20, 2019

What is your expected usecase for having client default to None in a Blob.from_string / Bucket.from_string call? The objects themselves aren't very useful without a client.

Per https://github.com/googleapis/google-cloud-python/issues/7762, the goal is to have Blob and Bucket usable without a client in more places, as methods like client.create_bucket should be able to take a Bucket object without a client object present. (I acknowledge that this isn't the case yet.)

@tseaver tseaver added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 20, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 20, 2019
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Jun 26, 2019
@yoshi-automation yoshi-automation removed the 🚨 This issue needs some love. label Jul 3, 2019
plamut and others added 4 commits July 17, 2019 10:08
"skipif" should be used instead of "skipIf", the latter is the thing
from the unittest nodule.
Update Makefile test proto builder:

- Use new 'conformance_tests' repo.
- Handle updated file hierarchy, etc.

Use new JSON format in 'test_cross_language.py'.

- Copy in JSON testcase files from 'conformance-tests' repo.
@AVaksman AVaksman added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 18, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 18, 2019
@tseaver
Copy link
Contributor

tseaver commented Aug 28, 2019

@HemangChothani please rebase your branch against the current master to pick up the unit test fixes merged yesterday in #9119. Also, can you please check your git configuration to ensure that the e-mail address used in the commits matches your CLA (one commit, 30617c2, has '[email protected]' as the e-mail address).

tritone and others added 11 commits August 28, 2019 09:59
…rame`. (googleapis#9084)

* Specify the index data type in partial schema to `load_table_from_dataframe` to include it.

If an index (or level of a multi-index) has a name and is present in the
schema passed to `load_table_from_dataframe`, then that index will be
serialized and written to the table. Otherwise, the index is omitted
from the serialized table.

* Don't include index if has same name as column name.

* Move `load_table_dataframe` sample from `snippets.py` to `samples/`.

Sample now demonstrates how to manually include the index with a
partial schema definition. Update docs reference to new
`load_table_dataframe` sample location.
* Make all system tests table columns NULL-able

Autodetected schema assumes NULLABLE fields, thus use NULLABLE columns
in test fixture.

* Replace helper function with BQ client method

The _add_rows() helper function is no longer needed, since
client.load_table_from_json() essentially does the same.

* Use explicit schema in data types decoding test

* Adjust a comment related to partial schemas
@HemangChothani HemangChothani force-pushed the feature/add_methods_fromuri_for_blob_bucket branch from 4b73404 to 58f2329 Compare August 29, 2019 05:54
@HemangChothani HemangChothani requested a review from a team August 29, 2019 05:54
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@HemangChothani HemangChothani force-pushed the feature/add_methods_fromuri_for_blob_bucket branch from 58f2329 to 38a2c93 Compare August 29, 2019 06:01
@HemangChothani
Copy link
Contributor Author

Closing this PR due to something irrelevant happens and unable to fix it, So replacing this PR with new PR 9143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. cla: no This human has *not* signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Storage: Add method(s) to parse gs://bucket_name and gs://bucket_name/path/to/blob URIs