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
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
activate-environment: astx
auto-update-conda: true
conda-solver: libmamba
python-version: "3.9.*"
python-version: "3.10.*"

- name: Install deps
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ jobs:
fail-fast: false
matrix:
python_version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
os:
- "ubuntu"
- "macos"
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
activate-environment: astx
auto-update-conda: true
conda-solver: libmamba
python-version: "3.9"
python-version: "3.10"

- name: Install dependencies
run: |
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ Install ASTx from PyPI:
pip install astx
```

For ASCII visualization in the console (via `mermaid-ascii`), install with the
`console` extra:

```bash
pip install 'astx[console]'
```

Or install all optional dependencies:

```bash
pip install 'astx[all]'
```

---

## 📖 Overview
Expand Down Expand Up @@ -123,7 +136,8 @@ def add(x: int, y: int) -> int:
- Graphical visualization (PNG or ASCII)

In a Jupyter Notebook, the default graphical visualization is **PNG**, while in
a console, the default is **ASCII**.
a console, the default is **ASCII** (requires `pip install 'astx[console]'`).
Without the `console` extra, console output falls back to **YAML**.

You can also print the AST structure in **JSON** or **YAML** format. For
example:
Expand Down
2 changes: 1 addition & 1 deletion conda/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- nodefaults
- conda-forge
dependencies:
- python >=3.9,<3.14
- python >=3.10
- poetry >=2
- nodejs >=18.17 # used by semantic-release
- shellcheck
Expand Down
18 changes: 18 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ $ pip install astx
This is the preferred method to install ASTx, as it will always install the most
recent stable release.

### Optional dependencies

For ASCII visualization of the AST in the console (using `mermaid-ascii`),
install with the `console` extra:

```bash
$ pip install 'astx[console]'
```

Or install all optional dependencies at once:

```bash
$ pip install 'astx[all]'
```

Without the `console` extra, the console representation falls back to YAML
output.

If you don't have [pip](https://pip.pypa.io) installed, this
[Python installation guide](http://docs.python-guide.org/en/latest/starting/installation/)
can guide you through the process.
Expand Down
16 changes: 15 additions & 1 deletion libs/astx-transpilers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ Install ASTx from PyPI:
pip install astx
```

For ASCII visualization in the console (via `mermaid-ascii`), install with the
`console` extra:

```bash
pip install 'astx[console]'
```

Or install all optional dependencies:

```bash
pip install 'astx[all]'
```

---

## 📖 Overview
Expand Down Expand Up @@ -123,7 +136,8 @@ def add(x: int, y: int) -> int:
- Graphical visualization (PNG or ASCII)

In a Jupyter Notebook, the default graphical visualization is **PNG**, while in
a console, the default is **ASCII**.
a console, the default is **ASCII** (requires `pip install 'astx[console]'`).
Without the `console` extra, console output falls back to **YAML**.

You can also print the AST structure in **JSON** or **YAML** format. For
example:
Expand Down
3 changes: 1 addition & 2 deletions libs/astx-transpilers/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ authors = [
{name = "Ivan Ogasawara", email = "ivan.ogasawara@gmail.com"}
]
license = "BSD 3 Clause"
requires-python = ">=3.9,<4"
requires-python = ">=3.10,<4"
dependencies = [
"atpublic >= 4.0",
"plum-dispatch >= 2",
"typeguard >= 4",
"eval-type-backport >=0.2 ; python_version < '3.10'",
"astx == 0.23.1", # semantic-release
]

Expand Down
16 changes: 15 additions & 1 deletion libs/astx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ Install ASTx from PyPI:
pip install astx
```

For ASCII visualization in the console (via `mermaid-ascii`), install with the
`console` extra:

```bash
pip install 'astx[console]'
```

Or install all optional dependencies:

```bash
pip install 'astx[all]'
```

---

## 📖 Overview
Expand Down Expand Up @@ -123,7 +136,8 @@ def add(x: int, y: int) -> int:
- Graphical visualization (PNG or ASCII)

In a Jupyter Notebook, the default graphical visualization is **PNG**, while in
a console, the default is **ASCII**.
a console, the default is **ASCII** (requires `pip install 'astx[console]'`).
Without the `console` extra, console output falls back to **YAML**.

You can also print the AST structure in **JSON** or **YAML** format. For
example:
Expand Down
10 changes: 6 additions & 4 deletions libs/astx/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ authors = [
{name = "Ivan Ogasawara", email = "ivan.ogasawara@gmail.com"}
]
license = "BSD 3 Clause"
requires-python = ">=3.9,<4"
requires-python = ">=3.10,<4"
dependencies = [
"atpublic >= 4.0",
"plum-dispatch >= 2",
"typeguard >= 4",
"typing-extensions >=4 ; python_version < '3.9'",
"eval-type-backport >=0.2 ; python_version < '3.10'",
"mermaid-ascii (>=0.6.1)",
"typing-extensions >= 4",
]

[project.optional-dependencies]
console = ["mermaid-ascii >=0.6.1"]
all = ["mermaid-ascii >=0.6.1"]


[build-system]
requires = ["poetry-core>=2"]
Expand Down
18 changes: 4 additions & 14 deletions libs/astx/src/astx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,17 @@
Iterator,
List,
Optional,
TypeAlias,
Union,
cast,
)

from astx.tools.typing import typechecked

try:
from typing_extensions import TypeAlias
except ImportError:
from typing import TypeAlias # type: ignore[no-redef,attr-defined]


try:
from typing_extensions import TypeVar
except ImportError:
from typing import TypeVar # type: ignore[assignment]


import yaml

from public import public
from typing_extensions import TypeVar

from astx.tools.typing import typechecked

ASTType = TypeVar("ASTType", bound="AST", default="AST")

Expand Down
7 changes: 1 addition & 6 deletions libs/astx/src/astx/mixes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
"""Module for mixing ASTx types from different modules."""

from typing import Union

try:
from typing import TypeAlias # type: ignore
except ImportError:
from typing_extensions import TypeAlias
from typing import TypeAlias, Union

from astx.base import DataType
from astx.callables import FunctionDef
Expand Down
17 changes: 8 additions & 9 deletions libs/astx/src/astx/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,9 @@ def visualize_image(ast: ReprStruct, direction: Direction = "TD") -> None:
)


def _find_mermaid_ascii() -> str:
"""Resolve the `mermaid-ascii` CLI path or raise a clear error."""
exe = shutil.which("mermaid-ascii") or shutil.which("mermaid-ascii.exe")
if not exe:
raise RuntimeError(
"mermaid-ascii CLI not found. Install the PyPI package that ships "
"the binary, or put `mermaid-ascii` on PATH."
)
return exe
def _find_mermaid_ascii() -> Optional[str]:
"""Resolve the `mermaid-ascii` CLI path or return None."""
return shutil.which("mermaid-ascii") or shutil.which("mermaid-ascii.exe")


def visualize_ascii(
Expand All @@ -169,6 +163,11 @@ def visualize_ascii(
- pipe-labeled edges (--> |label| ...)
"""
exe = _find_mermaid_ascii()
if exe is None:
import yaml

return str(yaml.dump(ast, sort_keys=False))

src = ast_to_mermaid_ascii(ast, direction=direction)

cmd = [exe]
Expand Down
Loading
Loading