-
Notifications
You must be signed in to change notification settings - Fork 125
project_id as optional #127
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
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c85a685
project_id is optional
max-sixty 8786e6d
Merge branch 'master' into default-project
max-sixty 17a2ede
gitignore
max-sixty 86b6fc5
docstring
max-sixty 11c146e
don't skip if no project
max-sixty 817c63a
formatting
max-sixty f0a8d36
add marks to allow test selecting
max-sixty 4ecfcfc
assign mark to test
max-sixty c402952
explicitly chose with auth to do from travis
max-sixty 476bcf1
too hasty to change the pandas installation
max-sixty ef59bca
do what needs doing
max-sixty 2112acd
Fixing style errors.
stickler-ci 6cc99f6
docstring & import order
max-sixty 56436ff
correct mark expression
max-sixty 5347858
project not required only if default creds available
max-sixty cd9b37d
remove any more branching in travis
max-sixty fa97b0f
Merge branch 'master' of https://github.com/pydata/pandas-gbq into de…
max-sixty a7f6c43
google import inline
max-sixty 2d50519
Merge remote-tracking branch 'upstream/master' into pr-127-maxim-lian…
tswast 7932c59
Use tuple for credentials & project for default project detection.
tswast 31e001f
lint errors.
tswast 08477cc
Remove extra project detection.
tswast 1f1f2c4
Update bad_project_id test to query actual data.
tswast d920959
Skip credentials tests if key not present.
tswast a3e6d2f
DOC: add project_id optional to changelog
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ | |
.ipynb_checkpoints | ||
.tags | ||
.pytest_cache | ||
.testmondata | ||
.testmon* | ||
.vscode/ | ||
|
||
# Docs # | ||
######## | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,6 @@ | |
TABLE_ID = 'new_test' | ||
|
||
|
||
def _skip_local_auth_if_in_travis_env(): | ||
if _in_travis_environment(): | ||
pytest.skip("Cannot run local auth in travis environment") | ||
|
||
|
||
def _skip_if_no_private_key_path(): | ||
if not _get_private_key_path(): | ||
pytest.skip("Cannot run integration tests without a " | ||
|
@@ -52,12 +47,8 @@ def _get_dataset_prefix_random(): | |
|
||
|
||
def _get_project_id(): | ||
|
||
project = os.environ.get('GBQ_PROJECT_ID') | ||
if not project: | ||
pytest.skip( | ||
"Cannot run integration tests without a project id") | ||
return project | ||
return (os.environ.get('GBQ_PROJECT_ID') | ||
or os.environ.get('GOOGLE_CLOUD_PROJECT')) # noqa | ||
|
||
|
||
def _get_private_key_path(): | ||
|
@@ -87,9 +78,12 @@ def _test_imports(): | |
gbq._test_google_api_imports() | ||
|
||
|
||
@pytest.fixture | ||
def project(): | ||
return _get_project_id() | ||
@pytest.fixture(params=['env']) | ||
def project(request): | ||
if request.param == 'env': | ||
return _get_project_id() | ||
elif request.param == 'none': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this didn't get used, but could param over it in the future) |
||
return None | ||
|
||
|
||
def _check_if_can_get_correct_default_credentials(): | ||
|
@@ -101,11 +95,13 @@ def _check_if_can_get_correct_default_credentials(): | |
from google.auth.exceptions import DefaultCredentialsError | ||
|
||
try: | ||
credentials, _ = google.auth.default(scopes=[gbq.GbqConnector.scope]) | ||
credentials, project = google.auth.default( | ||
scopes=[gbq.GbqConnector.scope]) | ||
except (DefaultCredentialsError, IOError): | ||
return False | ||
|
||
return gbq._try_credentials(_get_project_id(), credentials) is not None | ||
return gbq._try_credentials( | ||
project or _get_project_id(), credentials) is not None | ||
|
||
|
||
def clean_gbq_environment(dataset_prefix, private_key=None): | ||
|
@@ -173,21 +169,18 @@ def test_generate_bq_schema_deprecated(): | |
gbq.generate_bq_schema(df) | ||
|
||
|
||
@pytest.fixture(params=['local', 'service_path', 'service_creds']) | ||
@pytest.fixture(params=[ | ||
pytest.param('local', marks=pytest.mark.local_auth), | ||
pytest.param('service_path', marks=pytest.mark.s_path_auth), | ||
pytest.param('service_creds', marks=pytest.mark.s_cred_auth), | ||
]) | ||
def auth_type(request): | ||
|
||
auth = request.param | ||
|
||
if auth == 'local': | ||
|
||
if _in_travis_environment(): | ||
pytest.skip("Cannot run local auth in travis environment") | ||
|
||
pass | ||
elif auth == 'service_path': | ||
|
||
if _in_travis_environment(): | ||
pytest.skip("Only run one auth type in Travis to save time") | ||
|
||
_skip_if_no_private_key_path() | ||
elif auth == 'service_creds': | ||
_skip_if_no_private_key_contents() | ||
|
@@ -238,13 +231,12 @@ def test_should_be_able_to_get_results_from_query(self, gbq_connector): | |
assert pages is not None | ||
|
||
|
||
@pytest.mark.local_auth | ||
class TestGBQConnectorIntegrationWithLocalUserAccountAuth(object): | ||
|
||
@pytest.fixture(autouse=True) | ||
def setup(self, project): | ||
|
||
_skip_local_auth_if_in_travis_env() | ||
|
||
self.sut = gbq.GbqConnector(project, auth_local_webserver=True) | ||
|
||
def test_get_application_default_credentials_does_not_throw_error(self): | ||
|
@@ -310,12 +302,8 @@ def test_to_gbq_should_fail_if_invalid_table_name_passed(self): | |
with pytest.raises(gbq.NotFoundException): | ||
gbq.to_gbq(DataFrame(), 'invalid_table_name', project_id="1234") | ||
|
||
def test_to_gbq_with_no_project_id_given_should_fail(self): | ||
with pytest.raises(TypeError): | ||
gbq.to_gbq(DataFrame(), 'dataset.tablename') | ||
|
||
def test_read_gbq_with_no_project_id_given_should_fail(self): | ||
with pytest.raises(TypeError): | ||
def test_read_gbq_with_no_project_id_given_should_pass(self, credentials): | ||
if _check_if_can_get_correct_default_credentials(): | ||
gbq.read_gbq('SELECT 1') | ||
|
||
def test_that_parse_data_works_properly(self): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
On second thought, this could cause us to go through the whole "application default credentials" flow twice, which could be quite slow. (It checks for env var, checks for GCE, checks for App Engine, ...)
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.
Could we change https://github.com/maxim-lian/pandas-gbq/blob/a7f6c43434bc21e1d2fc7633d3c5cb9c04060a4a/pandas_gbq/gbq.py#L223 to not discard the project instead?
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.
OK, and it's not cached?
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.
Yeah not great:
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.
What do you think about changing those methods to return 2-tuples?
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 think tuples would be reasonable. The other (more disruptive, probably) option would be to pass in the project to the credentials methods and have them return a
google.cloud.bigquery.Client
.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 updated this PR to tuples as we discussed.