diff --git a/.coveragerc b/.coveragerc index 77dd56b8e2e8..240882dc7d07 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,5 @@ [report] omit = - */demo/* - */demo.py */_generated/*.py exclude_lines = # Re-enable the standard pragma diff --git a/gcloud/datastore/demo/__init__.py b/gcloud/datastore/demo/__init__.py deleted file mode 100644 index cf0a84004efc..000000000000 --- a/gcloud/datastore/demo/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# 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 gcloud.environment_vars import TESTS_DATASET - -__all__ = ['PROJECT'] - -PROJECT = os.getenv(TESTS_DATASET) diff --git a/gcloud/datastore/demo/__main__.py b/gcloud/datastore/demo/__main__.py deleted file mode 100644 index e5e55065a9fa..000000000000 --- a/gcloud/datastore/demo/__main__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# 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. - -# pragma NO COVER -from gcloud import demo -from gcloud import datastore - -demo.DemoRunner.from_module(datastore).run() diff --git a/gcloud/datastore/demo/demo.py b/gcloud/datastore/demo/demo.py deleted file mode 100644 index 5814db57b88b..000000000000 --- a/gcloud/datastore/demo/demo.py +++ /dev/null @@ -1,119 +0,0 @@ -# Welcome to the gCloud Datastore Demo! (hit enter) -# We're going to walk through some of the basics... -# Don't worry though. You don't need to do anything, just keep hitting enter... - -# Copyright 2014 Google Inc. All rights reserved. -# -# 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. - -# Let's start by importing the demo module and initializing our client. -from gcloud import datastore -from gcloud.datastore import demo - -client = datastore.Client(project=demo.PROJECT) - -# Let's create a new entity of type "Thing" and name it 'Toy': -key = client.key('Thing') -toy = datastore.Entity(key) -toy.update({'name': 'Toy'}) - -# Now let's save it to our datastore: -client.put(toy) - -# If we look it up by its key, we should find it... -print(client.get(toy.key)) - -# And we should be able to delete it... -client.delete(toy.key) - -# Since we deleted it, if we do another lookup it shouldn't be there again: -print(client.get(toy.key)) - -# Now let's try a more advanced query. -# First, let's create some entities. -SAMPLE_DATA = [ - (1234, 'Computer', 10), - (2345, 'Computer', 8), - (3456, 'Laptop', 10), - (4567, 'Printer', 11), - (5678, 'Printer', 12), - (6789, 'Computer', 13)] -sample_keys = [] -for id, name, age in SAMPLE_DATA: - key = client.key('Thing', id) - sample_keys.append(key) - entity = datastore.Entity(key) - entity['name'] = name - entity['age'] = age - client.put(entity) -# We'll start by look at all Thing entities: -query = client.query(kind='Thing') - -# Let's look at the first two. -print(list(query.fetch(limit=2))) - -# Now let's check for Thing entities named 'Computer' -query.add_filter('name', '=', 'Computer') -print(list(query.fetch())) - -# If you want to filter by multiple attributes, -# you can call .add_filter multiple times on the query. -query.add_filter('age', '=', 10) -print(list(query.fetch())) - -# Now delete them. -client.delete_multi(sample_keys) - -# You can also work inside a transaction. -# (Check the official docs for explanations of what's happening here.) -with client.transaction() as xact: - print('Creating and saving an entity...') - key = client.key('Thing', 'foo') - thing = datastore.Entity(key) - thing['age'] = 10 - xact.put(thing) - - print('Creating and saving another entity...') - key2 = client.key('Thing', 'bar') - thing2 = datastore.Entity(key2) - thing2['age'] = 15 - xact.put(thing2) - - print('Committing the transaction...') - -# Now that the transaction is commited, let's delete the entities. -client.delete_multi([key, key2]) - -# To rollback a transaction, just call .rollback() -with client.transaction() as xact: - key = client.key('Thing', 'another') - thing = datastore.Entity(key) - xact.put(thing) - xact.rollback() - -# Let's check if the entity was actually created: -created = client.get(key) -print('yes' if created else 'no') - -# Remember, a key won't be complete until the transaction is commited. -# That is, while inside the transaction block, thing.key will be incomplete. -with client.transaction() as xact: - key = client.key('Thing') # partial - thing = datastore.Entity(key) - xact.put(thing) - print(thing.key) # This will still be partial - -print(thing.key) # This will be complete - -# Now let's delete the entity. -client.delete(thing.key) diff --git a/gcloud/demo.py b/gcloud/demo.py deleted file mode 100644 index 05b78a4ab8c4..000000000000 --- a/gcloud/demo.py +++ /dev/null @@ -1,131 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# 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. - -# pragma NO COVER -from code import interact -import itertools -import os.path -import sys -import time -from six.moves import input - - -class DemoRunner(object): - """An interactive runner of demo scripts.""" - - KEYPRESS_DELAY = 0.02 - GLOBALS, LOCALS = globals(), locals() - CODE, COMMENT = 'code', 'comment' - - def __init__(self, fp): - self.lines = [line.rstrip() for line in fp.readlines()] - - @classmethod - def from_module(cls, module): - path = os.path.join(os.path.dirname(module.__file__), - 'demo', 'demo.py') - - return cls(open(path, 'r')) - - def run(self): - line_groups = itertools.groupby(self.lines, self.get_line_type) - - newline = False # Don't use newline on the first statement. - for group_type, lines in line_groups: - if group_type == self.COMMENT: - self.write(lines, newline=newline) - newline = True - - elif group_type == self.CODE: - self.code(lines) - - interact('(Hit CTRL-D to exit...)', local=self.LOCALS) - - def wait(self): - input() - - @classmethod - def get_line_type(cls, line): - if line.startswith('#'): - return cls.COMMENT - else: - return cls.CODE - - def get_indent_level(self, line): - if not line.strip(): - return None - return len(line) - len(line.lstrip()) - - def _print(self, text='', newline=True): - sys.stdout.write(text) - if newline: - sys.stdout.write('\n') - - def write(self, lines, newline=True): - self._print(newline=newline) - self._print('\n'.join(lines), False) - self.wait() - - def code(self, lines): - code_lines = [] - - for line in lines: - indent = self.get_indent_level(line) - - # If we've completed a block, - # run whatever code was built up in code_lines. - if indent == 0: - self._execute_lines(code_lines) - code_lines = [] - - # Print the prefix for the line depending on the indentation level. - if indent == 0: - self._print('>>> ', False) - elif indent > 0: - self._print('\n... ', False) - elif indent is None: - continue - - # Break the line into the code section and the comment section. - if '#' in line: - code, comment = line.split('#', 2) - else: - code, comment = line, None - - # 'Type' out the comment section. - for char in code.rstrip(): - time.sleep(self.KEYPRESS_DELAY) - sys.stdout.write(char) - sys.stdout.flush() - - # Print the comment section (not typed out). - if comment: - sys.stdout.write(' # %s' % comment.strip()) - - # Add the current line to the list of lines to be run - # in this block. - code_lines.append(line) - - # If we had any code built up that wasn't part of a completed block - # (ie, the lines ended with an indented line), - # run that code. - if code_lines: - self._execute_lines(code_lines) - - def _execute_lines(self, lines): - if lines: - self.wait() - - # Yes, this is crazy unsafe... but it's demo code. - exec('\n'.join(lines), self.GLOBALS, self.LOCALS) diff --git a/gcloud/storage/demo/__init__.py b/gcloud/storage/demo/__init__.py deleted file mode 100644 index a5d4b20fc566..000000000000 --- a/gcloud/storage/demo/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# 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 gcloud.environment_vars import TESTS_PROJECT - -__all__ = ['PROJECT_ID'] - -PROJECT_ID = os.getenv(TESTS_PROJECT) diff --git a/gcloud/storage/demo/__main__.py b/gcloud/storage/demo/__main__.py deleted file mode 100644 index ada9e7858624..000000000000 --- a/gcloud/storage/demo/__main__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# 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. - -# pragma NO COVER -from gcloud import demo -from gcloud import storage - -demo.DemoRunner.from_module(storage).run() diff --git a/gcloud/storage/demo/demo.py b/gcloud/storage/demo/demo.py deleted file mode 100644 index f64c05f145d0..000000000000 --- a/gcloud/storage/demo/demo.py +++ /dev/null @@ -1,55 +0,0 @@ -# Welcome to the gCloud Storage Demo! (hit enter) -# We're going to walk through some of the basics... -# Don't worry though. You don't need to do anything, just keep hitting enter... - -# Copyright 2014 Google Inc. All rights reserved. -# -# 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. - -# Let's start by importing the demo module and getting a client: -import time - -from gcloud import storage -from gcloud.storage import demo - -client = storage.Client(project=demo.PROJECT_ID) - -# OK, now let's look at all of the buckets... -print(list(client.list_buckets())) # This might take a second... - -# Now let's create a new bucket... -bucket_name = ("bucket-%s" % time.time()).replace(".", "") # Get rid of dots. -print(bucket_name) -bucket = client.create_bucket(bucket_name) -print(bucket) - -# Let's look at all of the buckets again... -print(list(client.list_buckets())) - -# How about we create a new blob inside this bucket. -blob = bucket.blob("my-new-file.txt") - -# Now let's put some data in there. -blob.upload_from_string("this is some data!") - -# ... and we can read that data back again. -print(blob.download_as_string()) - -# Now let's delete that blob. -print(blob.delete()) - -# And now that we're done, let's delete that bucket... -print(bucket.delete()) - -# Alright! That's all! -# Here's an interactive prompt for you now... diff --git a/scripts/pylintrc_default b/scripts/pylintrc_default index 79c31cf9a83c..9b99cdb0b5c5 100644 --- a/scripts/pylintrc_default +++ b/scripts/pylintrc_default @@ -2,7 +2,7 @@ # # NOTES: # -# - Rules for test / demo code are generated into 'pylintrc_reduced' +# - Rules for test code are generated into 'pylintrc_reduced' # as deltas from this configuration by the 'run_pylint.py' script. # # - 'RATIONALE: API mapping' as a defense for non-default settings is diff --git a/scripts/run_pylint.py b/scripts/run_pylint.py index bfd8cf020f01..888d68a427dd 100644 --- a/scripts/run_pylint.py +++ b/scripts/run_pylint.py @@ -17,7 +17,7 @@ This runs pylint as a script via subprocess in two different subprocesses. The first lints the production/library code using the default rc file (PRODUCTION_RC). The second lints the -demo/test code using an rc file (TEST_RC) which allows more style +test code using an rc file (TEST_RC) which allows more style violations (hence it has a reduced number of style checks). """ @@ -126,7 +126,7 @@ def is_production_filename(filename): :rtype: bool :returns: Boolean indicating production status. """ - return not ('demo' in filename or 'test' in filename) + return 'test' not in filename def get_files_for_linting(allow_limited=True): @@ -195,7 +195,7 @@ def get_python_files(all_files=None): :rtype: tuple :returns: A tuple containing two lists and a boolean. The first list - contains all production files, the next all test/demo files and + contains all production files, the next all test files and the boolean indicates if a restricted fileset was used. """ using_restricted = False @@ -243,7 +243,7 @@ def main(): library_files, non_library_files, using_restricted = get_python_files() try: lint_fileset(library_files, PRODUCTION_RC, 'library code') - lint_fileset(non_library_files, TEST_RC, 'test and demo code') + lint_fileset(non_library_files, TEST_RC, 'test code') except SystemExit: if not using_restricted: raise @@ -254,7 +254,7 @@ def main(): library_files, non_library_files, _ = get_python_files( all_files=all_files) lint_fileset(library_files, PRODUCTION_RC, 'library code') - lint_fileset(non_library_files, TEST_RC, 'test and demo code') + lint_fileset(non_library_files, TEST_RC, 'test code') if __name__ == '__main__': diff --git a/scripts/verify_included_modules.py b/scripts/verify_included_modules.py index a136e72c2d8a..eb1a6f3571fe 100644 --- a/scripts/verify_included_modules.py +++ b/scripts/verify_included_modules.py @@ -34,17 +34,12 @@ 'gcloud.bigquery.__init__', 'gcloud.bigtable.__init__', 'gcloud.datastore.__init__', - 'gcloud.datastore.demo.__init__', - 'gcloud.datastore.demo.demo', - 'gcloud.demo', 'gcloud.dns.__init__', 'gcloud.iterator', 'gcloud.pubsub.__init__', 'gcloud.resource_manager.__init__', 'gcloud.search.__init__', 'gcloud.storage.__init__', - 'gcloud.storage.demo.__init__', - 'gcloud.storage.demo.demo', 'gcloud.streaming.__init__', 'gcloud.streaming.buffered_stream', 'gcloud.streaming.exceptions',