Include translation of file:// references

This commit is contained in:
Pieter Noordhuis 2024-11-11 15:42:17 +01:00
parent 3f87b7fa06
commit 2ff5775ae5
No known key found for this signature in database
GPG Key ID: 12ACCCC104CF2930
1 changed files with 39 additions and 0 deletions

View File

@ -241,6 +241,40 @@ class LookupRewriter:
return variables
class FileRefRewriter:
_prefixes = [
"file://",
"file:fuse://",
]
def __init__(self, job: Job) -> None:
self.job = job
def rewrite(self):
# Now rewrite the job configuration
def cb(path, obj):
if not isinstance(obj, str):
return obj
for prefix in self._prefixes:
if not obj.startswith(prefix):
continue
# DBX anchors paths at the root of the project.
# DABs anchors paths relative to the location of the configuration file.
# Below we write configuration to the "./resources" directory.
# We need to go up one level to get to the root of the project.
payload = obj.replace(prefix, "")
return f"../{payload}"
return obj
for env in self.job.configs.keys():
self.job.configs[env] = walk(copy.deepcopy(self.job.configs[env]), cb)
return
def dedup_variables(variables):
deduped = dict()
for v in variables:
@ -320,6 +354,11 @@ def main():
lr.add(env)
var_lookup_variables.extend(lr.rewrite())
# Rewrite file references
for job in jobs.values():
fr = FileRefRewriter(job)
fr.rewrite()
for job in jobs.values():
base_job = job.compute_base()