diff --git a/.kokoro/common.cfg b/.kokoro/common.cfg index c6f85f2fa42..eccfb8a1428 100644 --- a/.kokoro/common.cfg +++ b/.kokoro/common.cfg @@ -9,7 +9,7 @@ build_file: "python-docs-samples/.kokoro/trampoline.sh" # Use the Python worker docker image. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/python@sha256:d9de5f9279bccbfd75f52a179362da8fbd0ec2b08825415e793fec1c7b52bc9e" + value: "gcr.io/cloud-devrel-kokoro-resources/python@sha256:4b6ba8c199e96248980db4538065cddeea594138b9b9fb2d0388603922087747" } # Specify project ID diff --git a/.travis.yml b/.travis.yml index 2365aa29a28..924c6049b9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ sudo: false language: python +python: +- "3.6" services: - memcached - mysql @@ -27,7 +29,7 @@ addons: - python3.6-dev install: - pip install --upgrade pip wheel virtualenv -- pip install --upgrade nox-automation +- pip install --upgrade nox - pip install --upgrade git+https://github.com/dhermes/ci-diff-helper.git script: -- "./scripts/travis.sh" +- "./scripts/travis.sh" \ No newline at end of file diff --git a/appengine/standard_python37/django/mysite/settings.py b/appengine/standard_python37/django/mysite/settings.py index 4eaee248cbd..cd0b2e8e4bf 100644 --- a/appengine/standard_python37/django/mysite/settings.py +++ b/appengine/standard_python37/django/mysite/settings.py @@ -80,9 +80,9 @@ # https://docs.djangoproject.com/en/2.1/ref/settings/#databases # Install PyMySQL as mysqlclient/MySQLdb to use Django's mysqlclient adapter -# See https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-db-api-drivers for -# more information -import pymysql +# See https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-db-api-drivers +# for more information +import pymysql # noqa: 402 pymysql.install_as_MySQLdb() # [START db_setup] @@ -123,16 +123,16 @@ AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # noqa: 501 }, { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', # noqa: 501 }, { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', # noqa: 501 }, { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', # noqa: 501 }, ] diff --git a/appengine/standard_python37/django/polls/admin.py b/appengine/standard_python37/django/polls/admin.py index ffd3760197a..66762c6c53d 100644 --- a/appengine/standard_python37/django/polls/admin.py +++ b/appengine/standard_python37/django/polls/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Question, Choice +from .models import Choice, Question admin.site.register(Question) admin.site.register(Choice) diff --git a/appengine/standard_python37/django/polls/models.py b/appengine/standard_python37/django/polls/models.py index 4c96e2a643b..bfb969713c1 100644 --- a/appengine/standard_python37/django/polls/models.py +++ b/appengine/standard_python37/django/polls/models.py @@ -10,7 +10,7 @@ class Question(models.Model): def __str__(self): return self.question_text - + def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1) diff --git a/appengine/standard_python37/django/polls/tests.py b/appengine/standard_python37/django/polls/tests.py index 7ce503c2dd9..1848508267c 100644 --- a/appengine/standard_python37/django/polls/tests.py +++ b/appengine/standard_python37/django/polls/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +from django.test import TestCase # noqa: 401 # Create your tests here. diff --git a/appengine/standard_python37/django/polls/views.py b/appengine/standard_python37/django/polls/views.py index 5e908b2c515..20adc951ff8 100644 --- a/appengine/standard_python37/django/polls/views.py +++ b/appengine/standard_python37/django/polls/views.py @@ -1,5 +1,5 @@ -from django.http import HttpResponse, HttpResponseRedirect -from django.shortcuts import get_object_or_404 ,render +from django.http import HttpResponse, HttpResponseRedirect # noqa: 401 +from django.shortcuts import get_object_or_404, render from django.urls import reverse from django.views import generic @@ -24,6 +24,7 @@ class ResultsView(generic.DetailView): model = Question template_name = 'polls/results.html' + def vote(request, question_id): question = get_object_or_404(Question, pk=question_id) try: @@ -40,4 +41,6 @@ def vote(request, question_id): # Always return an HttpResponseRedirect after successfully dealing # with POST data. This prevents data from being posted twice if a # user hits the Back button. - return HttpResponseRedirect(reverse('polls:results', args=(question.id,))) + return HttpResponseRedirect( + reverse('polls:results', args=(question.id,)) + ) diff --git a/bigtable/hello/main.py b/bigtable/hello/main.py index 95c78e24fb5..9134751076b 100644 --- a/bigtable/hello/main.py +++ b/bigtable/hello/main.py @@ -43,6 +43,7 @@ def main(project_id, instance_id, table_id): # [START creating_a_table] print('Creating the {} table.'.format(table_id)) table = instance.table(table_id) + print('Creating column family cf1 with Max Version GC rule...') # Create a column family with GC policy : most recent N versions # Define the GC policy to retain only the most recent 2 versions diff --git a/ml_engine/online_prediction/predict.py b/ml_engine/online_prediction/predict.py index 910f2efde45..270259b6b6e 100644 --- a/ml_engine/online_prediction/predict.py +++ b/ml_engine/online_prediction/predict.py @@ -141,7 +141,7 @@ def main(project, model, version=None, force_tfrecord=False): """Send user input to the prediction service.""" while True: try: - user_input = json.loads(raw_input("Valid JSON >>>")) + user_input = json.loads(input("Valid JSON >>>")) except KeyboardInterrupt: return diff --git a/nox.py b/noxfile.py similarity index 89% rename from nox.py rename to noxfile.py index e1f04e36eec..d89cddcbb6d 100644 --- a/nox.py +++ b/noxfile.py @@ -40,7 +40,7 @@ def _list_files(folder, pattern): def _collect_dirs( start_dir, - blacklist=set(['conftest.py', 'nox.py', 'lib', 'third_party']), + blacklist=set(['conftest.py', 'noxfile.py', 'lib', 'third_party']), suffix='_test.py', recurse_further=False): """Recursively collects a list of dirs that contain a file matching the @@ -52,8 +52,10 @@ def _collect_dirs( # Collect all the directories that have tests in them. for parent, subdirs, files in os.walk(start_dir): if './.' in parent: - continue # Skip top-level dotfiles - elif any(f for f in files if f.endswith(suffix) and f not in blacklist): + continue # Skip top-level dotfiles + elif any( + f for f in files if f.endswith(suffix) and f not in blacklist + ): # Don't recurse further for tests, since py.test will do that. if not recurse_further: del subdirs[:] @@ -147,13 +149,17 @@ def _setup_appengine_sdk(session): '--show-source', '--builtin', 'gettext', '--max-complexity', '20', '--import-order-style', 'google', '--exclude', '.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py', - '--ignore=E121,E123,E126,E226,E24,E704,W503,W504,I202', + '--ignore=E121,E123,E126,E226,E24,E704,W503,W504,I100,I201,I202', ] # Collect sample directories. ALL_TESTED_SAMPLES = sorted(list(_collect_dirs('.'))) -ALL_SAMPLE_DIRECTORIES = sorted(list(_collect_dirs('.', suffix='.py', recurse_further=True))) +ALL_SAMPLE_DIRECTORIES = sorted(list(_collect_dirs( + '.', + suffix='.py', + recurse_further=True +))) GAE_STANDARD_SAMPLES = [ sample for sample in ALL_TESTED_SAMPLES if sample.startswith('./appengine/standard/')] @@ -162,9 +168,11 @@ def _setup_appengine_sdk(session): sample for sample in ALL_TESTED_SAMPLES if (sample.startswith('./appengine/standard_python37') or sample.startswith('./functions/'))] -NON_GAE_STANDARD_SAMPLES_PY2 = sorted( - list((set(ALL_TESTED_SAMPLES) - set(GAE_STANDARD_SAMPLES)) - - set(PY3_ONLY_SAMPLES))) +NON_GAE_STANDARD_SAMPLES_PY2 = sorted(list(( + set(ALL_TESTED_SAMPLES) - + set(GAE_STANDARD_SAMPLES)) - + set(PY3_ONLY_SAMPLES) +)) NON_GAE_STANDARD_SAMPLES_PY3 = sorted( list(set(ALL_TESTED_SAMPLES) - set(PY2_ONLY_SAMPLES))) @@ -193,7 +201,7 @@ def _session_tests(session, sample, post_install=None): session.chdir(sample) - if os.path.exists(os.path.join(sample, 'requirements.txt')): + if os.path.exists('requirements.txt'): session.install('-r', 'requirements.txt') if post_install: @@ -208,10 +216,10 @@ def _session_tests(session, sample, post_install=None): success_codes=[0, 5]) +@nox.session(python='2.7') @nox.parametrize('sample', GAE_STANDARD_SAMPLES) -def session_gae(session, sample): +def gae(session, sample): """Runs py.test for an App Engine standard sample.""" - session.interpreter = 'python2.7' # Create a lib directory if needed, otherwise the App Engine vendor library # will complain. @@ -221,22 +229,23 @@ def session_gae(session, sample): _session_tests(session, sample, _setup_appengine_sdk) +@nox.session(python='2.7') @nox.parametrize('sample', NON_GAE_STANDARD_SAMPLES_PY2) -def session_py27(session, sample): +def py27(session, sample): """Runs py.test for a sample using Python 2.7""" - session.interpreter = 'python2.7' _session_tests(session, sample) +@nox.session(python='3.6') @nox.parametrize('sample', NON_GAE_STANDARD_SAMPLES_PY3) -def session_py36(session, sample): +def py36(session, sample): """Runs py.test for a sample using Python 3.6""" - session.interpreter = 'python3.6' _session_tests(session, sample) +@nox.session @nox.parametrize('sample', ALL_SAMPLE_DIRECTORIES) -def session_lint(session, sample): +def lint(session, sample): """Runs flake8 on the sample.""" session.install('flake8', 'flake8-import-order') @@ -253,10 +262,9 @@ def session_lint(session, sample): # Utility sessions # - -def session_missing_tests(session): +@nox.session +def missing_tests(session): """Lists all sample directories that do not have tests.""" - session.virtualenv = False print('The following samples do not have tests:') for sample in set(ALL_SAMPLE_DIRECTORIES) - set(ALL_TESTED_SAMPLES): print('* {}'.format(sample)) @@ -266,8 +274,9 @@ def session_missing_tests(session): list(_collect_dirs('.', suffix='.rst.in'))) +@nox.session @nox.parametrize('sample', SAMPLES_WITH_GENERATED_READMES) -def session_readmegen(session, sample): +def readmegen(session, sample): """(Re-)generates the readme for a sample.""" session.install('jinja2', 'pyyaml') @@ -278,7 +287,8 @@ def session_readmegen(session, sample): session.run('python', 'scripts/readme-gen/readme_gen.py', in_file) -def session_check_requirements(session): +@nox.session +def check_requirements(session): """Checks for out of date requirements and optionally updates them. This is intentionally not parametric, as it's desired to never have two