Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 7fc378f

Browse files
plamutshollyman
authored andcommitted
chore: update templates
1 parent 3d23c70 commit 7fc378f

21 files changed

Lines changed: 376 additions & 104 deletions

.github/CODEOWNERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Code owners file.
2+
# This file controls who is tagged for review for any given pull request.
3+
#
4+
# For syntax help see:
5+
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax
6+
7+
8+
/samples/ @shollyman @googleapis/python-samples-owners
9+

samples/AUTHORING_GUIDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md

samples/CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md

samples/snippets/README.rst

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
.. This file is automatically generated. Do not edit this file directly.
23
34
Google BigQuery Python Samples
@@ -15,14 +16,11 @@ This directory contains samples for Google BigQuery. `Google BigQuery`_ is Googl
1516
.. _Google BigQuery: https://cloud.google.com/bigquery/docs
1617

1718

18-
To run the sample, you need to have `BigQuery Admin` role.
19-
20-
21-
2219
Setup
2320
-------------------------------------------------------------------------------
2421

2522

23+
2624
Authentication
2725
++++++++++++++
2826

@@ -33,6 +31,9 @@ credentials for applications.
3331
.. _Authentication Getting Started Guide:
3432
https://cloud.google.com/docs/authentication/getting-started
3533

34+
35+
36+
3637
Install Dependencies
3738
++++++++++++++++++++
3839

@@ -47,7 +48,7 @@ Install Dependencies
4748
.. _Python Development Environment Setup Guide:
4849
https://cloud.google.com/python/setup
4950

50-
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
51+
#. Create a virtualenv. Samples are compatible with Python 3.6+.
5152

5253
.. code-block:: bash
5354
@@ -63,9 +64,15 @@ Install Dependencies
6364
.. _pip: https://pip.pypa.io/
6465
.. _virtualenv: https://virtualenv.pypa.io/
6566

67+
68+
69+
70+
71+
6672
Samples
6773
-------------------------------------------------------------------------------
6874

75+
6976
Quickstart
7077
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7178

@@ -82,6 +89,8 @@ To run this sample:
8289
$ python quickstart.py
8390
8491
92+
93+
8594
Simple Application
8695
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8796

@@ -98,6 +107,8 @@ To run this sample:
98107
$ python simple_app.py
99108
100109
110+
111+
101112
User Credentials
102113
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
103114

@@ -113,6 +124,7 @@ To run this sample:
113124
114125
$ python user_credentials.py
115126
127+
116128
usage: user_credentials.py [-h] [--launch-browser] project
117129
118130
Command-line application to run a query using user credentials.
@@ -131,6 +143,10 @@ To run this sample:
131143
132144
133145
146+
147+
148+
149+
134150
The client library
135151
-------------------------------------------------------------------------------
136152

@@ -146,4 +162,5 @@ to `browse the source`_ and `report issues`_.
146162
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
147163

148164

149-
.. _Google Cloud SDK: https://cloud.google.com/sdk/
165+
166+
.. _Google Cloud SDK: https://cloud.google.com/sdk/

samples/snippets/authenticate_service_account.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ def main():
2727
# key_path = "path/to/service_account.json"
2828

2929
credentials = service_account.Credentials.from_service_account_file(
30-
key_path,
31-
scopes=["https://www.googleapis.com/auth/cloud-platform"],
30+
key_path, scopes=["https://www.googleapis.com/auth/cloud-platform"],
3231
)
3332

34-
client = bigquery.Client(
35-
credentials=credentials,
36-
project=credentials.project_id,
37-
)
33+
client = bigquery.Client(credentials=credentials, project=credentials.project_id,)
3834
# [END bigquery_client_json_credentials]
3935
return client
4036

samples/snippets/authenticate_service_account_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def mock_credentials(*args, **kwargs):
2626

2727
def test_main(monkeypatch):
2828
monkeypatch.setattr(
29-
'google.oauth2.service_account.Credentials.from_service_account_file',
29+
"google.oauth2.service_account.Credentials.from_service_account_file",
3030
mock_credentials,
3131
)
3232
client = authenticate_service_account.main()

