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
|
#! /usr/bin/env python
from __future__ import print_function
import os
import sys
PATHS = [
'.',
'src',
'lib', # dependencies
]
# temporary solution top support current dev dev.
# TODO: remove when we are fully juju based
APPEND_PATHS = ['../local_config']
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
PROJECT_ROOT_DIR = os.path.abspath(os.path.join(CURRENT_DIR, os.pardir))
def get_paths(paths):
"""Sets up necessary python paths for sso in prod/staging"""
# only include a path if not already in sys.path to avoid duplication of
# paths when using code reloading
path_set = set(sys.path)
for p in paths:
path = os.path.abspath(os.path.join(PROJECT_ROOT_DIR, p))
if path not in path_set:
yield path
def setup_paths():
sys.path = list(get_paths(PATHS)) + sys.path + APPEND_PATHS
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
if __name__ == '__main__':
# For use in shell scripting
# e.g. $(python paths.py)
print("export PYTHONPATH=%s" % ":".join(get_paths(PATHS)))
print("export DJANGO_SETTINGS_MODULE=settings")
|