apple / pkl Goto Github PK
View Code? Open in Web Editor NEWA configuration as code language with rich validation and tooling.
Home Page: https://pkl-lang.org
License: Apache License 2.0
A configuration as code language with rich validation and tooling.
Home Page: https://pkl-lang.org
License: Apache License 2.0
Hi, just came here to check Pkl out. Unless it's hidden somewhere, I didn't see TOML being supported as an output format. Would it be possible to add TOML support?
Thanks!
This is the first step in #20 and critical to unlock outside contributions.
I'm really interested in using this in my rust projects, any plans on supporting serde/code generation?
Doc pages like:
https://pkl-lang.org/main/current/kotlin-binding/codegen.html
Contain the unnecessary staging repo config which seems like it should have been filtered out with:
ifndef::is-release-build[]
But maybe some underlying setting wasn't set when the release was created?
I'm trying to build Pkl on Ubuntu 22.04/WSL 2.0.14. (I'd prefer to build directly in Windows but ran into #20 and failing tests.) After reading through DEVELOPMENT.adoc
, I have the following questions:
What does "Setup Gradle on your system" entail? (./gradlew build
seems to work fine without further setup.)
How do I make ./gradlew buildNative
work? Currently, task :pkl-cli:alpineExecutableAmd64
fails with:
/usr/bin/ld: cannot find -lz: No such file or directory
Further up I see:
[7/7] Creating image... (0.0s @ 1.86GB)
Fatal error: java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1
Based on the linker command output, possible reasons for this include:
1. It appears as though libz:.a is missing. Please install it.
Installing package zlib1g-dev
, which contains /usr/lib/x86_64-linux-gnu/libz.a
, didn't solve the problem.
The good news is that after tinkering with the build scripts to exclude the Alpine build and test tasks, ./gradlew build buildNative
succeeded. So I think I'm pretty close...
Instead of adding bindings, it would be great if we had native Kotlin Multiplatform support. More then we can use pkl in more scenarios.
For example, I am considering using pkl to provide i18n in my Kotlin Multiplatform project.
We can follow this to implement a native Kotlin lexer.
especially for 3rd world countries where internet is slow
upx pkl
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2020
UPX 3.96 Markus Oberhumer, Laszlo Molnar & John Reiser Jan 23rd 2020
File size Ratio Format Name
-------------------- ------ ----------- -----------
87137256 -> 26604364 30.53% linux/amd64 pkl
Packed 1 file.
The default pkl aarch64 executable doesn't work on termux (or Android, basically), and I have no idea how to recompile the source code. The only workaround as of now is using something like andronix, where the pkl executable does work.
It would be beneficial if the process of writing a library for a given language was documented and semi standardized. So library support could be moved to the broader community. Especially for more niche languages.
We use kustomize to manage our Kubernetes configuration. Currently the pkl CLI fails when I feed it such a file to transform to YAML.
Here's what a kustomization file is: https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/
Here's the output of an attempt to convert a kustomization file:
pkl eval -p input=overlays/t1/kustomization.yaml -o overlays/t1/kustomization.pkl package://pkg.pkl-lang.org/pkl-pantry/[email protected]#/convert.pkl –– Pkl Error –– Cannot find a template for resource of kind
Kustomization`.
91 | throw("Cannot find a template for resource of kind \(kind)
.")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at k8s.contrib.convert#getResourceTemplate.<function#2> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L91-91)
88 | let (apiVersion = resource["apiVersion"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at k8s.contrib.convert#getResourceTemplate.<function#1> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L88-91)
87 | let (kind = resource["kind"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at k8s.contrib.convert#getResourceTemplate (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L87-91)
65 | let (template = getResourceTemplate(resource))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at k8s.contrib.convert#resourceConverters["convert resource to conform to Pkl template"].<function#1> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L65-65)
106 | resourceConverters.fold(resource, (acc, _, f) -> f.apply(acc))
^^^^^^^^^^^^
at k8s.contrib.convert#resourceConverterFn.<function#1> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L106-106)
106 | resourceConverters.fold(resource, (acc, _, f) -> f.apply(acc))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at k8s.contrib.convert#resourceConverterFn (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L106-106)
286 | for (lineIdx, line in renderConvertedValue(resourceConverterFn(resource)).split("\n")) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at k8s.contrib.convert#output.textBuffer (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L286-286)
304 | text = textBuffer.toList().join("")
^^^^^^^^^^
at k8s.contrib.convert#output.text (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/k8s.contrib/convert.pkl#L304-304)`
In the Typed objects, properties and amending section, the TutorialPart.pkl
has a name: String
property, but in the next section (A new template) in the workshop2023.pkl
example the agenda
(which I assume is to be an agenda: Mapping<String, TutorialPart>
from Workshop.pkl
) uses title
instead of name
:
pkl/docs/modules/language-tutorial/pages/03_writing_a_template.adoc
Lines 189 to 203 in 1543909
pkl/docs/modules/language-tutorial/pages/03_writing_a_template.adoc
Lines 305 to 310 in 1543909
After following along with the tutorial, adding amends "Workshop.pkl"
to the top of workshop2023.pkl
resulted in the error:
–– Pkl Error ––
Cannot find property `title` in module `TutorialPart`.
43 | title = "Basic Configuration"
^^^^^
at workshop2023#agenda["beginners"] (file://.../workshop2023.pkl, line 43)
Available properties in module `TutorialPart`:
amountLearned
bandwidthRequirementPerSecond
duration
hasExercises
name
output
part
41 | agenda {
^^^^^^^^
at workshop2023#agenda (file://.../workshop2023.pkl, line 41)
106 | text = renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.25.1/stdlib/base.pkl#L106)
Support for the Windows platform would be nice. As a member of the open source community (not acting officially with any company), here are some things I noticed that stand in the way of full Windows support.
Currently the Git repo cannot be cloned on Windows.
This file has a backslash in its name:
pkl-core/src/test/files/LanguageSnippetTests/input-helper/globtest/\moduleC.pkl
Since Windows uses the backslash a path separator, it is unable to create this file. Cloning fails with this error message:
error: invalid path 'pkl-core/src/test/files/LanguageSnippetTests/input-helper/globtest/\moduleC.pkl'
fatal: unable to checkout working tree
I tried working around this by doing a sparse checkout and have not had success. Git appears to validate path names before applying the sparse checkout filter.
Additionally, there are two directories with colons in the name. By default Git on Windows does not like these paths, but that could be worked around by setting git config core.protectNTFS false
.
Not yet attempted.
Net yet attempted
Net yet attempted
pkl-cli is published to Maven Central, but depends on pkl-server which is not.
It should be published as well.
There's an incorrect link in the output of pkl repl
:examples
that points to https://pkl-lang.org/main/0.25.1/language-reference/
Should this link go to https://pkl-lang.org/main/current/language-reference/index.html
?
pkl --version
Pkl 0.25.1 (macOS 14.1, native)
pkl repl
:examples
For more examples, see the Language Reference (Command+Double-click the link below):
https://pkl-lang.org/main/0.25.1/language-reference/
./gradlew pkldoc
Starting a Gradle Daemon, 1 busy and 3 incompatible Daemons could not be reused, use --status for details
> Task :pkl-core:compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :stdlib:pkldoc
An unexpected error has occurred. Would you mind filing a bug report?
java.lang.NullPointerException: uri.path must not be null
at org.pkl.doc.CliDocGenerator.doRun(CliDocGenerator.kt:237)
at org.pkl.commons.cli.CliCommand.run(CliCommand.kt:45)
at org.pkl.doc.DocCommand.run(Main.kt:71)
at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:198)
at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:18)
at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:400)
at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:397)
at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:415)
at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:440)
at org.pkl.doc.Main$main$1.invoke(Main.kt:36)
at org.pkl.doc.Main$main$1.invoke(Main.kt:36)
at org.pkl.commons.cli.CliMainKt.cliMain(CliMain.kt:31)
at org.pkl.doc.Main.main(Main.kt:36)
As a user after tackling boilerplate and validation in configuration, I would love a comparison of Pkl vs CUE in the relevant documentation sections.
I'd love to hear from anyone interested in writing PKL in Rust (:+1:) or Go.
Currently the following language bindings are supported:
It would be nice to add Python to the list, as it's one of the most popular programming languages, and it is often used to process configuration.
A first step towards achieving this may be the creation of a C API, which Python could then wrap:
I can help create a FreeBSD port, but I need to know how are you creating the Linux binaries.
While the artifacts currently contain Automatic-Module-Name
declarations in the manifest, which should make them usable from other JPMS modules, they don't have an actual module-info, which is required to use them with jlink for example.
Instead of being automatic modules, at least the library artifacts should have support for being loaded as actual named modules.
(Unfortunately, the unmaintained patched ANTLR fork as well as the collections library you use appear to be incompatible with this though)
There is no .jar
download file for version 0.25.1.
But the .jar
file is linked on the Installation page in the documentation.
It'd be great if there were examples of using pkl instead of HCL for Terraform in the same way that there is pkl-k8s-examples.
Please consider adding documentation for interop with Bazel, in particular bzlmod
and gazelle
.
Thank you
Hello, I'm trying to package pkl to NixOS. However, to this end, I would ideally need a gradle task that only downloads the dependencies, without trying to build the program. Does the project has something like this?
Thanks.
Problem statement:
The adoption of jsons/yamls is pretty much spread across the community/orgs. pkl
goal's to provide configuration-as-code language with rich validation and tooling.
For the cases when pkl
tool is the right fit this however entails a rather higher ramp up time for people converting the existing configurations -> pkl -> existing configuration format (json/yaml).
Feature Request:
A converter that would map the existing configurations into pkl templates + modules.
Aware of the complexity of the existing json/yaml configurations, the first versions of the converter could support the simplest mappings && let the configuration authors to convert more complex definitions manually.
Why is there no Neovim in Editor
in pkl.settings
?
There is a plugin for Neovim that could be added.
Would be great if we can use this in C#
Having two validators recurse into eachother blows up with a StackOverflowError
. I don't really expect a fix here, but a better error message (e.g. what was currently being evaluated) would be nice.
PKL code:
class Link {
operationRef: String?((this == null).xor(operationId == null))
operationId: String?((this == null).xor(operationRef == null))
parameters: Mapping<String, Any>
requestBody: unknown?
description: String?
server: Server?
}
(I know I can omit the validator from operationId
as the first one already covers it, initially I thought to add it to both just for some symmetry.)
Full stacktrace here: https://gist.github.com/madisp/f2d8f6edb50b9fccee15e17d87fa35a3
Just play around with pkl. It seems that parsing AST takes a very long time.
TLDR. In my PC, pkl takes 3089 ms, and kotlinx-serialization-properties takes 53 ms.
// benchmark.pkl
a {
b {
c {
d = "Hello World!"
}
}
}
// benchmark.properties
a.b.c.d=Hello World!
I have created a very simple project for benchmarking. (I didn't use kotlinx benchmark or anything else)
The docs on installation currently suggest the following instructions to download the executable:
curl -o pkl https://github.com/apple/pkl/releases/download/0.25.1/pkl-cli-macos-0.25.1.bin
chmod +x pkl
./pkl --version
but the URL https://github.com/apple/pkl/releases/download/0.25.1/pkl-cli-macos-0.25.1.bin
is invalid:
$ curl -I https://github.com/apple/pkl/releases/download/0.25.1/pkl-cli-macos-0.25.1.bin
HTTP/2 404
...
The current release page includes separate ARM vs Intel binaries, which link to eg: https://github.com/apple/pkl/releases/download/0.25.1/pkl-macos-amd64
which itself is a 302 redirect to a https://objects.githubusercontent.com/github-production-release-asset-2e65be/745600812/...
URL containing the actual binary.
I was able to curl -L
the https://github.com/apple/pkl/releases/download/0.25.1/pkl-macos-amd64
URL to get a working binary.
I'm guessing this requires a doc change in or around here:
but possibly a bit of new content explaining which build to choose based on system architecture.Happy to make a PR if it would help!
When trying to load the docs, It gives 404 when requesting /octicons-16.svg on code snippets.
Too lazy to take my Macbook out of my bag, assuming it works on macOS. Working on my remote Linux. So, I concluded this is related to Windows.
> Task :codegen-kotlin:configClasses FAILED
Execution failed for task ':codegen-kotlin:configClasses'.
> Illegal character in opaque part at index 2: G:\Git\apple\pkl-jvm-examples\codegen-kotlin\src\main\resources\Birds.pkl
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 293ms
1 actionable task: 1 executed
It would be nice to generate PKL classes from JSON Schema definitions. Similarly, it can go the other way around from PKL to JSON Schema. I'm aware that the typing will be lost, but since JSON Schema is integrated pretty much everywhere, it can provide interoperability for the language.
This is probably a simple editing error due to some changes that took place as the documentation was being written.
Defining Objects gives an example with dodo birds:
dodo {
name = "Dodo"
taxonomy {
`class` = "Aves"
}
}
But then a subsequent paragraph mentions a different example (emphasis added by me):
Like all values, objects are immutable, which is just a fancy (and short!) way to say that their properties never change. So what happens when Pigeon moves to a different street? Do we have to construct a new object from scratch?
I think the emphasized sentence needs to be rewritten to refer to the dodo bird vs the tortoise in the following section.
The pkl
package, a Configuration as Code language developed by Apple, is not currently available in the NixOS packages.
Include the pkl
package in NixOS packages.
pkl is a Configuration as Code language with rich validation and tooling. Adding it to NixOS packages would benefit users involved in configuration management and development workflows.
Thank you for considering this request.
Subject says all.
Homebrew (https://brew.sh/) is a very popular package manager for macOS where you can find almost any tool you might ever want to install.
The help text output when a crash happens has a URL to help submit a bug report, however this URL is mangled due to a missing newline:
$ echo "a { b = a }" | pkl eval - 2>&1 | head
An unexpected error has occurred. Would you mind filing a bug report?
Cmd+Double-click the link below to open an issue.
Please copy and paste the entire error output into the issue's description, provided you can share it.
https://github.com/apple/pkl/issues/newjava.lang.StackOverflowError
–– Pkl Error ––
Stack overflow
Pkl 0.25.1 (macOS 14.1, native)
The URL is https://github.com/apple/pkl/issues/newjava.lang.StackOverflowError instead of https://github.com/apple/pkl/issues/new.
This seems to be caused by a missing newline at the end of this paragraph:
I can open a separate issue for the stack overflow if needed - seems sometimes this is caught, e.g.:
$ echo "output { value = output }" | pkl eval - 2>&1
–– Pkl Error ––
A stack overflow occurred.
┌─ 4001 repetitions of:
│ 106 | text = renderer.renderDocument(value)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.25.1/stdlib/base.pkl#L106)
└─
When using pkl for object definitions and converting them to JSON format, I encountered an issue where duplicating nested object entries with the same entry names results in generated JSON with duplicate keys, violating JSON standards.
Here is the pkl code defining a series of beverages and their ingredients:
Tea {
Base = "Black Tea"
}
BubbleTea = (Tea) {
Additives {
"Pearls"
}
}
MilkBubbleTea = (BubbleTea) {
Additives {
"Creamer"
}
}
FreshMilkBubbleTea = (BubbleTea) {
Additives {
"Fresh Milk"
}
}
FreshMilkBubbleTea2 = (MilkBubbleTea) {
["Additives"] {
"Fresh Milk"
}
}
When converting to JSON, the process should detect potential duplicate keys resulting from nested object entries with the same name and either halt with an error or provide a warning. This behavior would prevent the generation of invalid JSON formats and ensure data integrity, especially in scenarios involving object inheritance and overriding.
The generated JSON for the FreshMilkBubbleTea2 object includes duplicate Additives keys, as shown below:
{
"Tea": {
"Base": "Black Tea"
},
"BubbleTea": {
"Base": "Black Tea",
"Additives": [
"Pearls"
]
},
"MilkBubbleTea": {
"Base": "Black Tea",
"Additives": [
"Pearls",
"Creamer"
]
},
"FreshMilkBubbleTea": {
"Base": "Black Tea",
"Additives": [
"Pearls",
"Fresh Milk"
]
},
"FreshMilkBubbleTea2": {
"Base": "Black Tea",
"Additives": [
"Pearls",
"Creamer"
],
"Additives": [
"Fresh Milk"
]
}
}
This results in an invalid JSON format since JSON does not allow duplicate keys at the same level.
On main
5 tests are failing. Not sure if there is something else I need to setup. Full log (too long to put in a comment):
https://gist.github.com/jamesward/738f703601fdbac2ef64fa18ef3dd3ef
Create a language server to give an IDE-like experience for any editor with an LSP client.
From the announcement blog post:
In addition, we are also planning on supporting the Language Server Protocol, which will provide a similar level of integration in other editors.
Also mentioned by @holzensp in #46 (comment):
There already is a tree-sitter implementation here. For more advanced support, LSP is actively being looked into.
It has a pkl configuration using bandwidthRequirementPerSecond = 50.mib.toUnit("mb")
, but it output bandwidthRequirementPerSecond = 50.mb
when evaluating.
It should be bandwidthRequirementPerSecond = 52.4288.mb
.
Execution failed for task ':pkl-playground:genKotlin'.
> Pkl union types are not supported by the Kotlin code generator.
Bit of a tall ask, I know, but it'd be wonderful if we could map union types into some form of Kotlin structure.
The docs (like https://pkl-lang.org/main/current/kotlin-binding/codegen.html) say to look in the javadocs / kdocs for more info on using the Java / Kotlin libraries, but the javadoc.jar files are essentially empty, like:
https://repo1.maven.org/maven2/org/pkl-lang/pkl-config-kotlin/0.25.1/pkl-config-kotlin-0.25.1-javadoc.jar
https://repo1.maven.org/maven2/org/pkl-lang/pkl-codegen-kotlin/0.25.1/pkl-codegen-kotlin-0.25.1-javadoc.jar
https://repo1.maven.org/maven2/org/pkl-lang/pkl-codegen-java/0.25.1/pkl-codegen-java-0.25.1-javadoc.jar
Hello, I'm having trouble setting up an offline gradle build.
First I run gradle normally, using the command described in #66 to fetch all dependencies.
Then, I convert the downloaded dependencies into a local maven repository, that I'll call "deps".
And then, I edit the following files:
Changing mavenCentral
into maven { url = uri("/path/to/deps") }
.
Then I try running gradle --offline --no-daemon build
. It manages to run most of the configuration step, showing that it manages to find the dependencies when it looks into the local repo. However, it then fails when trying to resolve dependencies of the step :pkl-cli:runtimeClasspath
with the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':pkl-cli:shadowJar'.
> Could not resolve all dependencies for configuration ':pkl-cli:runtimeClasspath'.
> Did not resolve 'com.github.ajalt.clikt:clikt-jvm:3.5.1' which is part of the dependency lock state
By the looks of the error, it seems that, for some reason, this step is still trying to reach mavenCentral()
instead of deps. How can I change the pkl-cli
repositories into deps
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.