File indexing completed on 2024-04-14 15:48:37

0001 # -*- coding: UTF-8 -*-
0002 
0003 """
0004 Insert fallback import paths in scripts.
0005 
0006 In case the C{PYTHONPATH} environment variable does not contain path
0007 to Pology library modules needed by scripts, this module will append
0008 all guesses for Pology library paths to system path.
0009 The assumption is that scripts themselves are in their default location
0010 in Pology source tree.
0011 
0012 Import this module before any imports from Pology library, in each script
0013 in this directory that depends on Pology library::
0014 
0015     try:
0016         import fallback_import_paths
0017     except:
0018         pass
0019 
0020     from pology.foo import bar
0021     from pology.qwyx import baz
0022     ...
0023 
0024 The try-except wrapper is needed because when scripts are properly installed,
0025 this module will not be available (nor needed).
0026 
0027 @author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>
0028 @license: GPLv3
0029 """
0030 
0031 import sys
0032 from os.path import realpath, sep, dirname
0033 
0034 pologypath = sep.join(realpath(sys.argv[0]).split(sep)[:-2])
0035 sys.path.insert(0, pologypath)