Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 2dad98c

Browse files
committed
Merge pull request #7 from andrewsg/config
rename appengine_config to env_config as the name conflicts with appengi...
2 parents 29b3532 + bf00dda commit 2dad98c

3 files changed

Lines changed: 35 additions & 35 deletions

File tree

multicore_runtime/middleware.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636
def reset_environment_middleware(app, frozen_environment, frozen_user_env,
37-
frozen_appengine_config_env):
37+
frozen_env_config_env):
3838
"""Replace the contents of os.environ with a frozen env + request data.
3939
4040
This requires a single-threaded webserver, or for os.environ to be patched to
@@ -47,7 +47,7 @@ def reset_environment_middleware(app, frozen_environment, frozen_user_env,
4747
`tuple(os.environ.iteritems())` produces appropriate output.
4848
frozen_user_env: An iterable of (key, value) tuples that can be used to
4949
populate os.environ with environment variables specified in app.yaml.
50-
frozen_appengine_config_env: An iterable of (key, value) tuples that can be
50+
frozen_env_config_env: An iterable of (key, value) tuples that can be
5151
used to populate os.environ with configuration-dependent env variables.
5252
5353
Returns:
@@ -71,8 +71,8 @@ def reset_environment_wrapper(wsgi_env, start_response): # pylint: disable=miss
7171
# Add in wsgi_env data, including request headers.
7272
os.environ.update(request_environment_for_wsgi_env(wsgi_env))
7373

74-
# Add in configuration data from appengine_config.
75-
os.environ.update(frozen_appengine_config_env)
74+
# Add in configuration data from env_config.
75+
os.environ.update(frozen_env_config_env)
7676

7777
# Add reserved keys, which draw from wsgi_env as well. These have a very
7878
# high priority and so are added nearly last.

multicore_runtime/wsgi.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@
2525

2626
from dispatcher import dispatcher
2727
from middleware import reset_environment_middleware
28-
from wsgi_config import env_vars_from_appengine_config
28+
from wsgi_config import env_vars_from_env_config
2929
from wsgi_config import get_module_config
3030
from wsgi_config import get_module_config_filename
3131
from wsgi_config import load_user_scripts_into_handlers
3232
from wsgi_config import ThreadLocalDict
33-
from wsgi_config import user_env_vars_from_appinfo_external
33+
from wsgi_config import user_env_vars_from_appinfo
3434

3535
from google.appengine.ext.vmruntime import vmconfig
3636
from google.appengine.ext.vmruntime import vmstub
3737

3838
logging.basicConfig(level=logging.INFO)
3939

40-
appinfo_external = get_module_config(get_module_config_filename())
41-
appengine_config = vmconfig.BuildVmAppengineEnvConfig()
40+
appinfo = get_module_config(get_module_config_filename())
41+
env_config = vmconfig.BuildVmAppengineEnvConfig()
4242

4343
# Ensure API requests include a valid ticket by default.
44-
vmstub.Register(vmstub.VMStub(appengine_config.default_ticket))
44+
vmstub.Register(vmstub.VMStub(env_config.default_ticket))
4545

4646
# Load user code.
47-
preloaded_handlers = load_user_scripts_into_handlers(appinfo_external.handlers)
47+
preloaded_handlers = load_user_scripts_into_handlers(appinfo.handlers)
4848

4949
# Now that all scripts are fully imported, it is safe to use asynchronous
5050
# API calls.
@@ -57,16 +57,16 @@
5757
frozen_environment = tuple(os.environ.iteritems())
5858

5959
# Also freeze user env vars specified in app.yaml. Later steps to modify the
60-
# environment such as env_vars_from_appengine_config and request middleware
60+
# environment such as env_vars_from_env_config and request middleware
6161
# will overwrite these changes. This is added to the environment in
6262
# `reset_environment_middleware`.
6363
frozen_user_env = tuple(
64-
user_env_vars_from_appinfo_external(appinfo_external).iteritems())
64+
user_env_vars_from_appinfo(appinfo).iteritems())
6565

66-
# Also freeze environment data from appengine_config. This is added to the
66+
# Also freeze environment data from env_config. This is added to the
6767
# environment in `reset_environment_middleware`.
68-
frozen_appengine_config_env = tuple(
69-
env_vars_from_appengine_config(appengine_config).iteritems())
68+
frozen_env_config_env = tuple(
69+
env_vars_from_env_config(env_config).iteritems())
7070

7171
# Monkey-patch os.environ to be thread-local. This is for backwards
7272
# compatibility with GAE's use of environment variables to store request data.
@@ -86,4 +86,4 @@
8686
# Reset os.environ to the frozen state and add request-specific data.
8787
meta_app = reset_environment_middleware(meta_app, frozen_environment,
8888
frozen_user_env,
89-
frozen_appengine_config_env)
89+
frozen_env_config_env)

multicore_runtime/wsgi_config.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ def app_wrapped_in_user_middleware(app):
6060
def get_add_middleware_from_appengine_config():
6161
"""Tries to import appengine_config and return middleware; fails silently.
6262
63-
`appengine_config` is optionally part of GAE-compatible user code.
63+
`env_config` is optionally part of GAE-compatible user code.
6464
If the user chooses to define the `webapp_add_wsgi_middleware` function
6565
there, then we will use it to wrap app scripts. This is used for e.g.
66-
appstats. Many user apps do not have or need appengine_config, so failure
66+
appstats. Many user apps do not have or need env_config, so failure
6767
to import it or failure to find `webapp_add_wsgi_middleware` is not an
6868
error.
6969
@@ -81,7 +81,7 @@ def get_add_middleware_from_appengine_config():
8181

