Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/python: Lint sdk develop #1411

Merged
merged 33 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d6c1094
moved pylint to root
Sep 22, 2023
2cda124
feat/Python: Add pylint to code (#1315)
Sep 26, 2023
0fc60ef
fixes for develop
Oct 9, 2023
ec15a13
reverts
Oct 9, 2023
2f33cab
lint
Oct 9, 2023
d2a5c36
reverted range
Oct 9, 2023
98b227c
Merge branch 'develop' into python/lint-sdk-develop
Oct 10, 2023
f0373c2
docs
Oct 10, 2023
ced83ec
format
Oct 10, 2023
7dd98a2
comment
Oct 16, 2023
82ba977
Merge branch 'develop' into python/lint-sdk-develop
Oct 16, 2023
bb6f51b
some more doc fix
Oct 16, 2023
638af66
todo comment on disable
Oct 16, 2023
3eb78af
changed docs
Oct 17, 2023
b42e24e
Update bindings/python/iota_sdk/wallet/account.py
thibault-martinez Oct 18, 2023
10840f8
Merge branch 'develop' into python/lint-sdk-develop
Oct 23, 2023
c82ee5e
2 review comments
Oct 23, 2023
c9db213
format
Oct 23, 2023
55711e8
Merge branch 'python/lint-sdk-develop' of https://github.com/kwek20/i…
Oct 23, 2023
97f5cb2
pep again?
Oct 23, 2023
1daed17
fmt x2
Oct 23, 2023
906ab30
final lints
Oct 23, 2023
00a3bf1
Merge branch 'develop' into python/lint-sdk-develop
Oct 23, 2023
e1f17a8
removed test
Oct 23, 2023
353ac73
review
Oct 24, 2023
d45e6a0
revert
Oct 24, 2023
990eb3a
1 more
Oct 24, 2023
3a6fe27
Merge branch 'develop' into python/lint-sdk-develop
thibault-martinez Oct 24, 2023
fbb069f
Update bindings/python/iota_sdk/types/unlock.py
thibault-martinez Oct 25, 2023
37b02bf
Update bindings/python/iota_sdk/types/irc_30.py
thibault-martinez Oct 25, 2023
3acc008
Merge branch 'develop' into python/lint-sdk-develop
thibault-martinez Oct 25, 2023
bd72347
changelog
Oct 25, 2023
50e66e4
Merge branch 'python/lint-sdk-develop' of https://github.com/kwek20/i…
Oct 25, 2023
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
5 changes: 5 additions & 0 deletions .github/workflows/bindings-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ jobs:
sudo apt-get update
sudo apt-get install libudev-dev libusb-1.0-0-dev

- name: Run linter for iota_sdk
if: ${{ startsWith(matrix.os, 'ubuntu-latest') }}
working-directory: bindings/python
run: tox -e lint-sdk

- name: Run linter for examples
if: ${{ startsWith(matrix.os, 'ubuntu-latest') }}
working-directory: bindings/python
Expand Down
10 changes: 8 additions & 2 deletions bindings/python/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ disable=missing-module-docstring,
invalid-name, # files that starts with number
duplicate-code,
consider-using-with,
consider-using-f-string

fixme, # TODOS
too-many-instance-attributes,
too-many-arguments,
too-many-public-methods,
too-few-public-methods,
too-many-locals

[TYPECHECK]
generated-members=from_dict,to_dict,to_json # Made from @json
4 changes: 2 additions & 2 deletions bindings/python/iota_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from .iota_sdk import *
from .client.client import Client, NodeIndexerAPI, ClientError
from .client._high_level_api import GenerateAddressesOptions, GenerateAddressOptions
from .external import *
from .utils import Utils
from .wallet.wallet import Wallet, Account
from .wallet.common import WalletError
from .wallet.sync_options import AccountSyncOptions, AliasSyncOptions, NftSyncOptions, SyncOptions
from .wallet.sync_options import AccountSyncOptions, NftSyncOptions, SyncOptions
from .secret_manager.secret_manager import *
from .prefix_hex import *
from .types.address import *
Expand Down
40 changes: 32 additions & 8 deletions bindings/python/iota_sdk/client/_high_level_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from iota_sdk.secret_manager.secret_manager import LedgerNanoSecretManager, MnemonicSecretManager, StrongholdSecretManager, SeedSecretManager
from typing import List, Optional, Union
from abc import ABCMeta, abstractmethod
from dacite import from_dict
from iota_sdk.types.block import Block
from iota_sdk.types.common import HexStr
from iota_sdk.types.common import CoinType, HexStr
from iota_sdk.types.output import OutputWithMetadata
from iota_sdk.types.output_id import OutputId
from iota_sdk.types.common import CoinType
from typing import List, Optional, Union
from dacite import from_dict
from iota_sdk.secret_manager.secret_manager import LedgerNanoSecretManager, MnemonicSecretManager, StrongholdSecretManager, SeedSecretManager


class Range:
Expand Down Expand Up @@ -50,8 +50,9 @@ class GenerateAddressesOptions():
options: An instance of `GenerateAddressOptions`.
"""

# pylint: disable=redefined-builtin
def __init__(self, coinType: CoinType,
range: range,
range: Range,
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
bech32Hrp: str,
accountIndex: Optional[int] = None,
options: Optional[GenerateAddressOptions] = None):
Expand All @@ -65,12 +66,14 @@ def __init__(self, coinType: CoinType,
options: An instance of `GenerateAddressOptions`.
"""
self.coinType = coinType
self.range = Range(range.start, range.stop)
self.range = range
self.bech32Hrp = bech32Hrp
self.accountIndex = accountIndex
self.options = options

def as_dict(self):
"""Converts this object to a dict.
"""
config = {k: v for k, v in self.__dict__.items() if v is not None}

config["range"] = config["range"].__dict__
Expand All @@ -79,10 +82,31 @@ def as_dict(self):
return config


class HighLevelAPI():
class HighLevelAPI(metaclass=ABCMeta):
"""High level API.
"""

@abstractmethod
def _call_method(self, name, data=None):
"""
Sends a message to the Rust library and returns the response.
It is abstract here as its implementation is located in `client.py`, which is a composite class.

Arguments:

* `name`: The `name` parameter is a string that represents the name of the method to be called.
It is used to identify the specific method to be executed in the Rust library.
* `data`: The `data` parameter is an optional parameter that represents additional data to be
sent along with the method call. It is a dictionary that contains key-value pairs of data. If
the `data` parameter is provided, it will be included in the `message` dictionary as the 'data'
key.

Returns:

The method returns either the payload from the JSON response or the entire response if there is
no payload.
"""

def get_outputs(
self, output_ids: List[OutputId]) -> List[OutputWithMetadata]:
"""Fetch OutputWithMetadata from provided OutputIds (requests are sent in parallel).
Expand Down
29 changes: 26 additions & 3 deletions bindings/python/iota_sdk/client/_node_core_api.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from typing import List, Union
from abc import ABCMeta, abstractmethod
from dacite import from_dict

from iota_sdk.types.block import Block, BlockMetadata
from iota_sdk.types.common import HexStr
from iota_sdk.types.node_info import NodeInfo, NodeInfoWrapper
from iota_sdk.types.output import OutputWithMetadata, OutputMetadata
from iota_sdk.types.output_id import OutputId
from iota_sdk.types.payload import MilestonePayload
from iota_sdk.types.utxo_changes import UtxoChanges
from typing import List, Union
from dacite import from_dict


class NodeCoreAPI():
class NodeCoreAPI(metaclass=ABCMeta):
"""Node core API.
"""

@abstractmethod
def _call_method(self, name, data=None):
"""
Sends a message to the Rust library and returns the response.
It is abstract here as its implementation is located in `client.py`, which is a composite class.

Arguments:

* `name`: The `name` parameter is a string that represents the name of the method to be called.
It is used to identify the specific method to be executed in the Rust library.
* `data`: The `data` parameter is an optional parameter that represents additional data to be
sent along with the method call. It is a dictionary that contains key-value pairs of data. If
the `data` parameter is provided, it will be included in the `message` dictionary as the 'data'
key.

Returns:

The method returns either the payload from the JSON response or the entire response if there is
no payload.
"""

def get_health(self, url: str):
""" Get node health.

Expand Down
106 changes: 66 additions & 40 deletions bindings/python/iota_sdk/client/_node_indexer_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from iota_sdk.types.common import HexStr
from iota_sdk.types.output_id import OutputId
from dataclasses import dataclass
from typing import Dict, Optional
from abc import ABCMeta, abstractmethod
import humps

from iota_sdk.types.common import HexStr
from iota_sdk.types.output_id import OutputId


class OutputIdsResponse:
"""Response type for output IDs.

Attributes:
ledger_index: The ledger index for which the response is valid.
cursor: The cursor to the next page of results.
items: The query results.
"""

def __init__(self, output_dict: Dict):
self.ledgerIndex = output_dict["ledgerIndex"]
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
self.cursor = output_dict["cursor"]
self.items = [OutputId.from_string(
output_id) for output_id in output_dict["items"]]


class NodeIndexerAPI():
class NodeIndexerAPI(metaclass=ABCMeta):
"""Node indexer API.
"""

Expand All @@ -23,48 +41,48 @@ class QueryParameters:
Filter foundry outputs based on bech32-encoded address of the controlling alias.
created_after :
Returns outputs that were created after a certain Unix timestamp.
created_before :
created_before :
Returns outputs that were created before a certain Unix timestamp.
cursor :
cursor :
Starts the search from the cursor (confirmationMS+outputId.pageSize).
expiration_return_address :
expiration_return_address :
Filters outputs based on the presence of a specific Bech32-encoded return address in the expiration unlock
condition.
expires_after :
expires_after :
Returns outputs that expire after a certain Unix timestamp.
expires_before :
expires_before :
Returns outputs that expire before a certain Unix timestamp.
governor :
governor :
Filters outputs based on bech32-encoded governor (governance controller) address.
has_expiration :
has_expiration :
Filters outputs based on the presence of expiration unlock condition.
has_native_tokens :
has_native_tokens :
Filters outputs based on the presence of native tokens.
has_storage_deposit_return :
has_storage_deposit_return :
Filters outputs based on the presence of storage deposit return unlock condition.
has_timelock :
has_timelock :
Filters outputs based on the presence of timelock unlock condition.
issuer:
issuer:
Filters outputs based on bech32-encoded issuer address.
max_native_token_count :
max_native_token_count :
Filters outputs that have at most a certain number of distinct native tokens.
min_native_token_count :
min_native_token_count :
Filters outputs that have at least a certain number of distinct native tokens.
page_size :
page_size :
The maximum amount of items returned in one call. If there are more items, a cursor to the next page is
returned too. The parameter is ignored when pageSize is defined via the cursor parameter.
sender :
sender :
Filters outputs based on the presence of validated Sender (bech32 encoded).
state_controller :
state_controller :
Filters outputs based on bech32-encoded state controller address.
storage_deposit_return_address :
storage_deposit_return_address :
Filters outputs based on the presence of a specific return address in the storage deposit return unlock
condition.
tag :
tag :
Filters outputs based on matching Tag Block.
timelocked_after :
timelocked_after :
Returns outputs that are timelocked after a certain Unix timestamp.
timelocked_before :
timelocked_before :
Returns outputs that are timelocked before a certain Unix timestamp.
unlockable_by_address :
Returns outputs that are unlockable by the bech32 address.
Expand Down Expand Up @@ -95,23 +113,31 @@ class QueryParameters:
unlockable_by_address: Optional[str] = None

def as_dict(self):
"""Converts this object to a dict.
"""
return humps.camelize(
[{k: v} for k, v in self.__dict__.items() if v is not None])

class OutputIdsResponse:
"""Response type for output IDs.

Attributes:
ledger_index: The ledger index for which the response is valid.
cursor: The cursor to the next page of results.
items: The query results.
@abstractmethod
def _call_method(self, name, data=None):
"""
Sends a message to the Rust library and returns the response.
It is abstract here as its implementation is located in `client.py`, which is a composite class.

Arguments:

def __init__(self, dict: Dict):
self.ledgerIndex = dict["ledgerIndex"]
self.cursor = dict["cursor"]
self.items = [OutputId.from_string(
output_id) for output_id in dict["items"]]
* `name`: The `name` parameter is a string that represents the name of the method to be called.
It is used to identify the specific method to be executed in the Rust library.
* `data`: The `data` parameter is an optional parameter that represents additional data to be
sent along with the method call. It is a dictionary that contains key-value pairs of data. If
the `data` parameter is provided, it will be included in the `message` dictionary as the 'data'
key.

Returns:

The method returns either the payload from the JSON response or the entire response if there is
no payload.
"""

def output_ids(
self, query_parameters: QueryParameters) -> OutputIdsResponse:
Expand All @@ -127,7 +153,7 @@ def output_ids(
response = self._call_method('outputIds', {
'queryParameters': query_parameters_camelized,
})
return self.OutputIdsResponse(response)
return OutputIdsResponse(response)

def basic_output_ids(
self, query_parameters: QueryParameters) -> OutputIdsResponse:
Expand All @@ -142,7 +168,7 @@ def basic_output_ids(
response = self._call_method('basicOutputIds', {
'queryParameters': query_parameters_camelized,
})
return self.OutputIdsResponse(response)
return OutputIdsResponse(response)

def alias_output_ids(
self, query_parameters: QueryParameters) -> OutputIdsResponse:
Expand All @@ -157,7 +183,7 @@ def alias_output_ids(
response = self._call_method('aliasOutputIds', {
'queryParameters': query_parameters_camelized,
})
return self.OutputIdsResponse(response)
return OutputIdsResponse(response)

def alias_output_id(self, alias_id: HexStr) -> OutputId:
"""Fetch alias output ID from the given alias ID.
Expand All @@ -182,7 +208,7 @@ def nft_output_ids(
response = self._call_method('nftOutputIds', {
'queryParameters': query_parameters_camelized,
})
return self.OutputIdsResponse(response)
return OutputIdsResponse(response)

def nft_output_id(self, nft_id: HexStr) -> OutputId:
"""Fetch NFT output ID from the given NFT ID.
Expand All @@ -207,7 +233,7 @@ def foundry_output_ids(
response = self._call_method('foundryOutputIds', {
'queryParameters': query_parameters_camelized,
})
return self.OutputIdsResponse(response)
return OutputIdsResponse(response)

def foundry_output_id(self, foundry_id: HexStr) -> OutputId:
"""Fetch foundry Output ID from the given foundry ID.
Expand Down
Loading
Loading