Skip to content

Commit 2e7ee90

Browse files
authored
Merge pull request #24 from inpefess/server-start-parameters
Server start parameters
2 parents 0b0c844 + cd2f252 commit 2e7ee90

File tree

7 files changed

+103
-14
lines changed

7 files changed

+103
-14
lines changed

doc/source/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
author = "Boris Shminke"
3535

3636
# The full version, including alpha/beta/rc tags
37-
release = "0.1.5"
37+
release = "0.2.0"
3838

3939

4040
# -- General configuration ---------------------------------------------------

examples/example.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
def main():
2323
""" using ``isabelle`` client """
2424
# first, we start Isabelle server
25-
server_info, _ = start_isabelle_server()
25+
server_info, _ = start_isabelle_server(
26+
name="test", port="9999", log_file="server.log"
27+
)
2628
isabelle = get_isabelle_client(server_info)
27-
# we will log all the messages from the server to stdout
29+
# we will log all the messages from the server to a file
2830
isabelle.logger = logging.getLogger()
2931
isabelle.logger.setLevel(logging.INFO)
30-
isabelle.logger.addHandler(logging.FileHandler("out.log"))
32+
isabelle.logger.addHandler(logging.FileHandler("session.log"))
3133
# now we can send a theory file from this directory to the server
3234
# and get a response
3335
isabelle.use_theories(

examples/tty.gif

-490 KB
Loading
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Copyright 2021 Boris Shminke
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
import time
17+
18+
with open("video_example/example.txt", "r") as example:
19+
lines = example.readlines()
20+
21+
for line in lines:
22+
if line[:6] == "SLEEP ":
23+
time.sleep(int(line[6:]))
24+
else:
25+
for char in line:
26+
print(char, end="", flush=True)
27+
time.sleep(60 / 600)

examples/video_example/example.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Hi! This is an example of using ``isabelle-client`` package
2+
python
3+
# first, we need to start an Isabelle server
4+
from isabelle_client import start_isabelle_server
5+
6+
server_info, _ = start_isabelle_server(
7+
name="test", port=9999, log_file="server.log"
8+
)
9+
SLEEP 1
10+
# we could also start the server outside this scrit and use its info
11+
# now let's create a client to our server
12+
from isabelle_client import get_isabelle_client
13+
14+
isabelle = get_isabelle_client(server_info)
15+
# we will log all the messages from the server to a file
16+
import logging
17+
18+
isabelle.logger = logging.getLogger()
19+
isabelle.logger.setLevel(logging.INFO)
20+
isabelle.logger.addHandler(logging.FileHandler("session.log"))
21+
# let's suppose that we also have another Python script which generates some
22+
# theory files
23+
# now we can build a session document using ROOT and root.tex files
24+
isabelle.session_build(dirs=["."], session="examples")
25+
SLEEP 3
26+
# note that the client returns only the last reply from the server
27+
# all other messages are saved to the log file
28+
# we also can issue a free-form command through TCP
29+
import asyncio
30+
31+
asyncio.run(isabelle.execute_command("echo 42", asynchronous=False))
32+
exit()
33+
# our sessions was logged to the file:
34+
cat session.log & sleep 3
35+
SLEEP 3
36+
bye

isabelle_client/utils.py

+32-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""
1616
import asyncio
1717
import re
18-
from typing import Tuple
18+
from typing import Optional, Tuple
1919

2020
from isabelle_client.isabelle__client import IsabelleClient
2121

@@ -45,9 +45,11 @@ def get_isabelle_client(server_info: str) -> IsabelleClient:
4545
return isabelle_client
4646

4747

48-
async def async_start_isabelle_server() -> Tuple[
49-
str, asyncio.subprocess.Process
50-
]:
48+
async def async_start_isabelle_server(
49+
log_file: Optional[str] = None,
50+
name: Optional[str] = None,
51+
port: Optional[int] = None,
52+
) -> Tuple[str, asyncio.subprocess.Process]:
5153
"""
5254
a technical function
5355
@@ -64,21 +66,39 @@ async def async_start_isabelle_server() -> Tuple[
6466
>>> server.stdout = None
6567
>>> server_builder = AsyncMock(return_value=server)
6668
>>> with patch("asyncio.create_subprocess_exec", server_builder):
67-
... print(asyncio.run(async_start_isabelle_server())[0])
69+
... print(asyncio.run(
70+
... async_start_isabelle_server("out.log", "isabelle", 10000)
71+
... )[0])
6872
Traceback (most recent call last):
6973
...
7074
ValueError: Failed to start server
75+
76+
:param log_file: a log file for exceptional output of internal server and
77+
session operations
78+
:param name: explicit server name (default: isabelle)
79+
:param port: explicit server port
80+
:returns: a line of server info and server process
7181
"""
82+
args = (
83+
"server"
84+
+ (f" -L {log_file}" if log_file is not None else "")
85+
+ (f" -p {str(port)}" if port is not None else "")
86+
+ (f" -n {name}" if name is not None else "")
87+
)
7288
isabelle_server = await asyncio.create_subprocess_exec(
73-
"isabelle", "server", stdout=asyncio.subprocess.PIPE
89+
"isabelle", *(args.split(" ")), stdout=asyncio.subprocess.PIPE
7490
)
7591
if isabelle_server.stdout is None:
7692
raise ValueError("Failed to start server")
7793
server_info = (await isabelle_server.stdout.readline()).decode("utf-8")
7894
return server_info, isabelle_server
7995

8096

81-
def start_isabelle_server() -> Tuple[str, asyncio.subprocess.Process]:
97+
def start_isabelle_server(
98+
log_file: Optional[str] = None,
99+
name: Optional[str] = None,
100+
port: Optional[int] = None,
101+
) -> Tuple[str, asyncio.subprocess.Process]:
82102
"""
83103
start ``isabelle`` server
84104
@@ -90,6 +110,10 @@ def start_isabelle_server() -> Tuple[str, asyncio.subprocess.Process]:
90110
... print(start_isabelle_server())
91111
TestIsabelleServer
92112
113+
:param log_file: a log file for exceptional output of internal server and
114+
session operations
115+
:param name: explicit server name (default: isabelle)
116+
:param port: explicit server port
93117
:return: a line of server info and server process
94118
"""
95-
return asyncio.run(async_start_isabelle_server())
119+
return asyncio.run(async_start_isabelle_server(log_file, name, port))

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "isabelle-client"
3-
version = "0.1.5"
3+
version = "0.2.0"
44
description = "A client to Isabelle proof assistant server"
55
authors = ["Boris Shminke <boris@shminke.ml>"]
66
license = "Apache-2.0"
@@ -11,7 +11,7 @@ classifiers=[
1111
"License :: OSI Approved :: Apache Software License",
1212
"Operating System :: OS Independent",
1313
"Intended Audience :: Science/Research",
14-
"Development Status :: 2 - Pre-Alpha",
14+
"Development Status :: 3 - Alpha",
1515
"Environment :: Console",
1616
"Natural Language :: English",
1717
"Topic :: Scientific/Engineering :: Artificial Intelligence",

0 commit comments

Comments
 (0)