|
1 | 1 | --- |
2 | | -title: x2py Documentation |
3 | | -audience: users, developers, maintainers |
| 2 | +title: x2py |
| 3 | +audience: users |
4 | 4 | prerequisites: none |
5 | | -related: user/index.md, developer/index.md, maintainer/README.md |
| 5 | +related: user/getting-started/index.md, user/getting-started/installation.md |
6 | 6 | status: maintained |
7 | 7 | publication: reviewed |
8 | 8 | --- |
9 | 9 |
|
10 | | -# x2py Documentation |
| 10 | +# x2py |
11 | 11 |
|
12 | | -x2py website documentation is divided into User, Developer, and Maintainer |
13 | | -lanes. Only reviewed lanes and pages appear in the published site. |
| 12 | +x2py turns supported Fortran source into an importable Python extension. It |
| 13 | +also exposes the parsed interface as language-neutral semantic IR and editable |
| 14 | +`.pyi` contracts, so unsupported boundaries are reported before wrapper code is |
| 15 | +compiled. |
14 | 16 |
|
15 | | -## User Documentation |
| 17 | +## Try x2py |
16 | 18 |
|
17 | | -[User documentation](user/index.md) explains how to install x2py, build and use |
18 | | -wrappers, understand generated contracts, diagnose failures, and distribute |
19 | | -artifacts. Start here when x2py is a tool you are using. |
| 19 | +This first example wraps a scalar Fortran function. Create `scale.f90`: |
20 | 20 |
|
21 | | -## Developer Documentation |
| 21 | +<!-- x2py-doc-source: tests/data/fortran/wrapper/scale.f90 --> |
| 22 | +```fortran |
| 23 | +real(8) function scale(value, factor) result(output) |
| 24 | + real(8), intent(in) :: value |
| 25 | + real(8), intent(in) :: factor |
| 26 | + output = value * factor |
| 27 | +end function scale |
| 28 | +``` |
22 | 29 |
|
23 | | -[Developer documentation](developer/index.md) explains how to change x2py, |
24 | | -locate implementation ownership, add features, run focused tests, and prepare a |
25 | | -contribution. Start here when you are modifying the codebase. |
| 30 | +Build the Python extension from the directory containing that file: |
26 | 31 |
|
27 | | -## Maintainer Documentation |
| 32 | +```bash |
| 33 | +python3 -m x2py scale.f90 |
| 34 | +``` |
28 | 35 |
|
29 | | -[Maintainer documentation](maintainer/README.md) records project governance, |
30 | | -accepted design decisions, internal architecture, release policy, and active |
31 | | -roadmaps. |
| 36 | +The command creates an importable `scale` extension beside the source and keeps |
| 37 | +its generated wrapper and build artifacts under `__x2py__/`. Call the native |
| 38 | +function from Python with the exact NumPy scalar types required by its |
| 39 | +contract: |
| 40 | + |
| 41 | +```python |
| 42 | +import numpy as np |
| 43 | + |
| 44 | +import scale |
| 45 | + |
| 46 | +result = scale.scale(np.float64(3.0), np.float64(2.5)) |
| 47 | +print(result) |
| 48 | +``` |
| 49 | + |
| 50 | +The call prints: |
| 51 | + |
| 52 | +```text |
| 53 | +7.5 |
| 54 | +``` |
| 55 | + |
| 56 | +The generated function is inspectable from Python: |
| 57 | + |
| 58 | +```python |
| 59 | +print(scale.scale.__doc__) |
| 60 | +``` |
| 61 | + |
| 62 | +Its docstring describes the public signature, accepted dtypes, result, and |
| 63 | +call-time type error: |
| 64 | + |
| 65 | +```text |
| 66 | +scale(value, factor) -> float64 |
| 67 | +
|
| 68 | +Parameters |
| 69 | +---------- |
| 70 | +value : float64 |
| 71 | +factor : float64 |
| 72 | +
|
| 73 | +Returns |
| 74 | +------- |
| 75 | +result : float64 |
| 76 | +
|
| 77 | +Raises |
| 78 | +------ |
| 79 | +TypeError |
| 80 | + If an argument has an incompatible Python type or dtype. |
| 81 | +``` |
| 82 | + |
| 83 | +That is the basic x2py workflow: provide native source, build an extension, |
| 84 | +import it, and call the generated Python surface. |
| 85 | + |
| 86 | +## Continue With Getting Started |
| 87 | + |
| 88 | +This preview assumes x2py, NumPy, and a supported native compiler are already |
| 89 | +available. [Getting Started](user/getting-started/index.md) walks through |
| 90 | +installation and verification first, then rebuilds this function and explains |
| 91 | +its generated contract and artifacts. |
0 commit comments