Skip to content

Commit cac5081

Browse files
committed
Use tree-sitter prebuild python package
Signed-off-by: Andrew Helwer <[email protected]>
1 parent 2722b27 commit cac5081

9 files changed

+23
-38
lines changed

.github/scripts/check_manifest_features.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from typing import Any
1616
import re
1717
import tla_utils
18+
import tree_sitter_tlaplus
19+
from tree_sitter import Language, Parser
1820

1921
logging.basicConfig(level=logging.INFO)
2022

@@ -228,14 +230,16 @@ def check_features(parser, queries, manifest, examples_root):
228230
if __name__ == '__main__':
229231
parser = ArgumentParser(description='Checks metadata in tlaplus/examples manifest.json against module and model files in repository.')
230232
parser.add_argument('--manifest_path', help='Path to the tlaplus/examples manifest.json file', required=True)
231-
parser.add_argument('--ts_path', help='Path to tree-sitter-tlaplus directory', required=True)
233+
parser.add_argument('--ts_path', help='[DEPRECATED, UNUSED] Path to tree-sitter-tlaplus directory', required=False)
232234
args = parser.parse_args()
233235

234236
manifest_path = normpath(args.manifest_path)
235237
manifest = tla_utils.load_json(manifest_path)
236238
examples_root = dirname(manifest_path)
237239

238-
(TLAPLUS_LANGUAGE, parser) = tla_utils.build_ts_grammar(normpath(args.ts_path))
240+
TLAPLUS_LANGUAGE = Language(tree_sitter_tlaplus.language(), 'tlaplus')
241+
parser = Parser()
242+
parser.set_language(TLAPLUS_LANGUAGE)
239243
queries = build_queries(TLAPLUS_LANGUAGE)
240244

241245
if check_features(parser, queries, manifest, examples_root):

.github/scripts/generate_manifest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pathlib import PureWindowsPath
1414
import glob
1515
import tla_utils
16+
from tree_sitter import Language, Parser
1617

1718
def to_posix(path):
1819
"""
@@ -165,15 +166,17 @@ def integrate_old_manifest_into_new(old_manifest, new_manifest):
165166
parser = ArgumentParser(description='Generates a new manifest.json derived from files in the repo.')
166167
parser.add_argument('--manifest_path', help='Path to the current tlaplus/examples manifest.json file', default='manifest.json')
167168
parser.add_argument('--ci_ignore_path', help='Path to the CI ignore file', default='.ciignore')
168-
parser.add_argument('--ts_path', help='Path to tree-sitter-tlaplus directory', default='tree-sitter-tlaplus')
169+
parser.add_argument('--ts_path', help='[DEPRECATED, UNUSED] Path to tree-sitter-tlaplus directory', required=False)
169170
args = parser.parse_args()
170171

171172
manifest_path = normpath(args.manifest_path)
172173
examples_root = dirname(manifest_path)
173174
ci_ignore_path = normpath(args.ci_ignore_path)
174175
ignored_dirs = tla_utils.get_ignored_dirs(ci_ignore_path)
175176

176-
(TLAPLUS_LANGUAGE, parser) = tla_utils.build_ts_grammar(normpath(args.ts_path))
177+
TLAPLUS_LANGUAGE = Language(tree_sitter_tlaplus.language(), 'tlaplus')
178+
parser = Parser()
179+
parser.set_language(TLAPLUS_LANGUAGE)
177180
queries = build_queries(TLAPLUS_LANGUAGE)
178181

179182
old_manifest = tla_utils.load_json(manifest_path)

.github/scripts/linux-setup.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ main() {
3737
fi
3838
# Put all dependencies in their own directory to ensure they aren't included implicitly
3939
mkdir -p "$DEPS_DIR"
40-
# Get tree-sitter-tlaplus
41-
wget -nv https://github.com/tlaplus-community/tree-sitter-tlaplus/archive/main.tar.gz -O /tmp/tree-sitter-tlaplus.tar.gz
42-
tar -xzf /tmp/tree-sitter-tlaplus.tar.gz --directory "$DEPS_DIR"
43-
mv "$DEPS_DIR/tree-sitter-tlaplus-main" "$DEPS_DIR/tree-sitter-tlaplus"
4440
# Get TLA⁺ tools
4541
mkdir -p "$DEPS_DIR/tools"
4642
wget -nv http://nightly.tlapl.us/dist/tla2tools.jar -P "$DEPS_DIR/tools"

.github/scripts/requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
jsonschema == 4.20.0
2-
tree-sitter==0.20.4
1+
jsonschema==4.20.0
32
mistletoe==1.2.1
3+
tree-sitter
4+
tree-sitter-tlaplus
45

.github/scripts/tla_utils.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import datetime
22
import json
33
from os.path import join, normpath, pathsep
4-
from tree_sitter import Language, Parser
54
import subprocess
65
import re
76

@@ -51,17 +50,6 @@ def write_json(data, path):
5150
with open(path, 'w', encoding='utf-8') as file:
5251
json.dump(data, file, indent=2, ensure_ascii=False)
5352

54-
def build_ts_grammar(ts_path):
55-
"""
56-
Builds the tree-sitter-tlaplus grammar and constructs the parser.
57-
"""
58-
ts_build_path = join(ts_path, 'build', 'tree-sitter-languages.so')
59-
Language.build_library(ts_build_path, [ts_path])
60-
TLAPLUS_LANGUAGE = Language(ts_build_path, 'tlaplus')
61-
parser = Parser()
62-
parser.set_language(TLAPLUS_LANGUAGE)
63-
return (TLAPLUS_LANGUAGE, parser)
64-
6553
def parse_module(examples_root, parser, path):
6654
"""
6755
Parses a .tla file; returns the parse tree along with whether a parse

