Skip to content

Commit 9b7c9ac

Browse files
holtskinnerkweinmeistergcf-owl-bot[bot]
authored
chore: Ran nox -s blacken on samples (GoogleCloudPlatform#10231)
* fix: Update appengine standard noxfile_config.py to fix syntax error * chore: Ran `nox -s blacken` * Adjust lint ignore for cloudiot sample * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Karl Weinmeister <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent e86dcc5 commit 9b7c9ac

File tree

1,201 files changed

+30642
-27996
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,201 files changed

+30642
-27996
lines changed

appengine/flexible/analytics/main.py

+24-22
Original file line numberDiff line numberDiff line change
@@ -24,52 +24,54 @@
2424

2525

2626
# Environment variables are defined in app.yaml.
27-
GA_TRACKING_ID = os.environ['GA_TRACKING_ID']
27+
GA_TRACKING_ID = os.environ["GA_TRACKING_ID"]
2828

2929

3030
def track_event(category, action, label=None, value=0):
3131
data = {
32-
'v': '1', # API Version.
33-
'tid': GA_TRACKING_ID, # Tracking ID / Property ID.
32+
"v": "1", # API Version.
33+
"tid": GA_TRACKING_ID, # Tracking ID / Property ID.
3434
# Anonymous Client Identifier. Ideally, this should be a UUID that
3535
# is associated with particular user, device, or browser instance.
36-
'cid': '555',
37-
't': 'event', # Event hit type.
38-
'ec': category, # Event category.
39-
'ea': action, # Event action.
40-
'el': label, # Event label.
41-
'ev': value, # Event value, must be an integer
42-
'ua': 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14'
36+
"cid": "555",
37+
"t": "event", # Event hit type.
38+
"ec": category, # Event category.
39+
"ea": action, # Event action.
40+
"el": label, # Event label.
41+
"ev": value, # Event value, must be an integer
42+
"ua": "Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14",
4343
}
4444

45-
response = requests.post(
46-
'https://www.google-analytics.com/collect', data=data)
45+
response = requests.post("https://www.google-analytics.com/collect", data=data)
4746

4847
# If the request fails, this will raise a RequestException. Depending
4948
# on your application's needs, this may be a non-error and can be caught
5049
# by the caller.
5150
response.raise_for_status()
5251

5352

54-
@app.route('/')
53+
@app.route("/")
5554
def track_example():
56-
track_event(
57-
category='Example',
58-
action='test action')
59-
return 'Event tracked.'
55+
track_event(category="Example", action="test action")
56+
return "Event tracked."
6057

6158

6259
@app.errorhandler(500)
6360
def server_error(e):
64-
logging.exception('An error occurred during a request.')
65-
return """
61+
logging.exception("An error occurred during a request.")
62+
return (
63+
"""
6664
An internal error occurred: <pre>{}</pre>
6765
See logs for full stacktrace.
68-
""".format(e), 500
66+
""".format(
67+
e
68+
),
69+
500,
70+
)
6971

7072

71-
if __name__ == '__main__':
73+
if __name__ == "__main__":
7274
# This is used when running locally. Gunicorn is used to run the
7375
# application on Google App Engine. See entrypoint in app.yaml.
74-
app.run(host='127.0.0.1', port=8080, debug=True)
76+
app.run(host="127.0.0.1", port=8080, debug=True)
7577
# [END gae_flex_analytics_track_event]

appengine/flexible/analytics/main_test.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
@pytest.fixture
2222
def app(monkeypatch):
23-
monkeypatch.setenv('GA_TRACKING_ID', '1234')
23+
monkeypatch.setenv("GA_TRACKING_ID", "1234")
2424

2525
import main
2626

@@ -31,17 +31,15 @@ def app(monkeypatch):
3131
@responses.activate
3232
def test_tracking(app):
3333
responses.add(
34-
responses.POST,
35-
re.compile(r'.*'),
36-
body='{}',
37-
content_type='application/json')
34+
responses.POST, re.compile(r".*"), body="{}", content_type="application/json"
35+
)
3836

39-
r = app.get('/')
37+
r = app.get("/")
4038

4139
assert r.status_code == 200
42-
assert 'Event tracked' in r.data.decode('utf-8')
40+
assert "Event tracked" in r.data.decode("utf-8")
4341

4442
assert len(responses.calls) == 1
4543
request_body = responses.calls[0].request.body
46-
assert 'tid=1234' in request_body
47-
assert 'ea=test+action' in request_body
44+
assert "tid=1234" in request_body
45+
assert "ea=test+action" in request_body

appengine/flexible/datastore/main.py

+26-17
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,59 @@ def is_ipv6(addr):
3333

3434

3535
# [START gae_flex_datastore_app]
36-
@app.route('/')
36+
@app.route("/")
3737
def index():
3838
ds = datastore.Client()
3939

4040
user_ip = request.remote_addr
4141

4242
# Keep only the first two octets of the IP address.
4343
if is_ipv6(user_ip):
44-
user_ip = ':'.join(user_ip.split(':')[:2])
44+
user_ip = ":".join(user_ip.split(":")[:2])
4545
else:
46-
user_ip = '.'.join(user_ip.split('.')[:2])
46+
user_ip = ".".join(user_ip.split(".")[:2])
4747

