Skip to content

Commit 1d793c3

Browse files
authored
Merge pull request #162 from kiranandcode/kg-env-catalog
Expose `env.catalog` as `env_catalog` method on pantograph.Server
2 parents 0442f08 + bd48882 commit 1d793c3

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

pantograph/server.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,25 @@ async def env_add_async(
409409

410410
env_add = to_sync(env_add_async)
411411

412+
async def env_catalog_async(
413+
self,
414+
module_prefix: str | None = None,
415+
invert_filter: bool = False
416+
) -> list[str]:
417+
"""
418+
Print all symbols in environment.
419+
"""
420+
with tempfile.NamedTemporaryFile('r') as tmp_file:
421+
result = await self.run_async('env.catalog', {
422+
'filename': tmp_file.name,
423+
'modulePrefix': module_prefix,
424+
'invertFilter': invert_filter,
425+
})
426+
if "error" in result:
427+
raise ServerError(result["desc"])
428+
return [line.strip() for line in tmp_file.readlines()]
429+
env_catalog = to_sync(env_catalog_async)
430+
412431
async def env_inspect_async(
413432
self,
414433
name: str,

pantograph/test_server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ def test_env_add_inspect(self):
226226
inspect_result = server.env_inspect(name="mystery")
227227
self.assertEqual(inspect_result['type'], {'pp': 'Nat → Nat'})
228228

229+
def test_env_catalog(self):
230+
server = Server()
231+
server.load_definitions("def foo: Nat -> Nat | 0 => 1 | n + 1 => foo n")
232+
definitions = server.env_catalog(module_prefix="Init", invert_filter=True)
233+
self.assertEqual(
234+
set(definitions),
235+
{'dfoo._sunfold', 'dfoo._unsafe_rec', 'dfoo', 'dfoo.match_1'}
236+
)
237+
229238
def test_env_parse(self):
230239
server = Server()
231240
head, tail = server.env_parse("intro x; apply a", category="tactic")

0 commit comments

Comments
 (0)