~click-hackers/click/trunk

« back to all changes in this revision

Viewing changes to click/tests/__init__.py

  • Committer: Colin Watson
  • Date: 2014-03-03 17:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 354.
  • Revision ID: cjwatson@canonical.com-20140303170137-4gs1zjmqtgkvzphq
Move an initial core of functionality (database, hooks, osextras, query,
user) from Python into a new "libclick" library, allowing
performance-critical clients to avoid the cost of starting a new Python
interpreter (LP: #1282311).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import print_function
 
2
 
 
3
import os
 
4
import sys
 
5
 
 
6
from click.tests import config
 
7
 
 
8
 
 
9
def _append_env_path(envname, value):
 
10
    if envname in os.environ:
 
11
        if value in os.environ[envname].split(":"):
 
12
            return False
 
13
        os.environ[envname] = "%s:%s" % (os.environ[envname], value)
 
14
    else:
 
15
        os.environ[envname] = value
 
16
    return True
 
17
 
 
18
 
 
19
# Don't do any of this in interactive mode.
 
20
if not hasattr(sys, "ps1"):
 
21
    _lib_click_dir = os.path.join(config.abs_top_builddir, "lib", "click")
 
22
    changed = False
 
23
    if _append_env_path(
 
24
            "LD_LIBRARY_PATH", os.path.join(_lib_click_dir, ".libs")):
 
25
        changed = True
 
26
    if _append_env_path("GI_TYPELIB_PATH", _lib_click_dir):
 
27
        changed = True
 
28
    if changed:
 
29
        # We have to re-exec ourselves to get the dynamic loader to pick up
 
30
        # the new value of LD_LIBRARY_PATH.
 
31
        if "-m unittest" in sys.argv[0]:
 
32
            # unittest does horrible things to sys.argv in the name of
 
33
            # "usefulness", making the re-exec more painful than it needs to
 
34
            # be.
 
35
            os.execvp(
 
36
                sys.executable, [sys.executable, "-m", "unittest"] + sys.argv[1:])
 
37
        else:
 
38
            os.execvp(sys.executable, [sys.executable] + sys.argv)
 
39
        os._exit(1)