Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Added Bu Sun's updates, fixed some lint errors #1770

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 7 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 .kokoro/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions 6 .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
sudo: false
language: python
python:
- "3.6"
services:
- memcached
- mysql
Expand Down Expand Up @@ -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"
14 changes: 7 additions & 7 deletions 14 appengine/standard_python37/django/mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
},
]

Expand Down
2 changes: 1 addition & 1 deletion 2 appengine/standard_python37/django/polls/admin.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion 2 appengine/standard_python37/django/polls/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion 2 appengine/standard_python37/django/polls/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase
from django.test import TestCase # noqa: 401

# Create your tests here.
9 changes: 6 additions & 3 deletions 9 appengine/standard_python37/django/polls/views.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand All @@ -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,))
)
1 change: 1 addition & 0 deletions 1 bigtable/hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 2 ml_engine/online_prediction/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 31 additions & 21 deletions 52 nox.py → noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[:]
Expand Down Expand Up @@ -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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ignore list is applied to all the samples, but I don't think it's right.
We'll remove them in #3727
@engelke FYI

]


# 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/')]
Expand All @@ -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)))

Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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')

Expand All @@ -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))
Expand All @@ -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')

Expand All @@ -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
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.