| title | Common Beginner Workflow |
|---|---|
| description | Recommended development loop — edit, review contract, build, test, and rebuild |
| audience | users |
| prerequisites | first wrapped function |
| related | ../guide/index.md, ../guide/c/index.md |
| status | maintained |
| publication | reviewed |
Use this loop for a Fortran or C project: edit the source, review its Python interface, build, and test.
This layout continues with scale.f90 or scale.c from First Wrapped
Function:
my-project/
├── src/
│ └── scale.f90 # or scale.c
├── build/ # ← Generated, do not commit
├── tests/
│ └── test_scale.py
└── contracts/ # Optional edited semantic contracts
Keep src/ and tests/ under version control. Never commit the build/ folder.
Edit the native source, then preview the generated Python interface with the command for your language.
Fortran:
python3 -m prik generate --pyi src/scale.f90C:
python3 -m prik generate --pyi --language c src/scale.cCheck the function names, arguments, result types, and required NumPy dtypes. This review is especially useful after changing a public declaration.
Fortran:
python3 -m prik src/scale.f90 --out scale --out-dir build/scaleC:
python3 -m prik --language c src/scale.c \
--compiler cc \
--out scale \
--out-dir build/scaleRerun the same command after source changes. Add --verbose only when you need
the compiler and linker details.
Create tests/test_scale.py:
import sys
import numpy as np
sys.path.insert(0, "build/scale")
import scale
def test_scale_function():
result = scale.scale(np.float64(3.0), np.float64(2.5))
assert result == 7.5Run it with:
python3 -m pytest tests/test_scale.py -qSave the generated contract when you want to change the Python interface. Create the optional directory from the layout above first:
mkdir -p contractsFortran writes a contract package:
python3 -m prik generate --pyi src/scale.f90 --out contracts/scaleEdit contracts/scale/scale.pyi, then build through its package entry:
python3 -m prik contracts/scale/__init__.pyi \
--native-fortran-sources src/scale.f90 \
--out scale \
--out-dir build/scale-editedC writes one contract file:
python3 -m prik generate --pyi --language c src/scale.c \
--out contracts/scale.pyiEdit contracts/scale.pyi, then build it with the C implementation:
python3 -m prik --language c contracts/scale.pyi \
--native-c-sources src/scale.c \
--compiler cc \
--out scale \
--out-dir build/scale-editedUse this form instead of the source build in step 2 when the edited contract
should control the wrapper. The .pyi controls the Python surface; the native
source still supplies the implementation. Keep its native symbol names, types,
rank, and argument order accurate.
The User Guide introduces small edits next to the feature they affect.
Use .pyi Format to understand the generated
project, declarations, and keywords. Use Editing .pyi
Contracts to find the supported recipe
for the change you want to make.
If a build fails, rerun it with --verbose. If a Python call fails, compare
the arguments with the generated contract. Use a clean output directory only
when you need to rule out stale build files.
- Continue with the User Guide.
- For Fortran modules, see Wrapping Modules.
- For C pointers, arrays, strings, and outputs, see the C User Guide.