[Scons-users] Build, install and use python modules from scons

Bill Deegan bill at baddogconsulting.com
Mon Oct 17 17:35:27 EDT 2016


Bobby,

Wow the formatting of your copy/pasted code got pretty munged.

Any chance you can pastebin them, and share them via those URLs?

env['ENV']['PYTHONPATH'] is propagated to all commands run in that
Environment().
So if you used env.Command() instead if Command(), that might work.

It's hard to tell what install_python_modules is doing without included the
sources..
Can you pastebin that as well?

-Bill

On Mon, Oct 17, 2016 at 2:26 PM, Bobby Casey <beecee808 at gmail.com> wrote:

> Hello,
>
> I'm running into an issue with setting environment variables for
> actions.  Essentially what I'm
> trying to do is install some python modules in my build directory and
> set PYTHONPATH for any python
> scripts that are getting executed, but I can't find a good way.  I put
> an example setup below:
>
> ./SConstruct ./module-test.scons ./module_test.py
> ./extern/module_a/setup.py
> ./extern/module_a/module_a/__init__.py ./extern/module_b/setup.py
> ./extern/module_b/module_b/__init__.py
>
> I should note that all directories under `extern' are pulled in from
> an external repository.  We
> need to build/use those in order to properly build our application.
>
> module-test.scons looks like this:
>
> ```
> env = Environment() env['PYLIBSDIR'] = env.Dir('pylibs') def
> install_python_module(mdir, mname):
> source = env.Dir(mdir).srcnode() target = '%s/%s' % (env['PYLIBSDIR'],
> mname) lib = Command(target,
> source, [Delete('${TARGET.abspath}'), 'PYTHONPATH=%s python setup.py
> build_py -d build' %
> env['PYLIBSDIR'].abspath, Mkdir(env['PYLIBSDIR']),
> Copy('${TARGET.abspath}', mname)], chdir=source)
> return lib
>
> modules = install_python_module('module_a', 'module_a') modules +=
> install_python_module('module_b',
> 'module_b')
>
> module_test_file = env.File('module_test.py') test_out =
> Command(target='test.out',
> source='test.in', action='PYTHONPATH=%s %s < $SOURCE > $TARGET' %
> (env['PYLIBSDIR'].path,
> module_test_file.path))
>
> env.Depends(module_test_file, modules) env.Depends(test_out,
> module_test_file)
> ```
>
> module_test.py will attempt to import module_a and module_b.  What I
> want to do is build module_a
> and module_b (using `python setup.py build_py') and install them as
> modules in the `pylibs'
> directory, where it can be used by other scripts. I then need to run
> my other script
> (module_test.py) with PYTHONPATH set properly to find these modules.
> I'm presently doing this by
> explicitly setting PYTHONPATH as part of my action, which feels really
> clumsy and error prone.  Is
> there a better way to do this?
>
> To recap, I think these are my two core questions:
>
> 1. My method of installing libraries (the install_python_modules
> function above) feels wrong.  Is
> there a better way?
>
> 2. Is there a better way to pass environment variables down to called
> applications?  Putting
> PYTHONPATH on the command line is probably non-portable and feels like
> one big hack.
>
> Thanks,
>   Bobby
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20161017/d80f579a/attachment.html>


More information about the Scons-users mailing list