Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ Installation of cyjs is pretty simplistic and you can get the released version f
pip install cyjs
```

## Running as a Standalone script

Currently there is a new standalone script if you need
to run javascript directly like with quickjs although
it currently is in it's early phases. It currently uses
[typer](https://typer.tiangolo.com/) as a backend (which was developed by the same people who wrote fastapi which is another popular python package).

```
pip install cyjs[cli]
```

### Using the cli

It should not be difficult although cyjs is still not very mature yet but hopefully the commandline will help to patch a few bugs or make it easier to test different aspects of quickjs-ng.

```
py -m cyjs -e "console.log('Hello Vizonex');"
Hello Vizonex
```


### Using Unreleased Development Versions
If your planning to contribute or want in on anything newly
added you can clone the github repo there is however one
Expand Down
33 changes: 33 additions & 0 deletions cyjs/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pathlib import Path
from typing import Annotated

from typer import Argument, Option, Typer

from ._cyjs import Context

app = Typer()

@app.command()
def cli(
args:Annotated[list[str] | None, Argument(help="Arguments to pass to quickjs script")] = None,
script: Annotated[Path | None, Option("-C", "--script", help="load module as a script", exists=True)] = None,
eval_code: Annotated[str | None, Option("-e", "--eval", metavar="EVAL", help= "evaluate EXPR")] = None,
strict: bool = False,
backtrace_barrier: bool = False,
promise: bool = False
) -> None:
"""A Simplistic script runner for testing code with cyjs"""

ctx = Context()
if args:
ctx.set_script_arguments(*args)
ctx.add_std_print_handlers()

if script:
code = script.read_bytes()
ctx.eval_module(code, script.as_posix(), strict, backtrace_barrier, promise)
elif eval_code:
ctx.eval(eval_code, strict=strict, backtrace_barrier=backtrace_barrier, promise=promise)

if __name__ == "__main__":
app()
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ authors = [
{ name = "Vizonex", email = "VizonexBusiness@gmail.com" }
]
requires-python = ">=3.10"
dependencies = []


[tool.cibuildwheel]
Expand All @@ -28,3 +27,8 @@ version = {attr = "cyjs.__version__"}

[project.urls]
repository = "https://github.com/Vizonex/cyjs.git"

[project.optional-dependencies]
cli = [
"typer>=0.27.2",
]