Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bdbaddog
Created February 23, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdbaddog/1ddedecdfd13f6193c173e511e895b1f to your computer and use it in GitHub Desktop.
Save bdbaddog/1ddedecdfd13f6193c173e511e895b1f to your computer and use it in GitHub Desktop.
How to add to SConscript namespace
env=Environment()
SConscript('src/SConscript',exports='env')
import SCons.Script
def my_stuff():
print("BLAH")
SCons.Script.my_stuff = my_stuff
Import('env')
my_stuff()
@dragon512
Copy link

dragon512 commented Feb 24, 2018

right...

I was thinking that I would have a functions like:

site_scons site_init.py ( in a system directory)

import SCons.Script

def EnablePartsExtension():
    import parts
    globals().update(parts.glb.globals)
    # I would probably refactor more into something like
    import parts    
    parts.load() 

SCons.Script.my_stuff = EnablePartsExtension

The only problem with this is that the logic in SCons, if I read it correctly, will load the first site_init.py. So the code would break if the user added there own site_init.py in the directory with the Sconstruct.

@bdbaddog
Copy link
Author

I wonder if:

import SCons.Script
import parts

parts.setup_stuff(SCons.Script)

Would do what you want.. Then you'd add all the symbols you want available as attributes to the passed object.

@dragon512
Copy link

Yes that would work, but the user will have little control in being able to selection parts being added or not add to there build when using SCons. The suggestion I made means the user can add it or remove it at the point the Sconstruct is read in.

Ideally having a SCons extension API to allow control over what extensions get loaded or not would probably be better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment