From 8565a19fc276bcbc2d2a88577260871e8a8bbb61 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 1 Sep 2012 22:26:28 -0400 Subject: [PATCH] Add a customizable import config file. --- .gitignore | 10 ++++++++-- build.py | 13 +++++-------- toolserver/preconfig.py.ts | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 toolserver/preconfig.py.ts diff --git a/.gitignore b/.gitignore index 9d0e2f5..c302491 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,11 @@ *.pyc -temp/ -www/ +*.egg +*.egg-info +.DS_Store +__pycache__ + +temp +www .earwigbot rewrite.script +toolserver/preconfig.py diff --git a/build.py b/build.py index e293c7e..a6d2d86 100755 --- a/build.py +++ b/build.py @@ -9,19 +9,16 @@ import subprocess page_src = """#! /usr/bin/env python # -*- coding: utf-8 -*- import os -import site import sys os.chdir("..") -plat = sys.platform -if plat.startswith("sunos"): - plat = "solaris" -elif plat.startswith("linux"): - plat = "linux" -site.addsitedir(os.path.expanduser("~/.local/" + plat + "/lib/python2.7/site-packages")) -sys.path.insert(0, os.path.expanduser("~/.local/" + plat + "/lib/python2.7/site-packages")) sys.path.insert(0, ".") +try: + from toolserver import preconfig +except ImportError: + pass + from mako.template import Template from mako.lookup import TemplateLookup diff --git a/toolserver/preconfig.py.ts b/toolserver/preconfig.py.ts new file mode 100644 index 0000000..f94d47b --- /dev/null +++ b/toolserver/preconfig.py.ts @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +""" +This module contains installation-specific import configuration for the +Toolserver. To add your own, create and put code in the file 'preconfig.py' in +this directory, or rename this file to 'preconfig.py' if you want to use this +specific configuration. +""" + +import os +import site +import sys + +# Add a local platform-specific site package directory: + +plat = sys.platform +if plat.startswith("sunos"): + plat = "solaris" +elif plat.startswith("linux"): + plat = "linux" + +site.addsitedir(os.path.expanduser("~/.local/" + plat + "/lib/python2.7/site-packages")) +sys.path.insert(0, os.path.expanduser("~/.local/" + plat + "/lib/python2.7/site-packages")) + +# EarwigBot, in-between releases, tries to import the 'git' module and add the +# current git commit ID to its __version__ string. This behavior is useful, but +# the Toolserver can be slow at importing things. Insert a fake 'git' module +# into sys.modules so it skips the __version__ addition: + +from types import ModuleType +git = ModuleType("git") +sys.modules["git"] = git