From 96701837f842756353d26ae7489939428212d473 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 26 Sep 2016 12:43:30 -0700 Subject: [PATCH] Making bigquery subpackage into a proper package. - Adding README, setup.py, MANIFEST.in, .coveragerc and tox.ini - Adding google-cloud-bigquery as a dependency to the umbrella package - Adding the bigquery subdirectory into the list of packages for verifying the docs - Incorporating the bigquery subdirectory into the umbrella coverage report - Adding the bigquery only tox tests to the Travis config - Adding {toxinidir}/../core as a dependency for the bigquery tox config --- .travis.yml | 3 + bigquery/.coveragerc | 11 ++++ bigquery/MANIFEST.in | 4 ++ bigquery/README.rst | 89 ++++++++++++++++++++++++++++++ bigquery/setup.py | 68 +++++++++++++++++++++++ bigquery/tox.ini | 30 ++++++++++ scripts/verify_included_modules.py | 1 + setup.py | 1 + tox.ini | 7 +++ 9 files changed, 214 insertions(+) create mode 100644 bigquery/.coveragerc create mode 100644 bigquery/MANIFEST.in create mode 100644 bigquery/README.rst create mode 100644 bigquery/setup.py create mode 100644 bigquery/tox.ini diff --git a/.travis.yml b/.travis.yml index e99696201aad..c51faf9b92b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,17 +10,20 @@ script: - (cd bigtable && tox -e py27) - (cd storage && tox -e py27) - (cd datastore && tox -e py27) + - (cd bigquery && tox -e py27) - tox -e py34 - (cd core && tox -e py34) - (cd bigtable && tox -e py34) - (cd storage && tox -e py34) - (cd datastore && tox -e py34) + - (cd bigquery && tox -e py34) - tox -e lint - tox -e cover - (cd core && tox -e cover) - (cd bigtable && tox -e cover) - (cd storage && tox -e cover) - (cd datastore && tox -e cover) + - (cd bigquery && tox -e cover) - tox -e system-tests - tox -e system-tests3 - scripts/update_docs.sh diff --git a/bigquery/.coveragerc b/bigquery/.coveragerc new file mode 100644 index 000000000000..a54b99aa14b7 --- /dev/null +++ b/bigquery/.coveragerc @@ -0,0 +1,11 @@ +[run] +branch = True + +[report] +fail_under = 100 +show_missing = True +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ diff --git a/bigquery/MANIFEST.in b/bigquery/MANIFEST.in new file mode 100644 index 000000000000..cb3a2b9ef4fa --- /dev/null +++ b/bigquery/MANIFEST.in @@ -0,0 +1,4 @@ +include README.rst +graft google +graft unit_tests +global-exclude *.pyc diff --git a/bigquery/README.rst b/bigquery/README.rst new file mode 100644 index 000000000000..202cf807e1ca --- /dev/null +++ b/bigquery/README.rst @@ -0,0 +1,89 @@ +Python Client for Google Cloud BigQuery +======================================= + + Python idiomatic client for `Google Cloud BigQuery`_ + +.. _Google Cloud BigQuery: https://cloud.google.com/bigquery/what-is-bigquery + +- `Homepage`_ +- `API Documentation`_ + +.. _Homepage: https://googlecloudplatform.github.io/google-cloud-python/ +.. _API Documentation: http://googlecloudplatform.github.io/google-cloud-python/ + +Quick Start +----------- + +:: + + $ pip install --upgrade google-cloud-bigquery + +Authentication +-------------- + +With ``google-cloud-python`` we try to make authentication as painless as +possible. Check out the `Authentication section`_ in our documentation to +learn more. You may also find the `authentication document`_ shared by all +the ``google-cloud-*`` libraries to be helpful. + +.. _Authentication section: http://google-cloud-python.readthedocs.io/en/latest/google-cloud-auth.html +.. _authentication document: https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/authentication + +Using the API +------------- + +Querying massive datasets can be time consuming and expensive without the +right hardware and infrastructure. Google `BigQuery`_ (`BigQuery API docs`_) +solves this problem by enabling super-fast, SQL-like queries against +append-only tables, using the processing power of Google's infrastructure. + +.. _BigQuery: https://cloud.google.com/bigquery/what-is-bigquery +.. _BigQuery API docs: https://cloud.google.com/bigquery/docs/reference/v2/ + +Load data from CSV +~~~~~~~~~~~~~~~~~~ + +.. code:: python + + import csv + + from google.cloud import bigquery + from google.cloud.bigquery import SchemaField + + client = bigquery.Client() + + dataset = client.dataset('dataset_name') + dataset.create() # API request + + SCHEMA = [ + SchemaField('full_name', 'STRING', mode='required'), + SchemaField('age', 'INTEGER', mode='required'), + ] + table = dataset.table('table_name', SCHEMA) + table.create() + + with open('csv_file', 'rb') as readable: + table.upload_from_file( + readable, source_format='CSV', skip_leading_rows=1) + +Perform a synchronous query +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: python + + # Perform a synchronous query. + QUERY = ( + 'SELECT name FROM [bigquery-public-data:usa_names.usa_1910_2013] ' + 'WHERE state = "TX"') + query = client.run_sync_query('%s LIMIT 100' % QUERY) + query.timeout_ms = TIMEOUT_MS + query.run() + + for row in query.rows: + print(row) + + +See the ``google-cloud-python`` API `BigQuery documentation`_ to learn how +to connect to BigQuery using this Client Library. + +.. _BigQuery documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/bigquery-usage.html diff --git a/bigquery/setup.py b/bigquery/setup.py new file mode 100644 index 000000000000..2e94a44776e6 --- /dev/null +++ b/bigquery/setup.py @@ -0,0 +1,68 @@ +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from setuptools import find_packages +from setuptools import setup + + +PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__)) + +with open(os.path.join(PACKAGE_ROOT, 'README.rst')) as file_obj: + README = file_obj.read() + +# NOTE: This is duplicated throughout and we should try to +# consolidate. +SETUP_BASE = { + 'author': 'Google Cloud Platform', + 'author_email': 'jjg+google-cloud-python@google.com', + 'scripts': [], + 'url': 'https://github.com/GoogleCloudPlatform/google-cloud-python', + 'license': 'Apache 2.0', + 'platforms': 'Posix; MacOS X; Windows', + 'include_package_data': True, + 'zip_safe': False, + 'classifiers': [ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Topic :: Internet', + ], +} + + +REQUIREMENTS = [ + 'google-cloud-core', +] + +setup( + name='google-cloud-bigquery', + version='0.20.0dev', + description='Python Client for Google BigQuery', + long_description=README, + namespace_packages=[ + 'google', + 'google.cloud', + ], + packages=find_packages(), + install_requires=REQUIREMENTS, + **SETUP_BASE +) diff --git a/bigquery/tox.ini b/bigquery/tox.ini new file mode 100644 index 000000000000..4a5000739647 --- /dev/null +++ b/bigquery/tox.ini @@ -0,0 +1,30 @@ +[tox] +envlist = + py27,py34,py35,cover + +[testing] +deps = + {toxinidir}/../core + pytest +covercmd = + py.test --quiet \ + --cov=google.cloud.bigquery \ + --cov=unit_tests \ + --cov-config {toxinidir}/.coveragerc \ + unit_tests + +[testenv] +commands = + py.test --quiet {posargs} unit_tests +deps = + {[testing]deps} + +[testenv:cover] +basepython = + python2.7 +commands = + {[testing]covercmd} +deps = + {[testenv]deps} + coverage + pytest-cov diff --git a/scripts/verify_included_modules.py b/scripts/verify_included_modules.py index 71d52b13f43d..8bd4e73d65f8 100644 --- a/scripts/verify_included_modules.py +++ b/scripts/verify_included_modules.py @@ -59,6 +59,7 @@ ]) PACKAGES = ( '', + 'bigquery', 'bigtable', 'core', 'datastore', diff --git a/setup.py b/setup.py index cc8e11714518..26b52c5b9f5f 100644 --- a/setup.py +++ b/setup.py @@ -50,6 +50,7 @@ REQUIREMENTS = [ + 'google-cloud-bigquery', 'google-cloud-bigtable', 'google-cloud-core', 'google-cloud-datastore', diff --git a/tox.ini b/tox.ini index 9ee3733bb156..c7bb3d36190b 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ deps = {toxinidir}/bigtable {toxinidir}/storage {toxinidir}/datastore + {toxinidir}/bigquery pytest covercmd = py.test --quiet \ @@ -39,6 +40,12 @@ covercmd = --cov-append \ --cov-config {toxinidir}/.coveragerc \ datastore/unit_tests + py.test --quiet \ + --cov=google.cloud \ + --cov=unit_tests \ + --cov-append \ + --cov-config {toxinidir}/.coveragerc \ + bigquery/unit_tests coverage report --show-missing --fail-under=100 [testenv]