Skip to content

Commit

Permalink
Merge pull request #44 from inpefess/maintenance
Browse files Browse the repository at this point in the history
Maintenance
  • Loading branch information
inpefess committed Feb 10, 2022
2 parents 01f3274 + 703bfa0 commit d27d668
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 291 deletions.
7 changes: 3 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ jobs:
command: |
. venv/bin/activate
pytest --cov isabelle_client --cov-report xml --cov-fail-under=99\
--junit-xml test-results/isabelle-client.xml isabelle_client\
tests
--junit-xml test-results/isabelle-client.xml isabelle_client
- run:
name: run linters
command: |
. venv/bin/activate
pycodestyle --max-doc-length 160 --ignore E203,E501,W503\
isabelle_client tests examples
isabelle_client examples
pylint --rcfile=.pylintrc isabelle_client examples
- run:
name: run type checks
command: |
. venv/bin/activate
mypy --config-file mypy.ini isabelle_client tests examples
mypy --config-file mypy.ini isabelle_client examples
- run:
name: upload data to codecov
command: |
Expand Down
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ examples/document/
./**/*.log
./**/*.*~
./**/*~
show_report.sh
local-build.sh
./**/.ini
./**/.yml
./**/.toml
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ doc/build/
*.aux
*.cicmauthinsts
.ipynb_checkpoints/
flycheck_*.*
.dir-locals.el
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Python client for Isabelle server
``isabelle-client`` is a TCP client for
`Isabelle <https://isabelle.in.tum.de>`__ server. For more information
about the server see part 4 of `the Isabelle system
manual <https://isabelle.in.tum.de/dist/Isabelle2021/doc/system.pdf>`__.
manual <https://isabelle.in.tum.de/dist/Isabelle2021-1/doc/system.pdf>`__.

How to Install
==============
Expand Down Expand Up @@ -56,7 +56,7 @@ are welcome. To start:
To check the code quality before creating a pull request, one might run
the script
`show_report.sh <https://github.com/inpefess/isabelle-client/blob/master/show_report.sh>`__.
`local-build.sh <https://github.com/inpefess/isabelle-client/blob/master/local-build.sh>`__.
It locally does nearly the same as the CI pipeline after the PR is
created.

Expand Down
27 changes: 23 additions & 4 deletions doc/source/usage-example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,41 @@ In what case to use

This client might be useful if:

* you have an Isabelle server instance running
* you have a machine with Isabelle installed
* you have scripts for automatic generation of theory files in Python
* you want to communicate with the server not using Scala and/or StandardML

First, we need to start an Isabelle server::
In what environment to use
==========================

The client works well in scripts and in Jupyter notebooks. For the latter, one have to first enable nested event loops::


import nest_asyncio

nest_asyncio.apply()
.. warning::
When using `start_isabelle_server <package-documentation.html#isabelle_client.utils.start_isabelle_server>`__ utility function in Python REPL or terminal IPython, shutting the server down within the same session is known to cause a runtime error on exit from the session. This behavious is related to a `well known issue <https://ipython.readthedocs.io/en/stable/interactive/autoawait.html#difference-between-terminal-ipython-and-ipykernel>`__.

Starting Isabelle server
========================

