Working with Files¶
Tugger’s Starlark dialect exposes various types and functions for working with files. The most important primitives are:
Represents an individual file - it’s filename, content, and an executable bit.
Represents a collection of files. This is a glorified mapping from an install path to
Read files from the filesystem by performing a glob filename pattern search.
Say you want to collect and then materialize a collection of files. Here’s how you would do that in Starlark.
# Create a new empty file manifest. m = FileManifest() # Add individual files to the manifest. m.add_file(FileContent(path = "file0.txt")) m.add_file(FileContent(path = "file1.txt")) # Then copy/materialize them somewhere. m.install("output/directory")
If you wanted, you could even rename files as part of this:
m = FileManifest() f = FileContent(path = "file0.txt") f.filename = "renamed.txt" m.add_file(f)
Or more concisely:
m = FileManifest() m.add_file(f, path="renamed.txt")