48-
entity = datastore.Entity(key=ds.key('visit'))
49-
entity.update({
50-
'user_ip': user_ip,
51-
'timestamp': datetime.datetime.now(tz=datetime.timezone.utc)
52-
})
48+
entity = datastore.Entity(key=ds.key("visit"))
49+
entity.update(
50+
{
51+
"user_ip": user_ip,
52+
"timestamp": datetime.datetime.now(tz=datetime.timezone.utc),
53+
}
54+
)
5355

5456
ds.put(entity)
55-
query = ds.query(kind='visit', order=('-timestamp',))
57+
query = ds.query(kind="visit", order=("-timestamp",))
5658

5759
results = []
5860
for x in query.fetch(limit=10):
5961
try:
60-
results.append('Time: {timestamp} Addr: {user_ip}'.format(**x))
62+
results.append("Time: {timestamp} Addr: {user_ip}".format(**x))
6163
except KeyError:
6264
print("Error with result format, skipping entry.")
6365

64-
output = 'Last 10 visits:\n{}'.format('\n'.join(results))
66+
output = "Last 10 visits:\n{}".format("\n".join(results))
67+
68+
return output, 200, {"Content-Type": "text/plain; charset=utf-8"}
69+
6570

66-
return output, 200, {'Content-Type': 'text/plain; charset=utf-8'}
6771
# [END gae_flex_datastore_app]
6872

6973

7074
@app.errorhandler(500)
7175
def server_error(e):
72-
logging.exception('An error occurred during a request.')
73-
return """
76+
logging.exception("An error occurred during a request.")
77+
return (
78+
"""
7479
An internal error occurred: <pre>{}</pre>
7580
See logs for full stacktrace.
76-
""".format(e), 500
81+
""".format(
82+
e
83+
),
84+
500,
85+
)
7786

7887

79-
if __name__ == '__main__':
88+
if __name__ == "__main__":
8089
# This is used when running locally. Gunicorn is used to run the
8190
# application on Google App Engine. See entrypoint in app.yaml.
82-
app.run(host='127.0.0.1', port=8080, debug=True)
91+
app.run(host="127.0.0.1", port=8080, debug=True)

appengine/flexible/datastore/main_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ def test_index():
1919
main.app.testing = True
2020
client = main.app.test_client()
2121

22-
r = client.get('/', environ_base={'REMOTE_ADDR': '127.0.0.1'})
22+
r = client.get("/", environ_base={"REMOTE_ADDR": "127.0.0.1"})
2323
assert r.status_code == 200
24-
assert 'Last 10 visits' in r.data.decode('utf-8')
24+
assert "Last 10 visits" in r.data.decode("utf-8")

appengine/flexible/disk/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def index():
6969

7070
output = f"Instance: {instance_id}\nSeen:{seen}"
7171
return output, 200, {"Content-Type": "text/plain; charset=utf-8"}
72+
73+
7274
# [END example]
7375

7476

appengine/flexible/django_cloudsql/noxfile_config.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,14 @@
2222

2323
TEST_CONFIG_OVERRIDE = {
2424
# You can opt out from the test for specific Python versions.
25-
'ignored_versions': ["2.7"],
26-
25+
"ignored_versions": ["2.7"],
2726
# An envvar key for determining the project id to use. Change it
2827
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
2928
# build specific Cloud project. You can also use your own string
3029
# to use your own Cloud project.
31-
'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
30+
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
3231
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
33-
3432
# A dictionary you want to inject into your test. Don't put any
3533
# secrets here. These values will override predefined values.
36-
'envs': {
37-
'DJANGO_SETTINGS_MODULE': 'mysite.settings'
38-
},
34+
"envs": {"DJANGO_SETTINGS_MODULE": "mysite.settings"},
3935
}

appengine/flexible/django_cloudsql/polls/apps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717

1818
class PollsConfig(AppConfig):
19-
name = 'polls'
19+
name = "polls"

appengine/flexible/django_cloudsql/polls/models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
class Question(models.Model):
1919
question_text = models.CharField(max_length=200)
20-
pub_date = models.DateTimeField('date published')
20+
pub_date = models.DateTimeField("date published")
2121

2222

2323
class Choice(models.Model):
2424
question = models.ForeignKey(Question, on_delete=models.CASCADE)
2525
choice_text = models.CharField(max_length=200)
2626
votes = models.IntegerField(default=0)
2727

28+
2829
# Create your models here.

appengine/flexible/django_cloudsql/polls/test_polls.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
class PollViewTests(TestCase):
1919
def test_index_view(self):
20-
response = self.client.get('/')
20+
response = self.client.get("/")
2121
assert response.status_code == 200
22-
assert 'Hello, world' in str(response.content)
22+
assert "Hello, world" in str(response.content)

appengine/flexible/django_cloudsql/polls/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
from . import views
1818

1919
urlpatterns = [
20-
re_path(r'^$', views.index, name='index'),
20+
re_path(r"^$", views.index, name="index"),
2121
]

