From ca7347d421b4a8aaddd7f6a85ff98cd43e6dd6b1 Mon Sep 17 00:00:00 2001 From: yihuang Date: Mon, 26 Feb 2024 11:57:18 +0800 Subject: [PATCH] Problem: nix develop don't work (#120) Solution: - fix default devShell - update link instruction in ci to use nix - update python dev dependencies --- .github/workflows/test.yml | 7 +- Makefile | 6 +- flake.nix | 12 ++- poetry.lock | 61 +++++++++++--- pyproject.toml | 10 +-- pystarport/cluster.py | 162 ++++++++++++++++++++++++++++--------- pystarport/cosmoscli.py | 46 +++++++++-- 7 files changed, 234 insertions(+), 70 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e6c08d..11ff65b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,12 +13,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Upgrade poetry - run: python3 -m pip install --user --upgrade poetry - - name: Install dependencies - run: poetry install + - uses: cachix/install-nix-action@v15 - name: Run linting - run: make lint + run: nix develop -c make lint-ci tests: runs-on: ubuntu-latest steps: diff --git a/Makefile b/Makefile index 1356508..6b5e299 100644 --- a/Makefile +++ b/Makefile @@ -3,4 +3,8 @@ test: lint: @poetry run flake8 --show-source --count --statistics - @poetry run isort --check-only . \ No newline at end of file + @poetry run isort --check-only . + +lint-ci: + @flake8 --show-source --count --statistics \ + --format="::error file=%(path)s,line=%(row)d,col=%(col)d::%(path)s:%(row)d:%(col)d: %(code)s %(text)s" diff --git a/flake.nix b/flake.nix index 889408b..398b334 100644 --- a/flake.nix +++ b/flake.nix @@ -24,6 +24,8 @@ durations = [ "setuptools" ]; multitail2 = [ "setuptools" ]; pytest-github-actions-annotate-failures = [ "setuptools" ]; + flake8-black = [ "setuptools" ]; + flake8-isort = [ "hatchling" ]; }; in pkgs.lib.mapAttrs @@ -44,9 +46,13 @@ type = "app"; program = "${packages.default}/bin/pystarport"; }; - devShell = pkgs.poetry2nix.mkPoetryEnv { - projectDir = ./.; - inherit overrides; + devShells.default = pkgs.mkShell { + buildInputs = [ + (pkgs.poetry2nix.mkPoetryEnv { + projectDir = ./.; + inherit overrides; + }) + ]; }; } )); diff --git a/poetry.lock b/poetry.lock index 44bcd1f..db29f1b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -276,12 +276,12 @@ test = ["pytest (>=6)"] [[package]] name = "fire" -version = "0.4.0" +version = "0.5.0" description = "A library for automatically generating command line interfaces." optional = false python-versions = "*" files = [ - {file = "fire-0.4.0.tar.gz", hash = "sha256:c5e2b8763699d1142393a46d0e3e790c5eb2f0706082df8f647878842c216a62"}, + {file = "fire-0.5.0.tar.gz", hash = "sha256:a6b0d49e98c8963910021f92bba66f65ab440da2982b78eb1bbf95a0a34aacc6"}, ] [package.dependencies] @@ -304,6 +304,43 @@ mccabe = ">=0.7.0,<0.8.0" pycodestyle = ">=2.11.0,<2.12.0" pyflakes = ">=3.2.0,<3.3.0" +[[package]] +name = "flake8-black" +version = "0.3.6" +description = "flake8 plugin to call black as a code style validator" +optional = false +python-versions = ">=3.7" +files = [ + {file = "flake8-black-0.3.6.tar.gz", hash = "sha256:0dfbca3274777792a5bcb2af887a4cad72c72d0e86c94e08e3a3de151bb41c34"}, + {file = "flake8_black-0.3.6-py3-none-any.whl", hash = "sha256:fe8ea2eca98d8a504f22040d9117347f6b367458366952862ac3586e7d4eeaca"}, +] + +[package.dependencies] +black = ">=22.1.0" +flake8 = ">=3" +tomli = {version = "*", markers = "python_version < \"3.11\""} + +[package.extras] +develop = ["build", "twine"] + +[[package]] +name = "flake8-isort" +version = "6.1.1" +description = "flake8 plugin that integrates isort" +optional = false +python-versions = ">=3.8" +files = [ + {file = "flake8_isort-6.1.1-py3-none-any.whl", hash = "sha256:0fec4dc3a15aefbdbe4012e51d5531a2eb5fa8b981cdfbc882296a59b54ede12"}, + {file = "flake8_isort-6.1.1.tar.gz", hash = "sha256:c1f82f3cf06a80c13e1d09bfae460e9666255d5c780b859f19f8318d420370b3"}, +] + +[package.dependencies] +flake8 = "*" +isort = ">=5.0.0,<6" + +[package.extras] +test = ["pytest"] + [[package]] name = "idna" version = "3.6" @@ -818,19 +855,19 @@ files = [ [[package]] name = "setuptools" -version = "69.1.0" +version = "69.1.1" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-69.1.0-py3-none-any.whl", hash = "sha256:c054629b81b946d63a9c6e732bc8b2513a7c3ea645f11d0139a2191d735c60c6"}, - {file = "setuptools-69.1.0.tar.gz", hash = "sha256:850894c4195f09c4ed30dba56213bf7c3f21d86ed6bdaafb5df5972593bfc401"}, + {file = "setuptools-69.1.1-py3-none-any.whl", hash = "sha256:02fa291a0471b3a18b2b2481ed902af520c69e8ae0919c13da936542754b4c56"}, + {file = "setuptools-69.1.1.tar.gz", hash = "sha256:5c0806c7d9af348e6dd3777b4f4dbb42c7ad85b190104837488eab9a7c945cf8"}, ] [package.extras] docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] -testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] -testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.2)", "pip (>=19.1)", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.2)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] [[package]] name = "six" @@ -887,13 +924,13 @@ files = [ [[package]] name = "tomlkit" -version = "0.7.2" +version = "0.12.3" description = "Style preserving TOML library" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.7" files = [ - {file = "tomlkit-0.7.2-py2.py3-none-any.whl", hash = "sha256:173ad840fa5d2aac140528ca1933c29791b79a374a0861a80347f42ec9328117"}, - {file = "tomlkit-0.7.2.tar.gz", hash = "sha256:d7a454f319a7e9bd2e249f239168729327e4dd2d27b17dc68be264ad1ce36754"}, + {file = "tomlkit-0.12.3-py3-none-any.whl", hash = "sha256:b0a645a9156dc7cb5d3a1f0d4bab66db287fcb8e0430bdd4664a095ea16414ba"}, + {file = "tomlkit-0.12.3.tar.gz", hash = "sha256:75baf5012d06501f07bee5bf8e801b9f343e7aac5a92581f20f80ce632e6b5a4"}, ] [[package]] @@ -927,4 +964,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "42444bf88838515ee9eb378592e3d5aede647797726d2c64e02ed8febd4c8e18" +content-hash = "949b6da603755fb93da9a78faf4a263bb3a95764becbc29ac15463830dac741c" diff --git a/pyproject.toml b/pyproject.toml index 115ea67..bafe0bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,11 +11,11 @@ repository = "https://github.com/crypto-com/pystarport" [tool.poetry.dependencies] python = "^3.9" -fire = "^0.4" -tomlkit = "^0.7" +fire = "^0" +tomlkit = "^0" jsonmerge = "^1.7" python-dateutil = "^2.8" -durations = "^0.3" +durations = "^0" supervisor = "^4.2" docker = "^7.0" bech32 = "^1.1" @@ -31,8 +31,8 @@ rpds-py = "^0.17.0" pytest = "^8.0" deepdiff = "^6.7" flake8 = "^7" -black = "^24.2" -isort = "^5.10" +flake8-black = "^0" +flake8-isort = "^6.1" [tool.poetry.scripts] pystarport = "pystarport.cli:main" diff --git a/pystarport/cluster.py b/pystarport/cluster.py index 6927b52..93114d3 100644 --- a/pystarport/cluster.py +++ b/pystarport/cluster.py @@ -185,7 +185,7 @@ def create_node( hostname="127.0.0.1", statesync=False, mnemonic=None, - broadcastmode="sync" + broadcastmode="sync", ): """create new node in the data directory, process information is written into supervisor config @@ -410,36 +410,70 @@ def transfer_offline(self, from_, to, coins, sequence, i=0, fees=None): return self.cosmos_cli(i).transfer_offline(from_, to, coins, sequence, fees) def transfer( - self, from_, to, coins, i=0, generate_only=False, fees=None, + self, + from_, + to, + coins, + i=0, + generate_only=False, + fees=None, event_query_tx=True, ): return self.cosmos_cli(i).transfer( - from_, to, coins, generate_only, fees, event_query_tx=event_query_tx, + from_, + to, + coins, + generate_only, + fees, + event_query_tx=event_query_tx, ) def transfer_from_ledger( - self, from_, to, coins, i=0, generate_only=False, fees=None, + self, + from_, + to, + coins, + i=0, + generate_only=False, + fees=None, event_query_tx=True, ): return self.cosmos_cli(i).transfer_from_ledger( - from_, to, coins, generate_only, fees, event_query_tx=event_query_tx, + from_, + to, + coins, + generate_only, + fees, + event_query_tx=event_query_tx, ) def get_delegated_amount(self, which_addr, i=0): return self.cosmos_cli(i).get_delegated_amount(which_addr) def delegate_amount( - self, to_addr, amount, from_addr, i=0, gas_price=None, event_query_tx=True, + self, + to_addr, + amount, + from_addr, + i=0, + gas_price=None, + event_query_tx=True, ): return self.cosmos_cli(i).delegate_amount( - to_addr, amount, from_addr, gas_price, + to_addr, + amount, + from_addr, + gas_price, event_query_tx=event_query_tx, ) # to_addr: croclcl1... , from_addr: cro1... def unbond_amount(self, to_addr, amount, from_addr, i=0, event_query_tx=True): return self.cosmos_cli(i).unbond_amount( - to_addr, amount, from_addr, event_query_tx=event_query_tx, + to_addr, + amount, + from_addr, + event_query_tx=event_query_tx, ) # to_validator_addr: crocncl1... , from_from_validator_addraddr: crocl1... @@ -454,14 +488,18 @@ def redelegate_amount( **kwargs, ): return self.cosmos_cli(i).redelegate_amount( - to_validator_addr, from_validator_addr, amount, from_addr, + to_validator_addr, + from_validator_addr, + amount, + from_addr, event_query_tx=event_query_tx, **kwargs, ) def withdraw_all_rewards(self, from_delegator, i=0, event_query_tx=True): return self.cosmos_cli(i).withdraw_all_rewards( - from_delegator, event_query_tx=event_query_tx, + from_delegator, + event_query_tx=event_query_tx, ) def make_multisig(self, name, signer1, signer2, i=0): @@ -551,7 +589,12 @@ def edit_validator( ): """MsgEditValidator""" return self.cosmos_cli(i).edit_validator( - commission_rate, moniker, identity, website, security_contact, details, + commission_rate, + moniker, + identity, + website, + security_contact, + details, event_query_tx=event_query_tx, ) @@ -560,12 +603,18 @@ def gov_propose(self, proposer, kind, proposal, i=0): def gov_vote(self, voter, proposal_id, option, i=0, event_query_tx=True): return self.cosmos_cli(i).gov_vote( - voter, proposal_id, option, event_query_tx=event_query_tx, + voter, + proposal_id, + option, + event_query_tx=event_query_tx, ) def gov_deposit(self, depositor, proposal_id, amount, i=0, event_query_tx=True): return self.cosmos_cli(i).gov_deposit( - depositor, proposal_id, amount, event_query_tx=event_query_tx, + depositor, + proposal_id, + amount, + event_query_tx=event_query_tx, ) def query_proposals(self, depositor=None, limit=None, status=None, voter=None, i=0): @@ -588,7 +637,12 @@ def ibc_transfer( event_query_tx=True, ): return self.cosmos_cli(i).ibc_transfer( - from_, to, amount, channel, target_version, event_query_tx=event_query_tx, + from_, + to, + amount, + channel, + target_version, + event_query_tx=event_query_tx, ) def create_nft( @@ -606,7 +660,12 @@ def create_nft( event_query_tx=True, ): return self.cosmos_cli(i).create_nft( - from_addr, denomid, denomname, schema, fees, event_query_tx=event_query_tx, + from_addr, + denomid, + denomname, + schema, + fees, + event_query_tx=event_query_tx, ) def query_nft(self, denomid="mydenomid", i=0): @@ -627,7 +686,12 @@ def create_nft_token( event_query_tx=True, ): return self.cosmos_cli(i).create_nft_token( - from_addr, to_addr, denomid, tokenid, uri, fees, + from_addr, + to_addr, + denomid, + tokenid, + uri, + fees, event_query_tx=event_query_tx, ) @@ -643,7 +707,10 @@ def burn_nft_token( event_query_tx=True, ): return self.cosmos_cli(i).burn_nft_token( - from_addr, denomid, tokenid, event_query_tx=event_query_tx, + from_addr, + denomid, + tokenid, + event_query_tx=event_query_tx, ) def edit_nft_token( @@ -657,7 +724,12 @@ def edit_nft_token( event_query_tx=True, ): return self.cosmos_cli(i).edit_nft_token( - from_addr, denomid, tokenid, newuri, newname, event_query_tx=event_query_tx, + from_addr, + denomid, + tokenid, + newuri, + newname, + event_query_tx=event_query_tx, ) def transfer_nft_token( @@ -670,7 +742,11 @@ def transfer_nft_token( event_query_tx=True, ): return self.cosmos_cli(i).transfer_nft_token( - from_addr, to_addr, denomid, tokenid, event_query_tx=event_query_tx, + from_addr, + to_addr, + denomid, + tokenid, + event_query_tx=event_query_tx, ) def event_query_tx_for(self, hash, i=0): @@ -684,17 +760,26 @@ def ibc_query_channels(self, connid, i=0): def icaauth_register_account(self, connid, i=0, event_query_tx=True): return self.cosmos_cli(i).icaauth_register_account( - connid, event_query_tx=event_query_tx, + connid, + event_query_tx=event_query_tx, ) def ica_query_account(self, connid, owner, i=0, **kwargs): return self.cosmos_cli(i).ica_query_account(connid, owner, **kwargs) def icaauth_submit_tx( - self, connid, tx, timeout_duration="1h", i=0, event_query_tx=True, + self, + connid, + tx, + timeout_duration="1h", + i=0, + event_query_tx=True, ): return self.cosmos_cli(i).icaauth_submit_tx( - connid, tx, timeout_duration, event_query_tx=event_query_tx, + connid, + tx, + timeout_duration, + event_query_tx=event_query_tx, ) @@ -849,13 +934,16 @@ def create_account(cli, account, use_ledger=False): rpc_port = ports.rpc_port(val["base_port"]) (data_dir / f"node{i}/config/client.toml").write_text( tomlkit.dumps( - jsonmerge.merge({ - "chain-id": config["chain_id"], - "keyring-backend": "test", - "output": "json", - "node": f"tcp://{val['hostname']}:{rpc_port}", - "broadcast-mode": "sync", - }, val.get("client_config", {})) + jsonmerge.merge( + { + "chain-id": config["chain_id"], + "keyring-backend": "test", + "output": "json", + "node": f"tcp://{val['hostname']}:{rpc_port}", + "broadcast-mode": "sync", + }, + val.get("client_config", {}), + ) ) ) @@ -886,7 +974,7 @@ def create_account(cli, account, use_ledger=False): "commission_rate", "details", "security_contact", - "gas_prices" + "gas_prices", ] extra_kwargs = { name: str(node[name]) for name in optional_fields if name in node @@ -982,9 +1070,7 @@ def create_account(cli, account, use_ledger=False): def get_relayer_chain_config(relayer_chains_config, chain_id): - return next( - (i for i in relayer_chains_config if i["id"] == chain_id), {} - ) + return next((i for i in relayer_chains_config if i["id"] == chain_id), {}) def relayer_chain_config_hermes(data_dir, chain, relayer_chains_config): @@ -1063,8 +1149,8 @@ def relayer_chain_config_rly(data_dir, chain, relayer_chains_config): "precompiled-contract-address": precompiled, "signing-algorithm": "", "broadcast-mode": "batch", - "min-loop-duration": "0s" - } + "min-loop-duration": "0s", + }, } @@ -1110,7 +1196,7 @@ def init_cluster( cfg = relayer_config.pop("chains", {}) if is_hermes: # write relayer config for hermes - relayer_config_hermes = (data_dir / "relayer.toml") + relayer_config_hermes = data_dir / "relayer.toml" relayer_config_hermes.write_text( tomlkit.dumps( jsonmerge.merge( @@ -1129,9 +1215,9 @@ def init_cluster( ) else: # write relayer config folder for rly - relayer_config_dir = (data_dir / "relayer/config") + relayer_config_dir = data_dir / "relayer/config" relayer_config_dir.mkdir(parents=True, exist_ok=True) - relayer_config_rly = (relayer_config_dir / "config.yaml") + relayer_config_rly = relayer_config_dir / "config.yaml" log_level = relayer_config.get("global", {}).get("log_level", "") relayer_config_rly.write_text( yaml.dump( diff --git a/pystarport/cosmoscli.py b/pystarport/cosmoscli.py index 86344c4..1a81885 100644 --- a/pystarport/cosmoscli.py +++ b/pystarport/cosmoscli.py @@ -418,7 +418,12 @@ def get_delegated_amount(self, which_addr): ) def delegate_amount( - self, to_addr, amount, from_addr, gas_price=None, event_query_tx=True, + self, + to_addr, + amount, + from_addr, + gas_price=None, + event_query_tx=True, ): rsp = json.loads( self.raw( @@ -922,7 +927,13 @@ def unsaferesetall(self): return self.raw("unsafe-reset-all") def create_nft( - self, from_addr, denomid, denomname, schema, fees, event_query_tx=True, + self, + from_addr, + denomid, + denomname, + schema, + fees, + event_query_tx=True, ): rsp = json.loads( self.raw( @@ -974,7 +985,14 @@ def query_denom_by_name(self, denomname): ) def create_nft_token( - self, from_addr, to_addr, denomid, tokenid, uri, fees, event_query_tx=True, + self, + from_addr, + to_addr, + denomid, + tokenid, + uri, + fees, + event_query_tx=True, ): rsp = json.loads( self.raw( @@ -1033,7 +1051,13 @@ def burn_nft_token(self, from_addr, denomid, tokenid, event_query_tx=True): return rsp def edit_nft_token( - self, from_addr, denomid, tokenid, newuri, newname, event_query_tx=True, + self, + from_addr, + denomid, + tokenid, + newuri, + newname, + event_query_tx=True, ): rsp = json.loads( self.raw( @@ -1057,7 +1081,12 @@ def edit_nft_token( return rsp def transfer_nft_token( - self, from_addr, to_addr, denomid, tokenid, event_query_tx=True, + self, + from_addr, + to_addr, + denomid, + tokenid, + event_query_tx=True, ): rsp = json.loads( self.raw( @@ -1149,7 +1178,12 @@ def ica_query_account(self, connid, owner, **kwargs): ) def icaauth_submit_tx( - self, connid, tx, timeout_duration="1h", event_query_tx=True, **kwargs, + self, + connid, + tx, + timeout_duration="1h", + event_query_tx=True, + **kwargs, ): default_kwargs = { "home": self.data_dir,