LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
Classes | Functions | Variables
lsst.sconsUtils.utils Namespace Reference

Classes

class  Log
 A dead-simple logger for all messages. More...
 

Functions

def _has_OSX_SIP
 Internal function indicating that the OS has System Integrity Protection. More...
 
def libraryPathPassThrough
 Returns name of library path environment variable to be passed through or else returns None if no pass through is required on this platform. More...
 
def whichPython
 Returns the full path to the Python executable as determined from the PATH. More...
 
def needShebangRewrite
 Returns True if the shebang lines of executables should be rewritten. More...
 
def libraryLoaderEnvironment
 Returns library loader path environment string to be prepended to external commands Will be "" if nothing is required. More...
 
def runExternal
 Safe wrapper for running external programs, reading stdout, and sanitizing error messages. More...
 
def memberOf
 A Python decorator that injects functions into a class. More...
 

Variables

 _pythonPath = None
 

Function Documentation

def lsst.sconsUtils.utils._has_OSX_SIP ( )
private

Internal function indicating that the OS has System Integrity Protection.

Definition at line 55 of file utils.py.

55 
56 def _has_OSX_SIP():
57  hasSIP = False
58  os_platform = SCons.Platform.platform_default()
59  # SIP is enabled on OS X >=10.11 equivalent to darwin >= 15
60  if os_platform == 'darwin':
61  release_str = platform.release()
62  release_major = int(release_str.split('.')[0])
63  if release_major >= 15:
64  hasSIP = True
65  return hasSIP
66 
def _has_OSX_SIP
Internal function indicating that the OS has System Integrity Protection.
Definition: utils.py:55
def lsst.sconsUtils.utils.libraryLoaderEnvironment ( )

Returns library loader path environment string to be prepended to external commands Will be "" if nothing is required.

Definition at line 105 of file utils.py.

107  libpathstr = ""
108  # If we have an OS X with System Integrity Protection enabled or similar we need
109  # to pass through DYLD_LIBRARY_PATH to the external command.
110  pass_through_var = libraryPathPassThrough()
111  if pass_through_var is not None:
112  for varname in (pass_through_var, "LSST_LIBRARY_PATH"):
113  if varname in os.environ:
114  libpathstr = '{}="{}"'.format(pass_through_var, os.environ[varname])
115  break
116  return libpathstr
117 
def libraryPathPassThrough
Returns name of library path environment variable to be passed through or else returns None if no pas...
Definition: utils.py:70
def libraryLoaderEnvironment
Returns library loader path environment string to be prepended to external commands Will be "" if not...
Definition: utils.py:105
def lsst.sconsUtils.utils.libraryPathPassThrough ( )

Returns name of library path environment variable to be passed through or else returns None if no pass through is required on this platform.

Definition at line 70 of file utils.py.

70 
72  if _has_OSX_SIP():
73  return "DYLD_LIBRARY_PATH"
74  return None
75 
76 
# Cache variable for whichPython() function
def _has_OSX_SIP
Internal function indicating that the OS has System Integrity Protection.
Definition: utils.py:55
def libraryPathPassThrough
Returns name of library path environment variable to be passed through or else returns None if no pas...
Definition: utils.py:70
def lsst.sconsUtils.utils.memberOf (   cls,
  name = None 
)

A Python decorator that injects functions into a class.

For example:

1 class test_class(object):
2  pass
3 
4 @memberOf(test_class):
5 def test_method(self):
6  print "test_method!"

...will cause test_method to appear as as if it were defined within test_class.

The function or method will still be added to the module scope as well, replacing any existing module-scope function with that name; this appears to be unavoidable.

Definition at line 157 of file utils.py.

158 def memberOf(cls, name=None):
159  if isinstance(cls, type):
160  classes = (cls,)
161  else:
162  classes = tuple(cls)
163  kw = {"name": name}
164 
165  def nested(member):
166  if kw["name"] is None:
167  kw["name"] = member.__name__
168  for scope in classes:
169  setattr(scope, kw["name"], member)
170  return member
171  return nested
def memberOf
A Python decorator that injects functions into a class.
Definition: utils.py:157
def lsst.sconsUtils.utils.needShebangRewrite ( )

Returns True if the shebang lines of executables should be rewritten.

Definition at line 97 of file utils.py.

97 
98 def needShebangRewrite():
99  return _has_OSX_SIP()
100 
def needShebangRewrite
Returns True if the shebang lines of executables should be rewritten.
Definition: utils.py:97
def _has_OSX_SIP
Internal function indicating that the OS has System Integrity Protection.
Definition: utils.py:55
def lsst.sconsUtils.utils.runExternal (   cmd,
  fatal = False,
  msg = None 
)

Safe wrapper for running external programs, reading stdout, and sanitizing error messages.

Note that the entire program output is returned, not just a single line.

Definition at line 123 of file utils.py.

124 def runExternal(cmd, fatal=False, msg=None):
125  if msg is None:
126  try:
127  msg = "Error running %s" % cmd.split()[0]
128  except:
129  msg = "Error running external command"
130  process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
131  stdout, stderr = process.communicate()
132  if process.returncode != 0:
133  if fatal:
134  raise RuntimeError("%s: %s" % (msg, stderr))
135  else:
136  from . import state # can't import at module scope due to circular dependency
137  state.log.warn("%s: %s" % (msg, stderr))
138  return stdout
139 
def runExternal
Safe wrapper for running external programs, reading stdout, and sanitizing error messages.
Definition: utils.py:123
def lsst.sconsUtils.utils.whichPython ( )

Returns the full path to the Python executable as determined from the PATH.

Does not return the full path of the Python running SCons. Caches result and assumes the PATH does not change between calls. Runs the "python" command and asks where it is rather than scanning the PATH.

Definition at line 86 of file utils.py.

86 
87 def whichPython():
88  global _pythonPath
89  if _pythonPath is None:
90  output = subprocess.check_output(["python", "-c", "import sys; print(sys.executable)"])
91  _pythonPath = output.decode()
92  return _pythonPath
93 
def whichPython
Returns the full path to the Python executable as determined from the PATH.
Definition: utils.py:86

Variable Documentation

lsst.sconsUtils.utils._pythonPath = None

Definition at line 77 of file utils.py.