8282

8383
def load_user_scripts_into_handlers(handlers):
84-
"""Preloads user scripts, wrapped in appengine_config middleware if present.
84+
"""Preloads user scripts, wrapped in env_config middleware if present.
8585
8686
Args:
8787
handlers: appinfo_external.handlers data as provided by get_module_config()
@@ -103,45 +103,45 @@ def load_user_scripts_into_handlers(handlers):
103103
return loaded_handlers
104104

105105

106-
def env_vars_from_appengine_config(appengine_config):
106+
def env_vars_from_env_config(env_config):
107107
"""Generate a dict suitable for updating os.environ to reflect app config.
108108
109109
This function only returns a dict and does not update os.environ directly.
110110
111111
Args:
112-
appengine_config: The app configuration as generated by
113-
vmconfig.BuildVmAppengineEnvConfig()
112+
env_config: The app configuration as generated by
113+
vmconfig.BuildVmAppengineEnvConfig()
114114
115115
Returns:
116116
A dict of strings suitable for e.g. `os.environ.update(values)`.
117117
"""
118118

119-
return {'SERVER_SOFTWARE': appengine_config.server_software,
119+
return {'SERVER_SOFTWARE': env_config.server_software,
120120
'APPENGINE_RUNTIME': 'python27',
121-
'APPLICATION_ID': '%s~%s' % (appengine_config.partition,
122-
appengine_config.appid),
123-
'INSTANCE_ID': appengine_config.instance,
124-
'BACKEND_ID': appengine_config.major_version,
125-
'CURRENT_MODULE_ID': appengine_config.module,
126-
'CURRENT_VERSION_ID': '%s.%s' % (appengine_config.major_version,
127-
appengine_config.minor_version),
128-
'DEFAULT_TICKET': appengine_config.default_ticket}
121+
'APPLICATION_ID': '%s~%s' % (env_config.partition,
122+
env_config.appid),
123+
'INSTANCE_ID': env_config.instance,
124+
'BACKEND_ID': env_config.major_version,
125+
'CURRENT_MODULE_ID': env_config.module,
126+
'CURRENT_VERSION_ID': '%s.%s' % (env_config.major_version,
127+
env_config.minor_version),
128+
'DEFAULT_TICKET': env_config.default_ticket}
129129

130130

131-
def user_env_vars_from_appinfo_external(appinfo_external):
131+
def user_env_vars_from_appinfo(appinfo):
132132
"""Generate a dict of env variables specified by the user in app.yaml.
133133
134134
This function only returns a dict and does not update os.environ directly.
135135
136136
Args:
137-
appinfo_external: The app.yaml configuration info as generated by
138-
get_module_config()
137+
appinfo: The configuration info (a parsed yaml object) as generated by
138+
get_module_config()
139139
140140
Returns:
141141
A dict of strings suitable for e.g. `os.environ.update(values)`.
142142
"""
143143

144-
return appinfo_external.env_variables or {}
144+
return appinfo.env_variables or {}
145145

146146

147147
# Dictionary with thread-local contents.

0 commit comments

Comments
 (0)