Skip to main content

Python Client for the Alloy Language Server

Project description

PythonAlloyClient

This is a Python client library for interacting with the Alloy Language Server. Currently, it supports checking the syntax of a given Alloy code snippet with the Alloy language server, but more features are planned for the future to make use of the full capabilities of the Alloy language server.

Installation

You can install the package from PyPI using pip.

pip install PythonAlloyClient

Or install directly from the source.

git clone https://github.com/mrigankpawagi/PythonAlloyClient.git
cd PythonAlloyClient
pip install -e .

Requirements

  • Python 3.6+
  • Java Runtime Environment (JRE) for running the Alloy language server

Usage

Basic Usage

from PythonAlloyClient import AlloyServer

server = AlloyServer() # Initialize the server
server.start() # Start the server

syntax_status = server.check_syntax("sig Person {}")
server.stop() # Stop the server

print(syntax_status.success) # True

Once the server is started, you can use the check_syntax method to check the syntax of an Alloy code snippet which is supplied as a string. The method returns a SyntaxStatus object with the following attributes.

  • success (bool): True if the syntax check passed, False otherwise
  • error_type (str): Type of error (always Syntax error for now), None if success is True
  • line_number (int): Line number where the error occurred, None if success is True
  • column_number (int): Column number where the error occurred, None if success is True
  • error_message (str): Error message, None if success is True
  • full_error_message (str): Full error message from Alloy, None if success is True

If a syntax check failed due to an unexpected error, the full_error_message attribute will contain the error message, success will be False, and all other attributes will be None.

Another Example

alloy_code = """
sig X {}
sig A extends X {}
sig A extends X {}
"""
syntax_check = server.check_syntax(alloy_code)

print(syntax_check.success) # False
print(syntax_check.error_type) # Syntax error
print(syntax_check.line_number) # 4
print(syntax_check.column_number) # 5
print(syntax_check.error_message) # "A" is already the name of a sig/parameter in this module.

Custom Alloy Build

By default, PythonAlloyClient uses the JAR file at PythonAlloyClient/resources/org.alloytools.alloy.dist.jar to run the Alloy language server. If you want to use a custom build of the Alloy language server, you can specify the path to the JAR file when initializing the AlloyServer object.

from PythonAlloyClient import AlloyServer

server = AlloyServer(alloy_jar_path="path/to/alloy.jar")

Other Options

PythonAlloyClient can print logs about the server's status and the requests being made to the server by setting the quiet attribute to False. This is set to True by default.

from PythonAlloyClient import AlloyServer

server = AlloyServer(quiet=False)

Development

Setting Up the Development Environment

This project uses pytest for testing. This is listed in requirements.txt and can be installed using pip.

Running Tests

python -m pytest tests/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit Pull Requests or issues.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PythonAlloyClient-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PythonAlloyClient-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file PythonAlloyClient-0.1.0.tar.gz.

File metadata

  • Download URL: PythonAlloyClient-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for PythonAlloyClient-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cba22ebfaadda491c7089ca0f70d9e0d3df03dff95db1b1a0773fbe152a50a17
MD5 b6f7648f753fd42109340236d4c9f1b0
BLAKE2b-256 2f1ce81e0d198fa202f0ec9089bdacb9d4532d52938511cb4203e4177b273e5c

See more details on using hashes here.

File details

Details for the file PythonAlloyClient-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for PythonAlloyClient-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c41cd2443a0425c228fbc3dd8e2b430fc3cf3fc31612b5a70827d7a17f524ef
MD5 845234251b41607c7f90b7fce56974b1
BLAKE2b-256 bc79a774b16de901e319f0175565ddcdfa84f2943f99a52d2e1283a22da9f92e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page