Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lint:
@ruff check . --fix
@ruff format .
.PHONY: lint

test:
python -m coverage run -m pytest tests/ -v && \
python -m coverage report
.PHONY: test
35 changes: 19 additions & 16 deletions examples/calculator.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from snet import sdk

config = sdk.config.Config(private_key="YOUR_PRIVATE_KEY",
eth_rpc_endpoint=f"https://sepolia.infura.io/v3/YOUR_INFURA_KEY",
concurrency=False,
force_update=False)

operators = {
"+": "add",
"-": "sub",
"*": "mul",
"/": "div"
}
config = sdk.config.Config(
private_key="YOUR_PRIVATE_KEY",
eth_rpc_endpoint="https://sepolia.infura.io/v3/YOUR_INFURA_KEY",
concurrency=False,
force_update=False,
)

operators = {"+": "add", "-": "sub", "*": "mul", "/": "div"}

snet_sdk = sdk.SnetSDK(config)
calc_client = snet_sdk.create_service_client(org_id="26072b8b6a0e448180f8c0e702ab6d2f",
service_id="Exampleservice", group_name="default_group")
calc_client = snet_sdk.create_service_client(
org_id="26072b8b6a0e448180f8c0e702ab6d2f",
service_id="Exampleservice",
group_name="default_group",
)


def parse_expression(expression):
Expand All @@ -23,12 +23,16 @@
raise Exception(f"Invalid expression '{expression}'. Three items required.")

if elements[1] not in ["+", "-", "*", "/"]:
raise Exception(f"Invalid expression '{expression}'. Operation must be '+' or '-' or '*' or '/'.")
raise Exception(

Check warning on line 26 in examples/calculator.py

View check run for this annotation

snet-sonarqube-app / SonarQube Code Analysis

examples/calculator.py#L26

Replace this generic exception class with a more specific one.
f"Invalid expression '{expression}'. Operation must be '+' or '-' or '*' or '/'."
)
try:
a = float(elements[0])
b = float(elements[2])
except ValueError:
raise Exception(f"Invalid expression '{expression}'. Operands must be integers or floating point numbers.")
raise Exception(

Check warning on line 33 in examples/calculator.py

View check run for this annotation

snet-sonarqube-app / SonarQube Code Analysis

examples/calculator.py#L33

Replace this generic exception class with a more specific one.
f"Invalid expression '{expression}'. Operands must be integers or floating point numbers."
)
op = elements[1]

return a, b, op
Expand All @@ -54,4 +58,3 @@

if __name__ == "__main__":
main()

Loading
Loading