parameters: (topdir, site_dir_name=None)
docstring: Load the site directory under topdir.
  
      If a site dir name is supplied use it, else use default "site_scons"
      Prepend site dir to sys.path.
      If a "site_tools" subdir exists, prepend to toolpath.
      Import "site_init.py" from site dir if it exists.
docstring_summary: Load the site directory under topdir.
docstring_tokens: Load the site directory under topdir .
function: def _load_site_scons_dir(topdir, site_dir_name=None):
      """Load the site directory under topdir.
  
      If a site dir name is supplied use it, else use default "site_scons"
      Prepend site dir to sys.path.
      If a "site_tools" subdir exists, prepend to toolpath.
      Import "site_init.py" from site dir if it exists.
      """
      if site_dir_name:
          err_if_not_found = True       # user specified: err if missing
      else:
          site_dir_name = "site_scons"
          err_if_not_found = False      # scons default: okay to be missing
      site_dir = os.path.join(topdir, site_dir_name)
  
      if not os.path.exists(site_dir):
          if err_if_not_found:
              raise SCons.Errors.UserError("site dir %s not found." % site_dir)
          return
      sys.path.insert(0, os.path.abspath(site_dir))
  
      site_init_filename = "site_init.py"
      site_init_modname = "site_init"
      site_tools_dirname = "site_tools"
      site_init_file = os.path.join(site_dir, site_init_filename)
      site_tools_dir = os.path.join(site_dir, site_tools_dirname)
  
      if os.path.exists(site_tools_dir):
          SCons.Tool.DefaultToolpath.insert(0, os.path.abspath(site_tools_dir))
  
      if not os.path.exists(site_init_file):
          return
  
      # "import" the site_init.py file into the SCons.Script namespace.
      # This is a variant on the basic Python import flow in that the globals
      # dict for the compile step is prepopulated from the SCons.Script
      # module object; on success the SCons.Script globals are refilled
      # from the site_init globals so it all appears in SCons.Script
      # instead of as a separate module.
      try:
          try:
              m = sys.modules['SCons.Script']
          except KeyError:
              fmt = 'cannot import {}: missing SCons.Script module'
              raise SCons.Errors.InternalError(fmt.format(site_init_file))
  
          spec = importlib.util.spec_from_file_location(site_init_modname, site_init_file)
          site_m = {
              "__file__": spec.origin,
              "__name__": spec.name,
              "__doc__": None,
          }
          re_dunder = re.compile(r"__[^_]+__")
          # update site dict with all but magic (dunder) methods
          for k, v in m.__dict__.items():
              if not re_dunder.match(k):
                  site_m[k] = v
  
          with open(spec.origin, 'r') as f:
              code = f.read()
          try:
              codeobj = compile(code, spec.name, "exec")
              exec(codeobj, site_m)
          except KeyboardInterrupt:
              raise
          except Exception:
              fmt = "*** Error loading site_init file {}:\n"
              sys.stderr.write(fmt.format(site_init_file))
              raise
          else:
              # now refill globals with site_init's symbols
              for k, v in site_m.items():
                  if not re_dunder.match(k):
                      m.__dict__[k] = v
      except KeyboardInterrupt:
          raise
      except Exception:
          fmt = "*** cannot import site init file {}:\n"
          sys.stderr.write(fmt.format(site_init_file))
          raise
function_tokens: def _load_site_scons_dir ( topdir , site_dir_name = None ) : if site_dir_name : err_if_not_found = True # user specified: err if missing else : site_dir_name = "site_scons" err_if_not_found = False # scons default: okay to be missing site_dir = os . path . join ( topdir , site_dir_name ) if not os . path . exists ( site_dir ) : if err_if_not_found : raise SCons . Errors . UserError ( "site dir %s not found." % site_dir ) return sys . path . insert ( 0 , os . path . abspath ( site_dir ) ) site_init_filename = "site_init.py" site_init_modname = "site_init" site_tools_dirname = "site_tools" site_init_file = os . path . join ( site_dir , site_init_filename ) site_tools_dir = os . path . join ( site_dir , site_tools_dirname ) if os . path . exists ( site_tools_dir ) : SCons . Tool . DefaultToolpath . insert ( 0 , os . path . abspath ( site_tools_dir ) ) if not os . path . exists ( site_init_file ) : return # "import" the site_init.py file into the SCons.Script namespace. # This is a variant on the basic Python import flow in that the globals # dict for the compile step is prepopulated from the SCons.Script # module object; on success the SCons.Script globals are refilled # from the site_init globals so it all appears in SCons.Script # instead of as a separate module. try : try : m = sys . modules [ 'SCons.Script' ] except KeyError : fmt = 'cannot import {}: missing SCons.Script module' raise SCons . Errors . InternalError ( fmt . format ( site_init_file ) ) spec = importlib . util . spec_from_file_location ( site_init_modname , site_init_file ) site_m = { "__file__" : spec . origin , "__name__" : spec . name , "__doc__" : None , } re_dunder = re . compile ( r"__[^_]+__" ) # update site dict with all but magic (dunder) methods for k , v in m . __dict__ . items ( ) : if not re_dunder . match ( k ) : site_m [ k ] = v with open ( spec . origin , 'r' ) as f : code = f . read ( ) try : codeobj = compile ( code , spec . name , "exec" ) exec ( codeobj , site_m ) except KeyboardInterrupt : raise except Exception : fmt = "*** Error loading site_init file {}:\n" sys . stderr . write ( fmt . format ( site_init_file ) ) raise else : # now refill globals with site_init's symbols for k , v in site_m . items ( ) : if not re_dunder . match ( k ) : m . __dict__ [ k ] = v except KeyboardInterrupt : raise except Exception : fmt = "*** cannot import site init file {}:\n" sys . stderr . write ( fmt . format ( site_init_file ) ) raise