Skip to content

Commit dbcd463

Browse files
authored
Move pdl-schema.json in src/pdl and add it to the package (#120)
1 parent 692efbd commit dbcd463

File tree

12 files changed

+25
-13
lines changed

12 files changed

+25
-13
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ jobs:
5757
- name: Install dependencies
5858
run: npm install
5959
- name: Generate pdl_ast.d.ts
60-
run: npx json2ts ../pdl-schema.json src/pdl_ast.d.ts --unreachableDefinitions
60+
run: npx json2ts ../src/pdl/pdl-schema.json src/pdl_ast.d.ts --unreachableDefinitions
6161
- name: Build viewer
6262
run: npm run build

.github/workflows/mkdocs-gh-pages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ jobs:
4343
run: npm install
4444
- name: Generate pdl_ast.d.ts
4545
working-directory: ./pdl-live
46-
run: npx json2ts ../pdl-schema.json src/pdl_ast.d.ts --unreachableDefinitions
46+
run: npx json2ts ../src/pdl/pdl-schema.json src/pdl_ast.d.ts --unreachableDefinitions
4747
- name: Build viewer
4848
working-directory: ./pdl-live
4949
run: npm run build
5050
- name: Copy viewer
5151
working-directory: ./pdl-live
5252
run: cp ./dist/bundle.js ../docs/dist/bundle.js
5353
- name: Copy schema
54-
run: cp ./pdl-schema.json ./docs/dist/pdl-schema.json
54+
run: cp ./src/pdl/pdl-schema.json ./docs/dist/pdl-schema.json
5555
# Docs
5656
- name: Setup Pages
5757
uses: actions/configure-pages@v5

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"yaml.schemas": {
3-
"./pdl-schema.json": "*.pdl"
3+
"./src/pdl/pdl-schema.json": "*.pdl"
44
},
55
"files.associations": {
66
"*.pdl": "yaml",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pdl <path/to/example.pdl>
5252

5353
The folder `examples` contains many examples of PDL programs. Several of these examples have been adapted from the LMQL [paper](https://arxiv.org/abs/2212.06094) by Beurer-Kellner et al. The examples cover a variety of prompting patterns such as CoT, RAG, ReAct, and tool use.
5454

55-
We highly recommend using VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language/blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language/blob/main/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using the following `.vscode/settings.json` file:
55+
We highly recommend using VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language/blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language/blob/main/src/pdl/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using the following `.vscode/settings.json` file:
5656

5757
```
5858
{

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pdl <path/to/example.pdl>
5757

5858
The folder `examples` contains many examples of PDL programs. Several of these examples have been adapted from the LMQL [paper](https://arxiv.org/abs/2212.06094) by Beurer-Kellner et al. The examples cover a variety of prompting patterns such as CoT, RAG, ReAct, and tool use.
5959

60-
We highly recommend using VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language/blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language/blob/main/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using the following `./vscode/settings.json` file:
60+
We highly recommend using VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language/blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language/blob/main/src/pdl/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using the following `./vscode/settings.json` file:
6161

6262
```
6363
{

docs/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ See examples of PDL being called programmatically in Python
734734
735735
## Debugging PDL Programs
736736
737-
We highly recommend to use VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language//blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language//blob/main/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using this settings and schema files. The PDL interpreter also provides similar error messages. To make sure that the schema is associated with your PDL files, be sure that `PDL Schemas` appear at the bottom right of your VSCode window, or on top of the editor window. You may also need to install the VSCode extension: `YAML Language Support by Red Hat`.
737+
We highly recommend to use VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language//blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language//blob/main/src/pdl/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using this settings and schema files. The PDL interpreter also provides similar error messages. To make sure that the schema is associated with your PDL files, be sure that `PDL Schemas` appear at the bottom right of your VSCode window, or on top of the editor window. You may also need to install the VSCode extension: `YAML Language Support by Red Hat`.
738738
739739
The interpreter prints out a log by default in the file `log.txt`. This log contains the details of inputs and outputs to every block in the program. It is useful to examine this file when the program is behaving differently than expected.
740740

pdl-live/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ npm install
55

66
Update the type definitions (if needed):
77
```
8-
npx json2ts ../pdl-schema.json src/pdl_ast.d.ts --unreachableDefinitions
8+
npx json2ts ../src/pdl/pdl-schema.json src/pdl_ast.d.ts --unreachableDefinitions
99
```
1010

1111
Automatically format the code

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,7 @@ pdl = "pdl.pdl:main"
6767
version_file = "src/pdl/_version.py"
6868

6969
[tool.setuptools.packages.find]
70-
where = ["src"]
70+
where = ["src"]
71+
72+
[tool.setuptools.package-data]
73+
pdl = ["pdl-schema.json"]
File renamed without changes.

src/pdl/pdl_parser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ def parse_str(pdl_str: str, file_name: str = "") -> tuple[Program, LocationType]
2626
try:
2727
prog = Program.model_validate(prog_yaml)
2828
except ValidationError as exc:
29-
with open("pdl-schema.json", "r", encoding="utf-8") as schema_file:
30-
schema = json.load(schema_file)
29+
pdl_schema_file = Path(__file__).parent / "pdl-schema.json"
30+
with open(pdl_schema_file, "r", encoding="utf-8") as schema_fp:
31+
schema = json.load(schema_fp)
3132
defs = schema["$defs"]
3233
errors = analyze_errors(defs, defs["Program"], prog_yaml, loc)
34+
if errors == []:
35+
errors = ["The file do not respect the schema."]
3336
raise PDLParseError(errors) from exc
3437
return prog, loc

tests/test_errors.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import json
2+
from pathlib import Path
23

34
from pydantic import ValidationError
45

6+
import pdl.pdl
57
from pdl.pdl_ast import Program, empty_block_location
68
from pdl.pdl_interpreter import InterpreterState, empty_scope, process_prog
79
from pdl.pdl_schema_error_analyzer import analyze_errors
@@ -13,7 +15,8 @@ def error(raw_data, assertion):
1315
data = Program.model_validate(raw_data)
1416
_, _, _, _ = process_prog(state, empty_scope, data)
1517
except ValidationError:
16-
with open("pdl-schema.json", "r", encoding="utf-8") as schemafile:
18+
pdl_schema_file = Path(pdl.pdl.__file__).parent / "pdl-schema.json"
19+
with open(pdl_schema_file, "r", encoding="utf-8") as schemafile:
1720
schema = json.load(schemafile)
1821
defs = schema["$defs"]
1922
errors = analyze_errors(

tests/test_schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import json
2+
from pathlib import Path
23

34
from pydantic.json_schema import models_json_schema
45

6+
import pdl.pdl
57
from pdl.pdl_ast import PdlBlock, PdlBlocks, Program
68

79

@@ -15,6 +17,7 @@ def test_saved_schema():
1517
title="PDL Schemas",
1618
)
1719
current_schema["anyOf"] = list(top.values())
18-
with open("pdl-schema.json", "r", encoding="utf-8") as fd:
20+
pdl_schema_file = Path(pdl.pdl.__file__).parent / "pdl-schema.json"
21+
with open(pdl_schema_file, "r", encoding="utf-8") as fd:
1922
saved_schema = json.load(fd)
2023
assert current_schema == saved_schema

0 commit comments

Comments
 (0)