appengine/flexible/extending_runtime/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def fortune():
3232
"""
3333
output = subprocess.check_output("/usr/games/fortune")
3434
return output, 200, {"Content-Type": "text/plain; charset=utf-8"}
35+
36+
3537
# [END example]
3638

3739

appengine/flexible/hello_world_django/helloworld/views.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818

1919

2020
def index(request):
21-
return HttpResponse(
22-
'Hello, World. This is Django running on Google App Engine')
21+
return HttpResponse("Hello, World. This is Django running on Google App Engine")

appengine/flexible/hello_world_django/project_name/settings.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
3535

3636
# SECURITY WARNING: keep the secret key used in production secret!
37-
SECRET_KEY = 'qgw!j*bpxo7g&o1ux-(2ph818ojfj(3c#-#*_8r^8&hq5jg$3@'
37+
SECRET_KEY = "qgw!j*bpxo7g&o1ux-(2ph818ojfj(3c#-#*_8r^8&hq5jg$3@"
3838

3939
# SECURITY WARNING: don't run with debug turned on in production!
4040
DEBUG = True
@@ -45,63 +45,63 @@
4545
# Application definition
4646

4747
INSTALLED_APPS = (
48-
'django.contrib.admin',
49-
'django.contrib.auth',
50-
'django.contrib.contenttypes',
51-
'django.contrib.sessions',
52-
'django.contrib.messages',
53-
'django.contrib.staticfiles',
54-
'helloworld'
48+
"django.contrib.admin",
49+
"django.contrib.auth",
50+
"django.contrib.contenttypes",
51+
"django.contrib.sessions",
52+
"django.contrib.messages",
53+
"django.contrib.staticfiles",
54+
"helloworld",
5555
)
5656

5757
MIDDLEWARE = (
58-
'django.middleware.security.SecurityMiddleware',
59-
'django.contrib.sessions.middleware.SessionMiddleware',
60-
'django.middleware.common.CommonMiddleware',
61-
'django.middleware.csrf.CsrfViewMiddleware',
62-
'django.contrib.auth.middleware.AuthenticationMiddleware',
63-
'django.contrib.messages.middleware.MessageMiddleware',
64-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
58+
"django.middleware.security.SecurityMiddleware",
59+
"django.contrib.sessions.middleware.SessionMiddleware",
60+
"django.middleware.common.CommonMiddleware",
61+
"django.middleware.csrf.CsrfViewMiddleware",
62+
"django.contrib.auth.middleware.AuthenticationMiddleware",
63+
"django.contrib.messages.middleware.MessageMiddleware",
64+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
6565
)
6666

67-
ROOT_URLCONF = 'project_name.urls'
67+
ROOT_URLCONF = "project_name.urls"
6868

6969
TEMPLATES = [
7070
{
71-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
72-
'DIRS': [],
73-
'APP_DIRS': True,
74-
'OPTIONS': {
75-
'context_processors': [
76-
'django.template.context_processors.debug',
77-
'django.template.context_processors.request',
78-
'django.contrib.auth.context_processors.auth',
79-
'django.contrib.messages.context_processors.messages',
71+
"BACKEND": "django.template.backends.django.DjangoTemplates",
72+
"DIRS": [],
73+
"APP_DIRS": True,
74+
"OPTIONS": {
75+
"context_processors": [
76+
"django.template.context_processors.debug",
77+
"django.template.context_processors.request",
78+
"django.contrib.auth.context_processors.auth",
79+
"django.contrib.messages.context_processors.messages",
8080
],
8181
},
8282
},
8383
]
8484

85-
WSGI_APPLICATION = 'project_name.wsgi.application'
85+
WSGI_APPLICATION = "project_name.wsgi.application"
8686

8787

8888
# Database
8989
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
9090

9191
DATABASES = {
92-
'default': {
93-
'ENGINE': 'django.db.backends.sqlite3',
94-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
92+
"default": {
93+
"ENGINE": "django.db.backends.sqlite3",
94+
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
9595
}
9696
}
9797

9898

9999
# Internationalization
100100
# https://docs.djangoproject.com/en/1.8/topics/i18n/
101101

102-
LANGUAGE_CODE = 'en-us'
102+
LANGUAGE_CODE = "en-us"
103103

104-
TIME_ZONE = 'UTC'
104+
TIME_ZONE = "UTC"
105105

106106
USE_I18N = True
107107

@@ -113,4 +113,4 @@
113113
# Static files (CSS, JavaScript, Images)
114114
# https://docs.djangoproject.com/en/1.8/howto/static-files/
115115

116-
STATIC_URL = '/static/'
116+
STATIC_URL = "/static/"

appengine/flexible/hello_world_django/project_name/urls.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434

3535

3636
urlpatterns = [
37-
url(r'^admin/', include(admin.site.urls)),
38-
url(r'^$', helloworld.views.index),
37+
url(r"^admin/", include(admin.site.urls)),
38+
url(r"^$", helloworld.views.index),
3939
]

0 commit comments

Comments
 (0)