Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Check in Cloud Job Discovery client code samples for python #1546

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

Merged
merged 17 commits into from
Jul 17, 2018

Conversation

xinyunh0929
Copy link
Contributor

CJD got Public beta launch so we would like to have our samples checked in as other projects.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 29, 2018
@xinyunh0929
Copy link
Contributor Author

Still working on the samples. But I would like to know how to run local tests for my samples.
I saw there are "_test" files under other project, but it seems I could not run it directly.

@xinyunh0929
Copy link
Contributor Author

I am working on the tests to those samples, however, I don't know how to run those '_test' files. Is there any guide?

@michaelawyu michaelawyu self-requested a review July 16, 2018 21:16
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Jul 16, 2018
from googleapiclient.discovery import build

client_service = build('jobs', 'v2')

Copy link
Contributor

@michaelawyu michaelawyu Jul 16, 2018

Choose a reason for hiding this comment

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

You can remove these empty lines between code and region tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use pyformat -i -s 4 --recursive . to format my code. And it seems this is recommended.
Should I manually modify those files? Or it should be fine?


import time

# [START instantiate]
Copy link
Contributor

Choose a reason for hiding this comment

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

For the region tag it might be better if you add the product name (job, maybe) as a prefix, i.e. use job_setup instead of setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for tag consistence among different languages since TW prefer them in the same name. Do you think it is necessary to modify the tag?

# [END instantiate]


# [START basic_company]
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's not necessary to declare a function here with a specific region tag. How about just specifying a company variable?

 company = {
       'display_name': 'Google',
       'distributor_company_id': distributor_company_id,
       'hq_location': '1600 Amphitheatre Parkway Mountain View, CA 94043'
}

You can use a fixed ID here as well I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could not use a fixed ID since creating an entity with same ID would lead to the failure of tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. This function is required from doc site and I couldn't use the fixed ID due to our system.

complete.companyName = company_name

results = complete.execute()
print('==========\n%s\n==========' % results)
Copy link
Contributor

Choose a reason for hiding this comment

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

The padding part ========== may not be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just want to make the output clear for customer. I could remove it if you think it is the better.

body=company_to_be_created).execute()
print('==========\nCompany created: %s\n==========' % company_created)
return company_created
except HttpError as e:
Copy link
Contributor

@michaelawyu michaelawyu Jul 16, 2018

Choose a reason for hiding this comment

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

Use the base error class (googleapiclient.errors.Error) would be better I think. Or you could just drop the try/except block and the let the error raise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.



# [START basic_job]
def generate_job_with_required_fields(company_name):
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel that this can be a simple job variable as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to distinguish this function from other generate job function such as generate_job_with_custom_attribute


# [START batch_job_create]
def batch_job_create(client_service, company_name):
import base_job_sample
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand your concern here; but for clarity I do feel that this part can be replaced with two simple job variables so that developers do not need to read another file to understand what's going on behind the scenes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be changed later since it request modifying the samples in all languages.

job_to_be_updated = jobs_to_be_updated[index]
job_to_be_updated.update({'job_title': 'Engineer in Mountain View'})
request = {'job': job_to_be_updated}
if index % 2 == 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

This part might be a little bit confusing I think. If we are showing the batch updating method do we really need to showcase updating only half of the jobs and leaving the other half alone? We can just update all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They want to have the updateRequest one with the field mask feature, one is not.

pass

batch = client_service.new_batch_http_request()
for index in range(0, len(jobs_to_be_updated)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Side note: if you switch to updating all jobs instead, this part can become for job in jobs, which is easier to understand and more idiomatic for Python devs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know. However, as mentioned above, they want half jobs updated using field mask feature, and half not.

pass

batch = client_service.new_batch_http_request()
for index in range(0, len(jobs_to_be_deleted)):
Copy link
Contributor

Choose a reason for hiding this comment

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

The index is not necessary though; how about for job in jobs?

@@ -0,0 +1,36 @@
# This file must be used with "source bin/activate.csh" *from csh*.
Copy link
Contributor

@michaelawyu michaelawyu Jul 17, 2018

Choose a reason for hiding this comment

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

Please remove this file from the commit.

jobs/env/bin/pip Outdated
@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1 @@
{"last_check":"2018-07-16T22:25:20Z","pypi_version":"10.0.1"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1 @@
/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/include
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1 @@
/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1 @@
/usr/include/python2.7
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1 @@
python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1 @@
python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,78 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

@@ -0,0 +1,11 @@
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this file from the commit.

Copy link
Contributor

@michaelawyu michaelawyu left a comment

Choose a reason for hiding this comment

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

PTAL at the comments.

@xinyunh0929
Copy link
Contributor Author

How could I add cla:yes back?


# [START instantiate]
from googleapiclient.discovery import build

Copy link
Contributor

@michaelawyu michaelawyu Jul 17, 2018

Choose a reason for hiding this comment

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

Please remove extra empty line(s) throughout the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@michaelawyu michaelawyu left a comment

Choose a reason for hiding this comment

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

See comments.

@michaelawyu michaelawyu merged commit a28eca0 into GoogleCloudPlatform:master Jul 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: no This human has *not* signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.