~osomon/pyexiv2/pyexiv2-0.3

6 by Olivier Tilloy
Split the Sconstruct script into two files.
1
# -*- coding: utf-8 -*-
2
301 by Olivier Tilloy
Do not require PYTHONPATH manipulations to build the doc.
3
import os
4
import sys
5
301.1.4 by Olivier Tilloy
Isolate the PYTHONPATH fiddling in a separate function,
6
def _fiddle_with_pythonpath():
7
    # Fiddle with the pythonpath to allow builders to locate pyexiv2
8
    # (see https://bugs.launchpad.net/pyexiv2/+bug/549398).
9
    curdir = os.path.abspath(os.curdir)
10
    sys.path.insert(0, os.path.join(curdir, 'build'))
11
    sys.path.insert(0, os.path.join(curdir, 'src'))
12
268.1.21 by Olivier Tilloy
Dispatch build targets.
13
def build_lib():
281.1.3 by Olivier Tilloy
Do not add the --user switch for Python < 2.6.
14
    try:
15
        from site import USER_SITE
16
    except ImportError:
17
        # Installing in the user site directory requires Python ≥ 2.6.
18
        pass
19
    else:
281.1.4 by Olivier Tilloy
Help text for the --user switch.
20
        AddOption('--user', action='store_true',
21
                  help='Install in the user site directory.')
268.1.21 by Olivier Tilloy
Dispatch build targets.
22
    SConscript('src/SConscript', variant_dir='build', duplicate=0)
23
24
def build_doc():
301.1.4 by Olivier Tilloy
Isolate the PYTHONPATH fiddling in a separate function,
25
    _fiddle_with_pythonpath()
268.1.21 by Olivier Tilloy
Dispatch build targets.
26
    SConscript('doc/SConscript')
27
301.1.3 by Olivier Tilloy
Add a scons target to run the unit tests.
28
def run_tests():
301.1.4 by Olivier Tilloy
Isolate the PYTHONPATH fiddling in a separate function,
29
    _fiddle_with_pythonpath()
301.1.7 by Olivier Tilloy
The test scons target is now aware of the result of running the test suite.
30
    SConscript('test/SConscript')
301.1.3 by Olivier Tilloy
Add a scons target to run the unit tests.
31
361.1.1 by Olivier Tilloy
Check that Python ≥ 2.6 in the build script.
32
if sys.version_info < (2, 6):
33
    sys.exit('ERROR: pyexiv2 requires Python ≥ 2.6. Exiting.')
34
268.1.21 by Olivier Tilloy
Dispatch build targets.
35
if not BUILD_TARGETS:
36
    # Default target: lib
37
    build_lib()
38
else:
268.1.22 by Olivier Tilloy
Resolve the install target.
39
    if 'lib' in BUILD_TARGETS or 'install' in BUILD_TARGETS:
268.1.21 by Olivier Tilloy
Dispatch build targets.
40
        build_lib()
41
    if 'doc' in BUILD_TARGETS:
302 by Olivier Tilloy
Updated a comment: building the doc doesn't require fiddling with the PYTHONPATH anymore.
42
        # Note: building the doc requires the lib to be built.
268.1.21 by Olivier Tilloy
Dispatch build targets.
43
        build_doc()
301.1.3 by Olivier Tilloy
Add a scons target to run the unit tests.
44
    if 'test' in BUILD_TARGETS:
301.1.7 by Olivier Tilloy
The test scons target is now aware of the result of running the test suite.
45
        # Note: running the unit tests requires the lib to be built.
301.1.3 by Olivier Tilloy
Add a scons target to run the unit tests.
46
        run_tests()
268.1.21 by Olivier Tilloy
Dispatch build targets.
47