First, we need to start an Isabelle server (doesn't work on Windows)::
from isabelle_client import start_isabelle_server

server_info, _ = start_isabelle_server(
name="test", port=9999, log_file="server.log"
)

We could also start the server outside this script and use its info::
We could also start the server outside this script and use its info (on Windows, this is done in Cygwin)::

isabelle server > server.info

Interacting with Isabelle server
================================

Now let's create a client to our server ::

from isabelle_client import get_isabelle_client
Expand Down
10 changes: 5 additions & 5 deletions conftest.py → isabelle_client/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


class BuggyTCPHandler(socketserver.BaseRequestHandler):
""" a dummy handler to mock bugs in Isabelle server response """
"""a dummy handler to mock bugs in Isabelle server response"""

def handle(self):
request = self.request.recv(1024).decode("utf-8").split("\n")[0]
Expand All @@ -34,7 +34,7 @@ def handle(self):


class DummyTCPHandler(socketserver.BaseRequestHandler):
""" a dummy handler to mock Isabelle server """
"""a dummy handler to mock Isabelle server"""

# pylint: disable=too-many-statements
def handle(self):
Expand All @@ -60,14 +60,14 @@ def handle(self):


class ReusableTCPServer(socketserver.TCPServer):
""" ignore TIME-WAIT during testing """
"""ignore TIME-WAIT during testing"""

allow_reuse_address = True


@fixture(autouse=True, scope="session")
def tcp_servers():
""" a simplistic TCP server mocking Isabelle server behaviour """
"""a simplistic TCP server mocking Isabelle server behaviour"""
with ReusableTCPServer(
("localhost", 9999), DummyTCPHandler
) as server, ReusableTCPServer(
Expand All @@ -84,7 +84,7 @@ def tcp_servers():

@fixture
def mock_logger():
""" a mock for logger to spy on ``info`` calls """
"""a mock for logger to spy on ``info`` calls"""
logger = Mock()
logger.info = Mock()
return logger
16 changes: 8 additions & 8 deletions isabelle_client/isabelle__client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def session_build(
dirs: List[str] = None,
verbose: bool = False,
**kwargs,
) -> IsabelleResponse:
) -> List[IsabelleResponse]:
"""
build a session from ROOT file
Expand Down Expand Up @@ -165,7 +165,7 @@ def session_start(self, session: str = "HOL", **kwargs) -> str:
f"Unexpected response type: {response_list[-1].response_type}"
)

def session_stop(self, session_id: str) -> IsabelleResponse:
def session_stop(self, session_id: str) -> List[IsabelleResponse]:
"""
stop session with given ID
Expand All @@ -187,7 +187,7 @@ def use_theories(
session_id: Optional[str] = None,
master_dir: Optional[str] = None,
**kwargs,
) -> IsabelleResponse:
) -> List[IsabelleResponse]:
"""
run the engine on theory files
Expand Down Expand Up @@ -224,7 +224,7 @@ def use_theories(
self.session_stop(new_session_id)
return response

def echo(self, message: Any) -> IsabelleResponse:
def echo(self, message: Any) -> List[IsabelleResponse]:
"""
asks a server to echo a message
Expand All @@ -243,7 +243,7 @@ def echo(self, message: Any) -> IsabelleResponse:
)
return response

def help(self) -> IsabelleResponse:
def help(self) -> List[IsabelleResponse]:
"""
asks a server to display the list of available commands
Expand All @@ -263,7 +263,7 @@ def purge_theories(
theories: List[str],
master_dir: Optional[str] = None,
purge_all: Optional[bool] = None,
) -> IsabelleResponse:
) -> List[IsabelleResponse]:
"""
asks a server to purge listed theories from it
Expand Down Expand Up @@ -296,7 +296,7 @@ def purge_theories(
)
return response

def cancel(self, task: str) -> IsabelleResponse:
def cancel(self, task: str) -> List[IsabelleResponse]:
"""
asks a server to try to cancel a task with a given ID
Expand All @@ -316,7 +316,7 @@ def cancel(self, task: str) -> IsabelleResponse:
)
return response

def shutdown(self) -> IsabelleResponse:
def shutdown(self) -> List[IsabelleResponse]:
"""
asks a server to shutdown immediately
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion isabelle_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def start_isabelle_server(
start Isabelle server
>>> import os
>>> os.environ["PATH"] = "tests:$PATH"
>>> os.environ["PATH"] = "isabelle_client/resources:$PATH"
>>> print(start_isabelle_server()[0])
server "isabelle" = 127.0.0.1:9999 (password "test_password")
<BLANKLINE>
Expand Down
6 changes: 3 additions & 3 deletions show_report.sh → local-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ make clean html coverage
cat build/coverage/python.txt
cd ..
pycodestyle --max-doc-length 160 --ignore E203,E501,W503 \
${PACKAGE_NAME} tests examples
pylint --rcfile=.pylintrc ${PACKAGE_NAME} tests examples
mypy --config-file mypy.ini ${PACKAGE_NAME} tests examples
${PACKAGE_NAME} examples
pylint --rcfile=.pylintrc ${PACKAGE_NAME} examples
mypy --config-file mypy.ini ${PACKAGE_NAME} examples
pytest --cov ${PACKAGE_NAME} --cov-report term-missing --cov-fail-under=99 \
--junit-xml test-results/isabelle-client.xml ${PACKAGE_NAME}
scc -i py ${PACKAGE_NAME}

0 comments on commit d27d668

Please sign in to comment.