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

fix: add mains to samples #3284

Merged
merged 20 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
18 changes: 17 additions & 1 deletion dataproc/create_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

# This sample walks a user through creating a Cloud Dataproc cluster using
# the Python client library.
#
# This script can be run on its own:
# python create_cluster.py ${PROJECT_ID} ${REGION} ${CLUSTER_NAME}


import sys

# [START dataproc_create_cluster]
from google.cloud import dataproc_v1 as dataproc
Expand All @@ -33,7 +39,7 @@ def create_cluster(project_id, region, cluster_name):

# Create a client with the endpoint set to the desired cluster region.
cluster_client = dataproc.ClusterControllerClient(client_options={
'api_endpoint': '{}-dataproc.googleapis.com:443'.format(region)
'api_endpoint': '{}-dataproc.googleapis.com:443'.format(region),
bradmiro marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit should we be using f-strings instead of .format to be more modern?

})

# Create the cluster config.
Expand All @@ -59,3 +65,13 @@ def create_cluster(project_id, region, cluster_name):
# Output a success message.
print('Cluster created successfully: {}'.format(result.cluster_name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

another potential f-string spot

# [END dataproc_create_cluster]


if __name__ == "__main__":
if len(sys.argv) < 4:
sys.exit('python create_cluster.py project_id region cluster_name')

project_id = sys.argv[1]
region = sys.argv[2]
cluster_name = sys.argv[3]
create_cluster(project_id, region, cluster_name)
bradmiro marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 11 additions & 3 deletions dataproc/instantiate_inline_workflow_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
# workflow for Cloud Dataproc using the Python client library.
#
# This script can be run on its own:
# python workflows.py ${PROJECT_ID} ${REGION}
# python instantiate_inline_workflow_template.py ${PROJECT_ID} ${REGION}


import sys

# [START dataproc_instantiate_inline_workflow_template]
from google.cloud import dataproc_v1 as dataproc

Expand Down Expand Up @@ -91,8 +93,14 @@ def instantiate_inline_workflow_template(project_id, region):

# Output a success message.
print('Workflow ran successfully.')
# [END dataproc_instantiate_inline_workflow_template]
# [END dataproc_instantiate_inline_workflow_template]


if __name__ == "__main__":
instantiate_inline_workflow_template(sys.argv[1], sys.argv[2])
if len(sys.argv) < 3:
sys.exit('python instantiate_inline_workflow_template.py '
+ 'project_id region')

project_id = sys.argv[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

region = sys.argv[2]
instantiate_inline_workflow_template(project_id, region)
15 changes: 5 additions & 10 deletions dataproc/quickstart/quickstart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import os
import uuid
import pytest
import subprocess

from google.cloud import dataproc_v1 as dataproc
from google.cloud import storage

import quickstart


PROJECT_ID = os.environ['GCLOUD_PROJECT']
REGION = 'us-central1'
Expand Down Expand Up @@ -60,15 +61,9 @@ def setup_teardown():
bucket.delete()


def test_quickstart():
command = [
'python', 'quickstart/quickstart.py',
'--project_id', PROJECT_ID,
'--region', REGION,
'--cluster_name', CLUSTER_NAME,
'--job_file_path', JOB_FILE_PATH
]
out = subprocess.check_output(command).decode("utf-8")
def test_quickstart(capsys):
quickstart.quickstart(PROJECT_ID, REGION, CLUSTER_NAME, JOB_FILE_PATH)
out, _ = capsys.readouterr()

assert 'Cluster created successfully' in out
assert 'Submitted job' in out
Expand Down