.github/scripts/unicode_number_set_shim.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from os.path import dirname, normpath, join
1414
import tla_utils
1515
from typing import List
16+
import tree_sitter_tlaplus
17+
from tree_sitter import Language, Parser
1618

1719
logging.basicConfig(level=logging.INFO)
1820

@@ -115,7 +117,7 @@ def write_module(examples_root, module_path, module_bytes):
115117
if __name__ == '__main__':
116118
parser = ArgumentParser(description='Adds ℕ/ℤ/ℝ Unicode number set shim definitions to modules as needed.')
117119
parser.add_argument('--manifest_path', help='Path to the tlaplus/examples manifest.json file', required=True)
118-
parser.add_argument('--ts_path', help='Path to tree-sitter-tlaplus directory', required=True)
120+
parser.add_argument('--ts_path', help='[DEPRECATED, UNUSED] Path to tree-sitter-tlaplus directory', required=False)
119121
parser.add_argument('--skip', nargs='+', help='Space-separated list of .tla modules to skip', required=False, default=[])
120122
parser.add_argument('--only', nargs='+', help='If provided, only modify models in this space-separated list', required=False, default=[])
121123
args = parser.parse_args()
@@ -126,7 +128,9 @@ def write_module(examples_root, module_path, module_bytes):
126128
skip_modules = [normpath(path) for path in args.skip]
127129
only_modules = [normpath(path) for path in args.only]
128130

129-
(TLAPLUS_LANGUAGE, parser) = tla_utils.build_ts_grammar(normpath(args.ts_path))
131+
TLAPLUS_LANGUAGE = Language(tree_sitter_tlaplus.language(), 'tlaplus')
132+
parser = Parser()
133+
parser.set_language(TLAPLUS_LANGUAGE)
130134
imports_query = build_imports_query(TLAPLUS_LANGUAGE)
131135

132136
modules = [

.github/scripts/windows-setup.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ main() {
3434
fi
3535
# Put all dependencies in their own directory to ensure they aren't included implicitly
3636
mkdir -p "$DEPS_DIR"
37-
# Get tree-sitter-tlaplus
38-
curl -L https://github.com/tlaplus-community/tree-sitter-tlaplus/archive/main.zip --output tree-sitter-tlaplus.zip
39-
7z x tree-sitter-tlaplus.zip
40-
mv tree-sitter-tlaplus-main "$DEPS_DIR/tree-sitter-tlaplus"
41-
rm tree-sitter-tlaplus.zip
4237
# Get TLA⁺ tools
4338
mkdir -p "$DEPS_DIR/tools"
4439
curl http://nightly.tlapl.us/dist/tla2tools.jar --output "$DEPS_DIR/tools/tla2tools.jar"

.github/workflows/CI.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ jobs:
5656
- name: Check manifest feature flags
5757
run: |
5858
python "$SCRIPT_DIR/check_manifest_features.py" \
59-
--manifest_path manifest.json \
60-
--ts_path $DEPS_DIR/tree-sitter-tlaplus
59+
--manifest_path manifest.json
6160
- name: Check README spec table
6261
run: |
6362
python "$SCRIPT_DIR/check_markdown_table.py" \
@@ -73,7 +72,6 @@ jobs:
7372
if: matrix.unicode
7473
run: |
7574
python "$SCRIPT_DIR/unicode_number_set_shim.py" \
76-
--ts_path "$DEPS_DIR/tree-sitter-tlaplus" \
7775
--manifest_path manifest.json
7876
- name: Translate PlusCal
7977
if: (!matrix.unicode) # PlusCal does not yet support unicode
@@ -174,7 +172,6 @@ jobs:
174172
rm -r $DEPS_DIR/tree-sitter-tlaplus/build
175173
python $SCRIPT_DIR/generate_manifest.py \
176174
--manifest_path manifest.json \
177-
--ci_ignore_path .ciignore \
178-
--ts_path $DEPS_DIR/tree-sitter-tlaplus
175+
--ci_ignore_path .ciignore
179176
git diff -a
180177

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,8 @@ Follow these instructions:
157157
To combat bitrot, it is important to add your spec and model to the continuous integration system.
158158
To do this, you'll have to update the [`manifest.json`](manifest.json) file with machine-readable records of your spec files.
159159
If this process doesn't work for you, you can alternatively modify the [`.ciignore`](.ciignore) file to exclude your spec from validation.
160-
Otherwise, follow these directions:
160+
Modifying the `manifest.json` can be done manually or (recommended) following these directions:
161161
1. Ensure you have Python 3.11+ installed
162-
1. Download & extract tree-sitter-tlaplus ([zip](https://github.com/tlaplus-community/tree-sitter-tlaplus/archive/refs/heads/main.zip), [tar.gz](https://github.com/tlaplus-community/tree-sitter-tlaplus/archive/refs/heads/main.tar.gz)) to the root of the repository; ensure the extracted folder is named `tree-sitter-tlaplus`
163-
1. Open a shell and navigate to the repo root; ensure a C++ compiler is installed and on your path
164-
- On Windows, this might entail running the below script from the visual studio developer command prompt
165162
1. It is considered best practice to create & initialize a Python virtual environment to preserve your system package store; run `python -m venv .` then `source ./bin/activate` on Linux & macOS or `.\Scripts\activate.bat` on Windows (run `deactivate` to exit)
166163
1. Run `pip install -r .github/scripts/requirements.txt`
167164
1. Run `python .github/scripts/generate_manifest.py`

0 commit comments

Comments
 (0)