mirror of https://github.com/databricks/cli.git
Include translation of file:// references
This commit is contained in:
parent
3f87b7fa06
commit
2ff5775ae5
|
@ -241,6 +241,40 @@ class LookupRewriter:
|
||||||
return variables
|
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):
|
def dedup_variables(variables):
|
||||||
deduped = dict()
|
deduped = dict()
|
||||||
for v in variables:
|
for v in variables:
|
||||||
|
@ -320,6 +354,11 @@ def main():
|
||||||
lr.add(env)
|
lr.add(env)
|
||||||
var_lookup_variables.extend(lr.rewrite())
|
var_lookup_variables.extend(lr.rewrite())
|
||||||
|
|
||||||
|
# Rewrite file references
|
||||||
|
for job in jobs.values():
|
||||||
|
fr = FileRefRewriter(job)
|
||||||
|
fr.rewrite()
|
||||||
|
|
||||||
for job in jobs.values():
|
for job in jobs.values():
|
||||||
base_job = job.compute_base()
|
base_job = job.compute_base()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue