Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 1.13 KB

File metadata and controls

27 lines (19 loc) · 1.13 KB
title sidebar_label
import_module
import_module

The import_module function imports the symbols from a Starlark script specified by the given locator, and requires that the calling Starlark script is part of a package.

# Import remote code from another package using an absolute import
remote = import_module("github.com/foo/bar/src/lib.star")

# Import local code from the same package using a relative import
local = import_module("./local.star")

def run(plan):
    # Use code from the imported module
    remote.do_something(plan)

    local.do_something_else(plan)

NOTE: We chose not to use the normal Starlark load primitive due to its lack of namespacing. By default, the symbols imported by load are imported to the global namespace of the script that's importing them. We preferred module imports to be namespaced, in the same way that Python does by default with its import statement.