-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Conversation
Still working on the samples. But I would like to know how to run local tests for my samples. |
I am working on the tests to those samples, however, I don't know how to run those '_test' files. Is there any guide? |
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. |
jobs/auto_complete_sample.py
Outdated
from googleapiclient.discovery import build | ||
|
||
client_service = build('jobs', 'v2') | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
jobs/auto_complete_sample.py
Outdated
|
||
import time | ||
|
||
# [START instantiate] |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
jobs/base_company_sample.py
Outdated
# [END instantiate] | ||
|
||
|
||
# [START basic_company] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
jobs/auto_complete_sample.py
Outdated
complete.companyName = company_name | ||
|
||
results = complete.execute() | ||
print('==========\n%s\n==========' % results) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
jobs/base_company_sample.py
Outdated
body=company_to_be_created).execute() | ||
print('==========\nCompany created: %s\n==========' % company_created) | ||
return company_created | ||
except HttpError as e: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
jobs/base_job_sample.py
Outdated
|
||
|
||
# [START basic_job] | ||
def generate_job_with_required_fields(company_name): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
jobs/batch_operation_sample.py
Outdated
|
||
# [START batch_job_create] | ||
def batch_job_create(client_service, company_name): | ||
import base_job_sample |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
jobs/batch_operation_sample.py
Outdated
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
jobs/batch_operation_sample.py
Outdated
pass | ||
|
||
batch = client_service.new_batch_http_request() | ||
for index in range(0, len(jobs_to_be_updated)): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
jobs/batch_operation_sample.py
Outdated
pass | ||
|
||
batch = client_service.new_batch_http_request() | ||
for index in range(0, len(jobs_to_be_deleted)): |
There was a problem hiding this comment.
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
?
jobs/env/bin/activate.csh
Outdated
@@ -0,0 +1,36 @@ | ||
# This file must be used with "source bin/activate.csh" *from csh*. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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/pip2
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pip2.7
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pyrsa-decrypt
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pip-selfcheck.json
Outdated
@@ -0,0 +1 @@ | ||
{"last_check":"2018-07-16T22:25:20Z","pypi_version":"10.0.1"} |
There was a problem hiding this comment.
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/local/include
Outdated
@@ -0,0 +1 @@ | ||
/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/include |
There was a problem hiding this comment.
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/local/bin
Outdated
@@ -0,0 +1 @@ | ||
/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin |
There was a problem hiding this comment.
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/include/python2.7
Outdated
@@ -0,0 +1 @@ | ||
/usr/include/python2.7 |
There was a problem hiding this comment.
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/wheel
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/python2.7
Outdated
@@ -0,0 +1 @@ | ||
python |
There was a problem hiding this comment.
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/python2
Outdated
@@ -0,0 +1 @@ | ||
python |
There was a problem hiding this comment.
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/python-config
Outdated
@@ -0,0 +1,78 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pyrsa-verify
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pyrsa-sign
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pyrsa-priv2pub
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pyrsa-keygen
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pyrsa-encrypt-bigfile
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pyrsa-encrypt
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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/pyrsa-decrypt-bigfile
Outdated
@@ -0,0 +1,11 @@ | ||
#!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
How could I add cla:yes back? |
|
||
# [START instantiate] | ||
from googleapiclient.discovery import build | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments.
CJD got Public beta launch so we would like to have our samples checked in as other projects.