Skip to content
Snippets Groups Projects
Commit 68dd0c5d authored by Dennis Terhorst's avatar Dennis Terhorst :rocket: Committed by Eleni Mathioulaki
Browse files

remove dead code


Co-Authored-By: default avatarEleni Mathioulaki <emathioulaki@athenarc.gr>
parent a2e19f97
No related branches found
No related tags found
No related merge requests found
......@@ -32,11 +32,15 @@ logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger()
class Rewriter:
def __init__(self, installpath=None, viewpath=None):
self._installpath = installpath
self._viewpath = viewpath
def __init__(self, installpath: Path, viewpath: Path):
self._installpath = Path(installpath)
self._viewpath = Path(viewpath)
self._export_re = re.compile(r"^export (?P<key>\w+)=['\"]?(?P<value>.*?)['\"]?;\n")
self._package_re = re.compile(r"(?P<package>\w[^/]+)-(?P<hash>[0-9a-z]{32})/(?P<relative>.*)")
if not self._installpath.is_dir():
raise ValueError(f"installpath {self._installpath} is not a directory")
if not self._viewpath.is_dir():
raise ValueError(f"viewpath {self._viewpath} is not a directory")
@property
def installpath(self):
......@@ -73,29 +77,13 @@ class Rewriter:
log.debug("REWRITE value split by '%s'", separator)
log.debug("REWRITE value '%s'", value)
# heuristically use the first path to the view as viewpath
if self._viewpath is None:
possibles = [inpath for inpath in value.split(separator) if inpath.endswith(".spack-env/view")]
log.debug("possible paths: %s", possibles)
if possibles:
self._viewpath = possibles[0]
log.info("identifed viewpath: %s", self._viewpath)
if separator not in value:
log.debug("value paste (no separator)")
return value
if self._viewpath is None and "spack" in value:
log.warning("viewpath is still unknown")
log.debug("value paste (no viewpath)")
return value
inpaths = value.split(separator)
log.debug("inspecting %s paths", len(inpaths))
if self._viewpath is None:
raise ValueError("Found export but view path is not known yet")
outpaths = []
for path in value.split(separator):
if not path.startswith(str(self.installpath)):
......@@ -109,7 +97,7 @@ class Rewriter:
log.debug(f"matching subpath={subpath}")
toolpath = self._package_re.match(subpath)
if toolpath:
newpath = str(Path(self._viewpath) / toolpath.group("relative"))
newpath = str(self._viewpath / toolpath.group("relative"))
if newpath not in outpaths:
log.debug("append changed: %s", newpath)
outpaths.append(newpath)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment