SCons: How do I import a Python module into SConscript that was called with VariantDir?

My assembly is structured like this:

SConstruct
subdir/SConscript
subdir/module/__init__.py

      

SConstruct

calls subdir/SConscript

as a child:

# SConstruct
SConscript('subdir/SConscript')

      

subdir/SConscript

import module

:

# subdir/SConscript
from module import foo
do SConsy stuff with foo()...

      

This works great until I use it variant_dir

with subdir/SConscript

:

# SConstruct
SConscript('subdir/SConscript', variant_dir='subdir/build', duplicate=0)

      

The problem is what import

is failing because it is module

no longer in the path that was changed to variant_dir

.

Is there a standard way to solve this problem in SCons or Python? I am aware of a special directory site_scons

, but it seems that this directory must exist at the top level with the root SConstruct

and I would like to store the subdir

-special files in subdir

.

+3


source to share


3 answers


Use site_scons dir in the project root for your module. For example, I have xxx module, and it is placed: root/site_scons/xxx/__init__.py

. I can now import xxx into all my SConscript files.



+3


source


In SConscript

front, import

change the Python path:



# subdir/SConscript
module_path = Dir('.').srcnode().abspath # get the path to subdir
import sys
sys.path.append(module_path)
from module import foo

      

+1


source


export PYTHONPATH = / path / to / dir_of_modules

This worked for me

0


source







All Articles