forked from oppia/oppia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappengine_config.py
55 lines (48 loc) · 2.4 KB
/
appengine_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright 2014 The Oppia Authors. 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.
"""Configuration for App Engine."""
from __future__ import absolute_import # pylint: disable=import-only-modules
from __future__ import unicode_literals # pylint: disable=import-only-modules
import os
import sys
from google.appengine.ext import vendor
# Root path of the app.
ROOT_PATH = os.path.dirname(__file__)
THIRD_PARTY_PATH = os.path.join(ROOT_PATH, 'third_party')
_PARENT_DIR = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
OPPIA_TOOLS_PATH = os.path.join(_PARENT_DIR, 'oppia_tools')
# oppia_tools/ is available locally (in both dev and prod mode). However,
# on the GAE production server, oppia_tools/ is not available, and the default
# PIL third-party library is used instead.
#
# We cannot special-case this using DEV_MODE because it is possible to run
# Oppia in production mode locally, where a built-in PIL won't be available.
# Hence the check for oppia_tools instead.
if os.path.isdir(OPPIA_TOOLS_PATH):
PIL_PATH = os.path.join(
OPPIA_TOOLS_PATH, 'Pillow-6.2.2')
if not os.path.isdir(PIL_PATH):
raise Exception('Invalid path for oppia_tools library: %s' % PIL_PATH)
sys.path.insert(0, PIL_PATH)
PROTOBUF_PATH = os.path.join(OPPIA_TOOLS_PATH, 'protobuf-3.12.0')
if not os.path.isdir(PROTOBUF_PATH):
raise Exception('Invalid path for oppia_tools library: %s' % (
PROTOBUF_PATH))
sys.path.insert(0, PROTOBUF_PATH)
# Google App Engine (GAE) uses its own virtual environment that sets up the
# python library system path using their third party python library, vendor. In
# order to inform GAE of the packages that are required for Oppia, we need to
# add it using the vendor library. More information can be found here:
# https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27
vendor.add(os.path.join(THIRD_PARTY_PATH, 'python_libs'))