LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Classes | Functions
lsst.sconsUtils.installation Namespace Reference

Classes

class  DirectoryInstaller
 SCons Action callable to recursively install a directory. More...
 

Functions

def makeProductPath
 return a path to use as the installation directory for a product More...
 
def determineVersion
 Set a version ID from env, or a version control ID string ($name$ or $HeadURL$) More...
 
def getFingerprint
 Return a unique fingerprint for a version (e.g. More...
 
def setPrefix
 Set a prefix based on the EUPS_PATH, the product name, and a versionString from cvs or svn. More...
 
def Declare
 Create current and declare targets for products. More...
 
def InstallDir
 Install the directory dir into prefix, (along with all its descendents if recursive is True). More...
 
def InstallEups
 Install a ups directory, setting absolute versions as appropriate (unless you're installing from the trunk, in which case no versions are expanded). More...
 
def InstallLSST
 Install directories in the usual LSST way, handling "ups" specially. More...
 

Function Documentation

def lsst.sconsUtils.installation.Declare (   self,
  products = None 
)

Create current and declare targets for products.

products may be a list of (product, version) tuples. If product is None it's taken to be self['eupsProduct']; if version is None it's taken to be self['version'].

Definition at line 139 of file installation.py.

140 def Declare(self, products=None):
141 
142  if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS and not self.GetOption("silent"):
143  state.log.warn("'scons undeclare' is deprecated; please use 'scons declare -c' instead")
144 
145  acts = []
146  if \
147  "declare" in SCons.Script.COMMAND_LINE_TARGETS or \
148  "undeclare" in SCons.Script.COMMAND_LINE_TARGETS or \
149  ("install" in SCons.Script.COMMAND_LINE_TARGETS and self.GetOption("clean")) or \
150  "current" in SCons.Script.COMMAND_LINE_TARGETS:
151  current = []; declare = []; undeclare = []
152 
153  if not products:
154  products = [None]
155 
156  for prod in products:
157  if not prod or isinstance(prod, str): # i.e. no version
158  product = prod
159 
160  if 'version' in self:
161  version = self['version']
162  else:
163  version = None
164  else:
165  product, version = prod
166 
167  if not product:
168  product = self['eupsProduct']
169 
170  if "EUPS_DIR" in os.environ:
171  self['ENV']['PATH'] += os.pathsep + "%s/bin" % (os.environ["EUPS_DIR"])
172  self["ENV"]["EUPS_LOCK_PID"] = os.environ.get("EUPS_LOCK_PID", "-1")
173  if "undeclare" in SCons.Script.COMMAND_LINE_TARGETS or self.GetOption("clean"):
174  if version:
175  command = "eups undeclare --flavor %s %s %s" % \
176  (self['eupsFlavor'], product, version)
177  if ("current" in SCons.Script.COMMAND_LINE_TARGETS
178  and not "declare" in SCons.Script.COMMAND_LINE_TARGETS):
179  command += " --current"
180 
181  if self.GetOption("clean"):
182  self.Execute(command)
183  else:
184  undeclare += [command]
185  else:
186  state.log.warn("I don't know your version; not undeclaring to eups")
187  else:
188  command = "eups declare --force --flavor %s --root %s" % \
189  (self['eupsFlavor'], self['prefix'])
190 
191  if 'eupsPath' in self:
192  command += " -Z %s" % self['eupsPath']
193 
194  if version:
195  command += " %s %s" % (product, version)
196 
197  current += [command + " --current"]
198 
199  if self.GetOption("tag"):
200  command += " --tag=%s" % self.GetOption("tag")
201 
202  declare += [command]
203 
204  if current:
205  acts += self.Command("current", "", action=current)
206  if declare:
207  if "current" in SCons.Script.COMMAND_LINE_TARGETS:
208  acts += self.Command("declare", "", action="") # current will declare it for us
209  else:
210  acts += self.Command("declare", "", action=declare)
211  if undeclare:
212  acts += self.Command("undeclare", "", action=undeclare)
213 
214  return acts
215 
216 #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def Declare
Create current and declare targets for products.
def lsst.sconsUtils.installation.determineVersion (   env,
  versionString 
)

Set a version ID from env, or a version control ID string ($name$ or $HeadURL$)

Definition at line 47 of file installation.py.

47 
48 def determineVersion(env, versionString):
49  version = "unknown"
50  if 'version' in env:
51  version = env['version']
52  elif not versionString:
53  version = "unknown"
54  elif re.search(r"^[$]Name:\s+", versionString):
55  # CVS. Extract the tagname
56  version = re.search(r"^[$]Name:\s+([^ $]*)", versionString).group(1)
57  if version == "":
58  version = "cvs"
59  elif re.search(r"^[$]HeadURL:\s+", versionString):
60  # SVN. Guess the tagname from the last part of the directory
61  HeadURL = re.search(r"^[$]HeadURL:\s+(.*)", versionString).group(1)
62  HeadURL = os.path.split(HeadURL)[0]
63  version = svn.guessVersionName(HeadURL)
64  elif versionString.lower() in ("hg", "mercurial"):
65  # Mercurial (hg).
66  version = hg.guessVersionName()
67  elif versionString.lower() in ("git",):
68  # git.
69  version = git.guessVersionName()
70  return version.replace("/", "_")
71 
72 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def determineVersion
Set a version ID from env, or a version control ID string ($name$ or $HeadURL$)
Definition: installation.py:47
def lsst.sconsUtils.installation.getFingerprint (   versionString)

Return a unique fingerprint for a version (e.g.

an SHA1); return None if unavailable

Definition at line 74 of file installation.py.

74 
75 def getFingerprint(versionString):
76  if versionString.lower() in ("hg", "mercurial"):
77  fingerprint, modified = hg.guessFingerprint()
78  elif versionString.lower() in ("git",):
79  fingerprint, modified = git.guessFingerprint()
80  else:
81  fingerprint, modified = None, False
82 
83  if fingerprint and modified:
84  fingerprint += " *"
85 
86  return fingerprint
def getFingerprint
Return a unique fingerprint for a version (e.g.
Definition: installation.py:74
def lsst.sconsUtils.installation.InstallDir (   self,
  prefix,
  dir,
  ignoreRegex = r"(~$|\.pyc$|\.os?$)",
  recursive = True 
)

Install the directory dir into prefix, (along with all its descendents if recursive is True).

Omit files and directories that match ignoreRegex

Definition at line 263 of file installation.py.

264 def InstallDir(self, prefix, dir, ignoreRegex=r"(~$|\.pyc$|\.os?$)", recursive=True):
265  if not self.installing:
266  return []
267  result = self.Command(target=os.path.join(self.Dir(prefix).abspath, dir), source=dir,
268  action=DirectoryInstaller(ignoreRegex, recursive))
269  self.AlwaysBuild(result)
270  return result
271 
272 #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
SCons Action callable to recursively install a directory.
def InstallDir
Install the directory dir into prefix, (along with all its descendents if recursive is True)...
def lsst.sconsUtils.installation.InstallEups (   env,
  dest,
  files = [],
  presetup = "" 
)

Install a ups directory, setting absolute versions as appropriate (unless you're installing from the trunk, in which case no versions are expanded).

Any build/table files present in "./ups" are automatically added to files.

If presetup is provided, it's expected to be a dictionary with keys product names and values the version that should be installed into the table files, overriding eups expandtable's usual behaviour. E.g. env.InstallEups(os.path.join(env['prefix'], "ups"), presetup={"sconsUtils" : env['version']})

Definition at line 285 of file installation.py.

286 def InstallEups(env, dest, files=[], presetup=""):
287 
288  acts = []
289  if not env.installing:
290  return acts
291 
292  if env.GetOption("clean"):
293  state.log.warn("Removing" + dest)
294  shutil.rmtree(dest, ignore_errors=True)
295  else:
296  presetupStr = []
297  for p in presetup:
298  presetupStr += ["--product %s=%s" % (p, presetup[p])]
299  presetup = " ".join(presetupStr)
300 
301  env = env.Clone(ENV = os.environ)
302  #
303  # Add any build/table/cfg files to the desired files
304  #
305  files = [str(f) for f in files] # in case the user used Glob not glob.glob
306  files += glob.glob(os.path.join("ups", "*.build")) + glob.glob(os.path.join("ups","*.table")) \
307  + glob.glob(os.path.join("ups", "*.cfg")) \
308  + glob.glob(os.path.join("ups", "eupspkg*"))
309  files = list(set(files)) # remove duplicates
310 
311  buildFiles = [f for f in files if re.search(r"\.build$", f)]
312  build_obj = env.Install(dest, buildFiles)
313  acts += build_obj
314 
315  tableFiles = [f for f in files if re.search(r"\.table$", f)]
316  table_obj = env.Install(dest, tableFiles)
317  acts += table_obj
318 
319  eupspkgFiles = [f for f in files if re.search(r"^eupspkg", f)]
320  eupspkg_obj = env.Install(dest, eupspkgFiles)
321  acts += eupspkg_obj
322 
323  miscFiles = [f for f in files if not re.search(r"\.(build|table)$", f)]
324  misc_obj = env.Install(dest, miscFiles)
325  acts += misc_obj
326 
327  try:
328  import eups.lock
329 
330  path = eups.Eups.setEupsPath()
331  if path:
332  locks = eups.lock.takeLocks("setup", path, eups.lock.LOCK_SH)
333  env["ENV"]["EUPS_LOCK_PID"] = os.environ.get("EUPS_LOCK_PID", "-1")
334  except ImportError:
335  state.log.warn("Unable to import eups; not locking")
336 
337  eupsTargets = []
338 
339  for i in build_obj:
340  env.AlwaysBuild(i)
341 
342  cmd = "eups expandbuild -i --version %s " % env['version']
343  if 'baseversion' in env:
344  cmd += " --repoversion %s " % env['baseversion']
345  cmd += str(i)
346  eupsTargets.extend(env.AddPostAction(build_obj, env.Action("%s" %(cmd), cmd)))
347 
348  for i in table_obj:
349  env.AlwaysBuild(i)
350 
351  cmd = "eups expandtable -i -W '^(?!LOCAL:)' " # version doesn't start "LOCAL:"
352  if presetup:
353  cmd += presetup + " "
354  cmd += str(i)
355 
356  act = env.Command("table", "", env.Action("%s" %(cmd), cmd))
357  eupsTargets.extend(act)
358  acts += act
359  env.Depends(act, i)
360 
361  # By declaring that all the Eups operations create a file called "eups" as a side-effect,
362  # even though they don't, SCons knows it can't run them in parallel (it thinks of the
363  # side-effect file as something like a log, and knows you shouldn't be appending to it
364  # in parallel). When Eups locking is working, we may be able to remove this.
365  env.SideEffect("eups", eupsTargets)
366 
367  return acts
368 
369 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def InstallEups
Install a ups directory, setting absolute versions as appropriate (unless you're installing from the ...
def lsst.sconsUtils.installation.InstallLSST (   self,
  prefix,
  dirs,
  ignoreRegex = None 
)

Install directories in the usual LSST way, handling "ups" specially.

Definition at line 372 of file installation.py.

373 def InstallLSST(self, prefix, dirs, ignoreRegex=None):
374  results = []
375  for d in dirs:
376  # if eups is disabled, the .build & .table files will not be "expanded"
377  if d == "ups" and not state.env['no_eups']:
378  t = self.InstallEups(os.path.join(prefix, "ups"))
379  else:
380  t = self.InstallDir(prefix, d, ignoreRegex=ignoreRegex)
381  self.Depends(t, d)
382  results.extend(t)
383  self.Alias("install", t)
384  self.Clean("install", prefix)
385  return results
def InstallLSST
Install directories in the usual LSST way, handling "ups" specially.
def lsst.sconsUtils.installation.makeProductPath (   env,
  pathFormat 
)

return a path to use as the installation directory for a product

Parameters
pathFormatthe format string to process
envthe scons environment

Definition at line 31 of file installation.py.

31 
32 def makeProductPath(env, pathFormat):
33  pathFormat = re.sub(r"%(\w)", r"%(\1)s", pathFormat)
34 
35  eupsPath = os.environ['PWD']
36  if 'eupsPath' in env and env['eupsPath']:
37  eupsPath = env['eupsPath']
38 
39  return pathFormat % { "P": eupsPath,
40  "f": env['eupsFlavor'],
41  "p": env['eupsProduct'],
42  "v": env['version'],
43  "c": os.environ['PWD'] }
44 
45 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
def makeProductPath
return a path to use as the installation directory for a product
Definition: installation.py:31
def lsst.sconsUtils.installation.setPrefix (   env,
  versionString,
  eupsProductPath = None 
)

Set a prefix based on the EUPS_PATH, the product name, and a versionString from cvs or svn.

Definition at line 88 of file installation.py.

88 
89 def setPrefix(env, versionString, eupsProductPath=None):
90  try:
91  env['version'] = determineVersion(env, versionString)
92  except RuntimeError as err:
93  env['version'] = "unknown"
94  if (env.installing or env.declaring) and not env['force']:
95  state.log.fail(
96  "%s\nFound problem with version number; update or specify force=True to proceed"
97  % err
98  )
99 
100  if state.env['no_eups']:
101  if 'prefix' in env and env['prefix']:
102  return env['prefix']
103  else:
104  return "/usr/local"
105 
106  if eupsProductPath:
107  eupsPrefix = makeProductPath(env, eupsProductPath)
108  elif 'eupsPath' in env and env['eupsPath']:
109  eupsPrefix = env['eupsPath']
110  else:
111  state.log.fail("Unable to determine eupsPrefix from eupsProductPath or eupsPath")
112  flavor = env['eupsFlavor']
113  if not re.search("/" + flavor + "$", eupsPrefix):
114  eupsPrefix = os.path.join(eupsPrefix, flavor)
115  prodPath = env['eupsProduct']
116  if 'eupsProductPath' in env and env['eupsProductPath']:
117  prodPath = env['eupsProductPath']
118  eupsPrefix = os.path.join(eupsPrefix, prodPath, env["version"])
119  else:
120  eupsPrefix = None
121  if 'prefix' in env:
122  if env['version'] != "unknown" and eupsPrefix and eupsPrefix != env['prefix']:
123  state.log.warn("Ignoring prefix %s from EUPS_PATH" % eupsPrefix)
124  return makeProductPath(env, env['prefix'])
125  elif 'eupsPath' in env and env['eupsPath']:
126  prefix = eupsPrefix
127  else:
128  prefix = "/usr/local"
129  return prefix
130 
131 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def makeProductPath
return a path to use as the installation directory for a product
Definition: installation.py:31
def determineVersion
Set a version ID from env, or a version control ID string ($name$ or $HeadURL$)
Definition: installation.py:47
def setPrefix
Set a prefix based on the EUPS_PATH, the product name, and a versionString from cvs or svn...
Definition: installation.py:88