Skip to content

Commit

Permalink
Call Rust from Python project
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrankel committed Oct 20, 2023
1 parent 7ad74a5 commit decf041
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions rust_over_pyo3/main.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions rust_over_pyo3/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
click==8.1.7

0 comments on commit decf041

Please sign in to comment.