Skip to content

Commit

Permalink
Add rel complement (set diff) arg to eups diff
Browse files Browse the repository at this point in the history
This commit adds a new argument to eups list: -C or  --diff. This
argument calculates the relative complement (aka, set difference) of
declared version products with respect to currently setup products.

All dependent products associated with the named product will be used as
a reference, relative to the list of setup products managed by EUPS.
  • Loading branch information
leeskelvin committed Jan 26, 2024
1 parent e80144b commit c103228
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
24 changes: 22 additions & 2 deletions python/eups/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .utils import cmp_or_key

def printProducts(ostrm, productName=None, versionName=None, eupsenv=None,
tags=None, setup=False, tablefile=False, directory=False,
tags=None, setup=False, tablefile=False, difference=False, directory=False,
dependencies=False, showVersion=False, showName=False, showTagsGlob="*",
depth=None, productDir=None, topological=False, checkCycles=False, raw=False):
"""
Expand All @@ -32,6 +32,8 @@ def printProducts(ostrm, productName=None, versionName=None, eupsenv=None,
@param setup restrict the listing to products that are currently
setup (or print actually setup versions with dependencies)
@param tablefile include the path to each product's table file
@param difference Print the relative complement (set difference) of declared version
products to setup products
@param directory include each product's installation directory
@param dependencies print the product's dependencies
@param showVersion Only print the product{'s,s'} version[s] (e.g. eups list -V -s afw)
Expand Down Expand Up @@ -97,7 +99,25 @@ def printProducts(ostrm, productName=None, versionName=None, eupsenv=None,

raise ProductNotFound(productName, versionName, msg="Unable to find product %s" % msg)

if difference:
if versionName:
raise EupsException("--diff does not make sense with a version")
if dependencies:
raise EupsException("--diff does not make sense with --dependencies")
setupProducts = set(eupsenv.getSetupProducts())
dependentProductList = eupsenv.getDependentProducts(productList[0])
dependentProducts = {x[0] for x in dependentProductList}
productList = list(setupProducts - dependentProducts)
if not productList:
return 0

productList.sort(key=lambda p: (p.name, p.version))

if difference:
# Insert the main product name at the front of the list, to be printed first
productNameIndex = [i for i, p in enumerate(productList) if p.name == productName][0]
productList.insert(0, productList.pop(productList.index(productList[productNameIndex])))

if dependencies:
_msgs = {} # maintain list of printed dependencies
recursionDepth, indent = 0, ""
Expand Down Expand Up @@ -249,7 +269,7 @@ def includeProduct(recursionDepth):
info += "|"
info += name + "|" + version
else:
if productName and not utils.isGlob(productName):
if productName and not utils.isGlob(productName) and not difference:
info += " "
else:
info += "%-21s " % (name)
Expand Down
5 changes: 4 additions & 1 deletion python/eups/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ def addOptions(self):
# these are specific to this command
self.clo.add_option("-c", "--current", dest="currentTag", action="store_true", default=False,
help="same as --postTag=current")
self.clo.add_option("-C", "--diff", dest="difference", action="store_true", default=False,
help="Print the relative complement (set difference) of declared version products with respect to currently setup products")
self.clo.add_option("-D", "--dependencies", dest="depends", action="store_true", default=False,
help="Print product's dependencies (must specify version if ambiguous). With --setup print the versions of dependent products that are actually setup.")
self.clo.add_option("--depth", dest="depth", action="store",
Expand Down Expand Up @@ -506,8 +508,9 @@ def execute(self):
n = eups.printProducts(sys.stdout, product, version,
self.createEups(self.opts, versionName=version, quiet=1),
tags=self.opts.tag,
setup=self.opts.setup,
setup=self.opts.setup or self.opts.difference,
tablefile=self.opts.tablefile,
difference=self.opts.difference,
directory=self.opts.printdir,
dependencies=self.opts.depends,
showVersion=self.opts.version, showName=self.opts.showName,
Expand Down

0 comments on commit c103228

Please sign in to comment.