Skip to content

File

laktory.models.resources.databricks.File ¤

Bases: RenderableFileMixin, FileBase

Databricks Unity Catalog Volume File

File uploaded to a Unity Catalog volume. Files can also be declared directly in the files of a Volume, with dirpath relative to the volume root.

Examples:

import io

from laktory import models

file_yaml = '''
source: ./data/stock_prices/prices.json
dirpath: /Volumes/dev/sources/landing/stock_prices/
'''
file = models.resources.databricks.File.model_validate_yaml(io.StringIO(file_yaml))
print(file.path)
# > /Volumes/dev/sources/landing/stock_prices/prices.json
References
BASE DESCRIPTION
content_base64

Contents in base 64 format. Conflicts with source

TYPE: str | None | VariableType DEFAULT: None

md5

TYPE: str | None | VariableType DEFAULT: None

remote_file_modified

TYPE: bool | None | VariableType DEFAULT: None

LAKTORY DESCRIPTION
dirpath

Volume directory in which the file is deployed, e.g. /Volumes/dev/sources/landing/configs/. When declared in the files of a volume, relative to the volume root. Used only if path is not specified.

TYPE: str | VariableType DEFAULT: None

path_

Volume filepath for the file, e.g. /Volumes/dev/sources/landing/file.txt. Overwrite dirpath.

TYPE: str | VariableType DEFAULT: None

render_vars

If True, resolve ${vars.x} / ${{ expr }} placeholders in this file's content before upload. Resolved content is staged under settings.build_root; the staged copy is (re)written whenever Stack.build() runs (which preview, deploy, destroy and build all trigger).

TYPE: bool DEFAULT: False

source_

The full absolute path to the file. Conflicts with content_base64

TYPE: str | VariableType DEFAULT: None

METHOD DESCRIPTION
build

Render ${vars.x}/${{ expr }} placeholders in the file content

check_staged

Raise a clear error if this resource is configured for variable

ATTRIBUTE DESCRIPTION
filename

File filename

TYPE: str

filename property ¤

File filename

build(vars=None) ¤

Render ${vars.x}/${{ expr }} placeholders in the file content and stage the result under settings.build_root, if render_vars is True. No-op otherwise.

Source code in laktory/models/resources/databricks/file.py
86
87
88
89
90
91
92
93
def build(self, vars: dict = None):
    """
    Render `${vars.x}`/`${{ expr }}` placeholders in the file content
    and stage the result under `settings.build_root`, if `render_vars`
    is `True`. No-op otherwise.
    """
    if self.render_vars:
        self._render_to_staged_path(self.source_, self.source, vars=vars)

check_staged() ¤

Raise a clear error if this resource is configured for variable rendering but its staged copy hasn't been written yet (i.e. .build() hasn't run). Guards against programmatic use that bypasses Stack.build() (the normal CLI flow always calls it before dumping resources).

Source code in laktory/models/resources/databricks/_renderablefile.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def check_staged(self):
    """
    Raise a clear error if this resource is configured for variable
    rendering but its staged copy hasn't been written yet (i.e.
    `.build()` hasn't run). Guards against programmatic use that
    bypasses `Stack.build()` (the normal CLI flow always calls it
    before dumping resources).
    """
    if not self.render_vars:
        return
    staged = self._rendered_field_value
    if staged and not Path(staged).exists():
        raise RuntimeError(
            f"'{staged}' has not been rendered yet. Run `laktory build` "
            "(or `preview`/`deploy`, which trigger it automatically) "
            "before this resource is used."
        )