From decf04177ca17b29f136aa97afebeb7f1c82eae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Fra=CC=88nkel?= Date: Wed, 18 Oct 2023 22:43:36 +0200 Subject: [PATCH] Call Rust from Python project --- rust_over_pyo3/main.py | 20 ++++++++++++++++++++ rust_over_pyo3/requirements.txt | 1 + 2 files changed, 21 insertions(+) create mode 100644 rust_over_pyo3/main.py create mode 100644 rust_over_pyo3/requirements.txt diff --git a/rust_over_pyo3/main.py b/rust_over_pyo3/main.py new file mode 100644 index 0000000..3a73761 --- /dev/null +++ b/rust_over_pyo3/main.py @@ -0,0 +1,20 @@ +from typing import Optional +from click import command, option +from rust_over_pyo3 import compute + + +@command() +@option('--add', 'command', flag_value='add') +@option('--sub', 'command', flag_value='sub') +@option('--mul', 'command', flag_value='mul') +@option('--arg1', help='First complex number in the form x+yj') +@option('--arg2', help='Second complex number in the form x\'+y\'j') +def cli(command: Optional[str], arg1: Optional[str], arg2: Optional[str]) -> None: + n1: complex = complex(arg1) + n2: complex = complex(arg2) + result: complex = compute(command, n1, n2) + print(result) + + +if __name__ == '__main__': + cli() diff --git a/rust_over_pyo3/requirements.txt b/rust_over_pyo3/requirements.txt new file mode 100644 index 0000000..2f72dd5 --- /dev/null +++ b/rust_over_pyo3/requirements.txt @@ -0,0 +1 @@ +click==8.1.7