apple / apple/pkl

inheriting imports on amends / extends

Open
#1,150 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
11.5k
Forks
402
Avg merge
1d 15h
Merged PRs (30d)
20

Description

Hello,

I have a pkl template file that have many imports defined. For example, main.pkl is my template, and foo.pkl is a supporting util library, and bar.pkl is my configuration file.

The idea is that, as a user-facing configuration file, for UX reasons, bar.pkl shouldn't have 100 import lines, where the user scrolls to the bottom of the file to enter their configurations.

I assume that since the imports are already in the non user-facing pkl files, then by doing 'amends' or 'extends' the config files can just access those imports.

At the moment, I did several test for this functionality as seen below. Is there another way to do this without writing a chaining function on the template?

*main.pkl*
```pkl
open module main

import "foo.pkl" as foo

bar: String?
baz: String?

function foo1(): String = foo.foo()
```

*foo.pkl*
```pkl
function foo(): String = "foo bar baz"
```

*bar.pkl*
```pkl
amends "main.pkl"

bar = foo1()
baz = "\(foo.foo())"
```

```sh
$ pkl eval bar.pkl
–– Pkl Error ––
Cannot find property `foo`.

4 | baz = "\(foo.foo())"
^^^
at bar#baz (file:///private/tmp/inherited-imports/bar.pkl, line 4)

Did you mean any of the following?
foo1()

106 | text = renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

*baz.pkl*
```pkl
extends "main.pkl"

bar = foo1()
baz = "\(foo.foo())"
```

```sh
$ pkl eval baz.pkl

–– Pkl Error ––
Cannot find property `foo`.

4 | baz = "\(foo.foo())"
^^^
at baz#baz (file:///private/tmp/inherited-imports/baz.pkl, line 4)

Did you mean any of the following?
foo1()

106 | text = renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

*qux.pkl*
```pkl
amends "main.pkl"

bar = foo1()
```

```sh
$ pkl eval qux.pkl

bar = "foo bar baz"
baz = null
```

Contributor guide

Open the contributing guide

Research direction

Start by running the examples in main.pkl, foo.pkl, bar.pkl, baz.pkl, and qux.pkl with `pkl eval` to confirm how imports behave across amends and extends. Compare the successful `foo1()` access with the failing direct `foo.foo()` access and determine whether inherited imports should be visible; done means the intended behavior is defined and covered by the reported examples.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.