Merge pull request 'Usage documentation' (#7) from feat/usage-documentation into main
Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
79
README.md
79
README.md
@@ -5,3 +5,82 @@
|
|||||||
*Midas* aims at providing Python developers with a simple annotation system to enable compile-time integrity and data type checks, as well as generating runtime assertions.
|
*Midas* aims at providing Python developers with a simple annotation system to enable compile-time integrity and data type checks, as well as generating runtime assertions.
|
||||||
|
|
||||||
This framework is being developed as part of a Bachelor's Thesis by Louis Heredero at HEI Sion.
|
This framework is being developed as part of a Bachelor's Thesis by Louis Heredero at HEI Sion.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Python 3.11+
|
||||||
|
- [uv](https://docs.astral.sh/uv/getting-started/installation/)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Clone the repository
|
||||||
|
```shell
|
||||||
|
git clone https://git.kb28.ch/HEL/midas.git
|
||||||
|
```
|
||||||
|
2. Go in the project directory
|
||||||
|
```shell
|
||||||
|
cd midas
|
||||||
|
```
|
||||||
|
3. Install the CLI as a user-wide tool
|
||||||
|
```shell
|
||||||
|
uv tool install .
|
||||||
|
```
|
||||||
|
4. You can now run the `midas` command from anywhere
|
||||||
|
```shell
|
||||||
|
midas --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
### Compiling
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> In the current state of the project, the `compile` command doesn't generate any runnable code, it only runs the parsers and type checker on the provided files
|
||||||
|
|
||||||
|
```shell
|
||||||
|
midas compile -t types.midas source.py
|
||||||
|
```
|
||||||
|
|
||||||
|
With the `compile` command, you can process a source Python file, with any number of custom type definition files (`-t FILE` option), and the type checker will verify the coherence of your program and generate the runnable code with valid syntax and runtime assertions.
|
||||||
|
|
||||||
|
The optional `-l FILE` option lets you produce a highlighted version of the source code showing diagnostics from the type checker (see [Highlighting](#highlighting))
|
||||||
|
|
||||||
|
### Highlighting
|
||||||
|
|
||||||
|
```shell
|
||||||
|
midas utils highlight source.py
|
||||||
|
# or
|
||||||
|
midas utils highlight types.midas
|
||||||
|
```
|
||||||
|
|
||||||
|
The `highlight` command takes in a source file (Python or Midas), runs the appropriate parser and outputs an HTML file containing the source code with added highlighting. This highlighting takes the form of hoverable annotations showing some of the parsed structures (e.g. a function definition, an assignment, a generic type, etc.)
|
||||||
|
|
||||||
|
The optional `-o FILE` option can be used to specify an output path. By default, the file is printed in stdout (equivalent to `-o -`).
|
||||||
|
|
||||||
|
### Dumping the AST
|
||||||
|
|
||||||
|
```shell
|
||||||
|
midas utils dump-ast source.py
|
||||||
|
# or
|
||||||
|
midas utils dump-ast types.midas
|
||||||
|
```
|
||||||
|
|
||||||
|
For debugging purposes, you can output the AST parsed from a Python or Midas file. For Python files, the `-p` flags lets you toggle the custom AST parsing. Without `-p`, the raw AST is returned, as produced by the builtin `ast` module. This flag has no effect on Midas files.
|
||||||
|
|
||||||
|
The optional `-o FILE` option can be used to specify an output path. By default, the file is printed in stdout (equivalent to `-o -`).
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
Several snapshot tests are available to assert the good behaviour of the parsers and type checker. They can be run as follows:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
uv run -m tests.midas run -a
|
||||||
|
uv run -m tests.python run -a
|
||||||
|
uv run -m tests.checker run -a
|
||||||
|
```
|
||||||
|
|
||||||
|
**Available subcommands:**
|
||||||
|
- Run all tests: `run -a`
|
||||||
|
- Run specific tests: `run tests/cases/test1.py tests/cases/test2.py ...`
|
||||||
|
- Update all tests: `update -a`
|
||||||
|
- Update specific tests: `update tests/cases/test1.py tests/cases/test2.py ...`
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from midas.utils import UniversalJSONDumper
|
|||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def midas():
|
def midas():
|
||||||
click.echo("Welcome to Midas!")
|
pass
|
||||||
|
|
||||||
|
|
||||||
@midas.command()
|
@midas.command()
|
||||||
|
|||||||
@@ -141,3 +141,9 @@ class Tester(ABC):
|
|||||||
success = tester.run_tests(args.FILE)
|
success = tester.run_tests(args.FILE)
|
||||||
if not success:
|
if not success:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
case None:
|
||||||
|
print("No subcommand provided. Available subcommands: run, update")
|
||||||
|
sys.exit(1)
|
||||||
|
case _:
|
||||||
|
print(f"Unknown subcommand '{args.subcommand}'")
|
||||||
|
sys.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user