samples/snippets/authorized_view_tutorial.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
def run_authorized_view_tutorial(override_values={}):
1919
# Note to user: This is a group email for testing purposes. Replace with
2020
# your own group email address when running this code.
21-
analyst_group_email = 'example-analyst-group@google.com'
21+
analyst_group_email = "example-analyst-group@google.com"
2222

2323
# [START bigquery_authorized_view_tutorial]
2424
# Create a source dataset
2525
# [START bigquery_avt_create_source_dataset]
2626
from google.cloud import bigquery
2727

2828
client = bigquery.Client()
29-
source_dataset_id = 'github_source_data'
29+
source_dataset_id = "github_source_data"
3030

3131
# [END bigquery_authorized_view_tutorial]
3232
# [END bigquery_avt_create_source_dataset]
@@ -38,13 +38,13 @@ def run_authorized_view_tutorial(override_values={}):
3838

3939
source_dataset = bigquery.Dataset(client.dataset(source_dataset_id))
4040
# Specify the geographic location where the dataset should reside.
41-
source_dataset.location = 'US'
41+
source_dataset.location = "US"
4242
source_dataset = client.create_dataset(source_dataset) # API request
4343
# [END bigquery_avt_create_source_dataset]
4444

4545
# Populate a source table
4646
# [START bigquery_avt_create_source_table]
47-
source_table_id = 'github_contributors'
47+
source_table_id = "github_contributors"
4848
job_config = bigquery.QueryJobConfig()
4949
job_config.destination = source_dataset.table(source_table_id)
5050
sql = """
@@ -56,15 +56,16 @@ def run_authorized_view_tutorial(override_values={}):
5656
sql,
5757
# Location must match that of the dataset(s) referenced in the query
5858
# and of the destination table.
59-
location='US',
60-
job_config=job_config) # API request - starts the query
59+
location="US",
60+
job_config=job_config,
61+
) # API request - starts the query
6162

6263
query_job.result() # Waits for the query to finish
6364
# [END bigquery_avt_create_source_table]
6465

6566
# Create a separate dataset to store your view
6667
# [START bigquery_avt_create_shared_dataset]
67-
shared_dataset_id = 'shared_views'
68+
shared_dataset_id = "shared_views"
6869

6970
# [END bigquery_authorized_view_tutorial]
7071
# [END bigquery_avt_create_shared_dataset]
@@ -75,13 +76,13 @@ def run_authorized_view_tutorial(override_values={}):
7576
# [START bigquery_avt_create_shared_dataset]
7677

7778
shared_dataset = bigquery.Dataset(client.dataset(shared_dataset_id))
78-
shared_dataset.location = 'US'
79+
shared_dataset.location = "US"
7980
shared_dataset = client.create_dataset(shared_dataset) # API request
8081
# [END bigquery_avt_create_shared_dataset]
8182

8283
# Create the view in the new dataset
8384
# [START bigquery_avt_create_view]
84-
shared_view_id = 'github_analyst_view'
85+
shared_view_id = "github_analyst_view"
8586
view = bigquery.Table(shared_dataset.table(shared_view_id))
8687
sql_template = """
8788
SELECT
@@ -91,7 +92,8 @@ def run_authorized_view_tutorial(override_values={}):
9192
`{}.{}.{}`
9293
"""
9394
view.view_query = sql_template.format(
94-
client.project, source_dataset_id, source_table_id)
95+
client.project, source_dataset_id, source_table_id
96+
)
9597
view = client.create_table(view) # API request
9698
# [END bigquery_avt_create_view]
9799

@@ -100,25 +102,27 @@ def run_authorized_view_tutorial(override_values={}):
100102
# analyst_group_email = 'data_analysts@example.com'
101103
access_entries = shared_dataset.access_entries
102104
access_entries.append(
103-
bigquery.AccessEntry('READER', 'groupByEmail', analyst_group_email)
105+
bigquery.AccessEntry("READER", "groupByEmail", analyst_group_email)
104106
)
105107
shared_dataset.access_entries = access_entries
106108
shared_dataset = client.update_dataset(
107-
shared_dataset, ['access_entries']) # API request
109+
shared_dataset, ["access_entries"]
110+
) # API request
108111
# [END bigquery_avt_shared_dataset_access]
109112

110113
# Authorize the view to access the source dataset
111114
# [START bigquery_avt_source_dataset_access]
112115
access_entries = source_dataset.access_entries
113116
access_entries.append(
114-
bigquery.AccessEntry(None, 'view', view.reference.to_api_repr())
117+
bigquery.AccessEntry(None, "view", view.reference.to_api_repr())
115118
)
116119
source_dataset.access_entries = access_entries
117120
source_dataset = client.update_dataset(
118-
source_dataset, ['access_entries']) # API request
121+
source_dataset, ["access_entries"]
122+
) # API request
119123
# [END bigquery_avt_source_dataset_access]
120124
# [END bigquery_authorized_view_tutorial]
121125

122126

123-
if __name__ == '__main__':
127+
if __name__ == "__main__":
124128
run_authorized_view_tutorial()

samples/snippets/authorized_view_tutorial_test.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import authorized_view_tutorial
2121

2222

23-
@pytest.fixture(scope='module')
23+
@pytest.fixture(scope="module")
2424
def client():
2525
return bigquery.Client()
2626

@@ -35,30 +35,39 @@ def datasets_to_delete(client):
3535

3636
def test_authorized_view_tutorial(client, datasets_to_delete):
3737
override_values = {
38-
"source_dataset_id": "github_source_data_{}".format(str(uuid.uuid4()).replace("-", "_")),
39-
"shared_dataset_id": "shared_views_{}".format(str(uuid.uuid4()).replace("-", "_")),
38+
"source_dataset_id": "github_source_data_{}".format(
39+
str(uuid.uuid4()).replace("-", "_")
40+
),
41+
"shared_dataset_id": "shared_views_{}".format(
42+
str(uuid.uuid4()).replace("-", "_")
43+
),
4044
}
4145
source_dataset_ref = client.dataset(override_values["source_dataset_id"])
4246
shared_dataset_ref = client.dataset(override_values["shared_dataset_id"])
43-
datasets_to_delete.extend([override_values["source_dataset_id"],
44-
override_values["shared_dataset_id"]])
47+
datasets_to_delete.extend(
48+
[override_values["source_dataset_id"], override_values["shared_dataset_id"]]
49+
)
4550

4651
authorized_view_tutorial.run_authorized_view_tutorial(override_values)
4752

4853
source_dataset = client.get_dataset(source_dataset_ref)
4954
shared_dataset = client.get_dataset(shared_dataset_ref)
50-
analyst_email = 'example-analyst-group@google.com'
51-
analyst_entries = [entry for entry in shared_dataset.access_entries
52-
if entry.entity_id == analyst_email]
55+
analyst_email = "example-analyst-group@google.com"
56+
analyst_entries = [
57+
entry
58+
for entry in shared_dataset.access_entries
59+
if entry.entity_id == analyst_email
60+
]
5361
assert len(analyst_entries) == 1
54-
assert analyst_entries[0].role == 'READER'
62+
assert analyst_entries[0].role == "READER"
5563

56-
authorized_view_entries = [entry for entry in source_dataset.access_entries
57-
if entry.entity_type == 'view']
64+
authorized_view_entries = [
65+
entry for entry in source_dataset.access_entries if entry.entity_type == "view"
66+
]
5867
expected_view_ref = {
59-
'projectId': client.project,
60-
'datasetId': override_values["shared_dataset_id"],
61-
'tableId': 'github_analyst_view',
68+
"projectId": client.project,
69+
"datasetId": override_values["shared_dataset_id"],
70+
"tableId": "github_analyst_view",
6271
}
6372
assert len(authorized_view_entries) == 1
6473
assert authorized_view_entries[0].entity_id == expected_view_ref

0 commit comments

Comments
 (0)