Skip to content

Commit

Permalink
Make conversion scripts compatible on Windows (#65)
Browse files Browse the repository at this point in the history
This makes various "scripts" that read off PWD as compatible on Windows.
  • Loading branch information
bioball authored Jun 17, 2024
1 parent b52aeb2 commit 6edcf46
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/k8s.contrib.crd/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ dependencies {
}

package {
version = "1.0.6"
version = "1.0.7"
}
2 changes: 1 addition & 1 deletion packages/k8s.contrib.crd/PklProject.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"package://pkg.pkl-lang.org/pkl-pantry/org.json_schema.contrib@1": {
"type": "local",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].7",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].8",
"path": "../org.json_schema.contrib"
},
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.syntax@1": {
Expand Down
9 changes: 8 additions & 1 deletion packages/k8s.contrib.crd/generate.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module k8s.contrib.crd.generate

import "pkl:yaml"
import "pkl:semver"
import "pkl:platform"
import "@deepToTyped/deepToTyped.pkl"
import "@uri/URI.pkl"

Expand Down Expand Up @@ -87,7 +88,13 @@ source: String = read("prop:source")
local sourceUri =
if (source.startsWith(Regex(#"\w+:"#))) source // absolute URI
else if (source.startsWith("/")) "file://\(source)" // absolute file path
else "file://\(read("env:PWD"))/\(source)" // relative file path
else // relative file path
let (pwd = read("env:PWD"))
let (path =
if (platform.current.operatingSystem.name == "Windows") "/\(pwd)/\(source)".replaceAll("\\", "/")
else "\(pwd)/\(source)"
)
"file://\(URI.encode(path))"

/// The CRD's source contents, as computed from [source].
sourceContents: String|Resource = read(URI.encode(sourceUri))
Expand Down
3 changes: 2 additions & 1 deletion packages/k8s.contrib/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ dependencies {
["k8s"] {
uri = "package://pkg.pkl-lang.org/pkl-k8s/[email protected]"
}
["uri"] = import("../pkl.experimental.uri/PklProject")
}

package {
version = "1.0.2"
version = "1.0.3"
}
5 changes: 5 additions & 0 deletions packages/k8s.contrib/PklProject.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"checksums": {
"sha256": "75c6d66d94c335417a3c502e107aaeadf7a60b4e1d34b2c979afe11193205a1a"
}
},
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.uri@1": {
"type": "local",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected]",
"path": "../pkl.experimental.uri"
}
}
}
11 changes: 10 additions & 1 deletion packages/k8s.contrib/convert.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ open module k8s.contrib.convert

import "pkl:reflect"
import "pkl:yaml"
import "pkl:platform"

import "@k8s/K8sObject.pkl"
import "@k8s/K8sResource.pkl"
import "@k8s/api/core/v1/ResourceRequirements.pkl"
import "@k8s/k8sSchema.pkl"
import "@uri/URI.pkl"

/// The Kubernetes resources to convert.
///
Expand Down Expand Up @@ -100,7 +103,13 @@ input = read("prop:input")
local inputUri =
if (input.startsWith(Regex(#"\w+:"#))) input // absolute URI
else if (input.startsWith("/")) "file://\(input)" // absolute file path
else "file://\(read("env:PWD"))/\(input)" // relative file path
else // relative file path
let (pwd = read("env:PWD"))
let (path =
if (platform.current.operatingSystem.name == "Windows") "/\(pwd)/\(input)".replaceAll("\\", "/")
else "\(pwd)/\(input)"
)
"file://\(URI.encode(path))"

function resourceConverterFn(resource) =
resourceConverters.fold(resource, (acc, _, f) -> f.apply(acc))
Expand Down
2 changes: 1 addition & 1 deletion packages/org.json_schema.contrib/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ dependencies {
}

package {
version = "1.0.7"
version = "1.0.8"
}
10 changes: 9 additions & 1 deletion packages/org.json_schema.contrib/generate.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
@ModuleInfo { minPklVersion = "0.25.0" }
module org.json_schema.contrib.generate

import "pkl:platform"

import "@jsonschema/Parser.pkl"
import "@jsonschema/JsonSchema.pkl"
import "@uri/URI.pkl"
Expand All @@ -55,7 +57,13 @@ local sourceProperty = read("prop:source")
local sourceUri =
if (sourceProperty.startsWith(Regex(#"\w+:"#))) sourceProperty // absolute URI
else if (sourceProperty.startsWith("/")) "file://\(sourceProperty)" // absolute file path
else "file://\(read("env:PWD"))/\(sourceProperty)" // relative file pat
else // relative file path
let (pwd = read("env:PWD"))
let (path =
if (platform.current.operatingSystem.name == "Windows") "/\(pwd)/\(sourceProperty)".replaceAll("\\", "/")
else "\(pwd)/\(sourceProperty)"
)
"file://\(URI.encode(path))"

local schema = read(URI.encode(sourceUri))

Expand Down
2 changes: 1 addition & 1 deletion packages/pkl.pipe/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
amends "../basePklProject.pkl"

package {
version = "1.0.1"
version = "1.0.2"
}

dependencies {
Expand Down
7 changes: 6 additions & 1 deletion packages/pkl.pipe/PklProject.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"resolvedDependencies": {
"package://pkg.pkl-lang.org/pkl-pantry/k8s.contrib@1": {
"type": "local",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].2",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].3",
"path": "../k8s.contrib"
},
"package://pkg.pkl-lang.org/pkl-k8s/k8s@1": {
Expand All @@ -12,6 +12,11 @@
"checksums": {
"sha256": "75c6d66d94c335417a3c502e107aaeadf7a60b4e1d34b2c979afe11193205a1a"
}
},
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.uri@1": {
"type": "local",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected]",
"path": "../pkl.experimental.uri"
}
}
}

0 comments on commit 6edcf46

Please sign in to comment.