a python wrapper for the simplicityhl compiler
run pysimplicityhl.run_from_python to call the SimplicityHL compiler like this:
import os
import json
import pysimplicityhl
if __name__ == "__main__":
basedir = os.path.dirname(__file__)
hl_file = f"'{basedir}/simple.hl'" # contains only a dummy "fn main() {}"
parameter = [
"--debug",
f"{hl_file}",
]
parameter_str = " ".join(parameter) # one single string
result_json= pysimplicityhl.run_from_python(parameter_str)
res = json.loads(result_json)
res["parameter_str"] = parameter_str
print(json.dumps(res, default=str))First build the complete rust project
cargo buildand you should find the binaries in the subfolder target with target folder debug or release.
Now create a python environment ...
python -m venv .venv... and activate it
. .venv/bin/activate # linux/mac
. .venv/Scripts/activate # windows (git-bash)Let poetry add missing libraries with
poetry updateNow build the debug wheel (to be found in folder debug/wheel)
maturin build --manifest-path pysimplicityhl/Cargo.tomlor the release build (to be found in folder relöease/wheel)
maturin build --manifest-path pysimplicityhl/Cargo.toml --releaseA quick install (i.e. a forced reinstall) of the newly compiled wheel could look like this, assuming at least one whl file exists.
poetry run pip install --force-reinstall "$(ls -t target/wheels/pysimplicityhl*.whl | head -n 1)"If you want to do all at once you may test this poe command (make sure the venv is activated)
poetry run poe build-wheelin the demo folder you will several simplicityHL test files like e.g.
the demo file demo/simple.hl which looks like this:
fn main() {}this example will compile to the binary JA== signifying an empty simplicity program.
Running
poetry run python demo/main.pyand should give the results of several test simplicity files being compiled
{
"status": "success",
"program": "JA==",
"parameter_str": "--debug './pysimplicityhl/demo/simple.hl'"
}
{
"status": "success",
"program": "4EkhxS8Oa67l4PQnU9GQOM5f425K8oynz2VMtqrT2Wu0YojxUYhwwDELM4oFrbGHM4qiEiuhMwARVwsGLwpYT2BhULrCX64qRkLLDgFbd+AIYBiA",
"witness": "m++NVW2A5Drn4L7LOn5oOLld7+RYlu1gdbuQNdBsmWRsMTsdPMpjnzMgUiD3LILjdVAYPbBV2h+dtuKPOUguR+U63L7LFh9S0iwNxyt4jytek6RFu6owclyxFl8DzezI",
"parameter_str": "--debug './pysimplicityhl/demo/p2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FA==",
"witness": "eb5mfvncu6xVoGKVzocLBwKb/NstzijZWfKBWxb4F5jGBH+UQe19bTBFQG6VwHzYXHeOS4zvPKerrAm5XHCe5fkwigGSWMMQSTRPhfidUim1MchFg2+ZsIYB8RO84Db5OqkA3bFYVFxox+iX4BSo9RzMXSFf4zMm1XxQaRTGVqHm4QmsY+QXm7KhOu4X9UZCxW30vdZJQUWkxS0RuAJtt4A=",
"parameter_str": "--debug './pysimplicityhl/demo/lastwill.hl' './pysimplicityhl/demo/lastwill.wit'"
}Windows users should note the surrounded quotes when stating filenames with full path (see output key parameter_str)