Skip to content

Commit b5831d8

Browse files
authored
Merge pull request #550 from singnet/development
Release 3.1.0
2 parents efd2b14 + d4462bc commit b5831d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1127
-1592
lines changed

.github/workflows/master.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ jobs:
7171
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
7272
# sh -ex ./snet/cli/test/utils/run_all_functional.sh
7373
python3 ./snet/cli/test/functional_tests/test_entry_point.py
74+
python3 ./snet/cli/test/functional_tests/func_tests.py

.github/workflows/test.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: tests_functional_tests_update
2+
on:
3+
push:
4+
branches: [ "functional-tests-update" ]
5+
# pull_request:
6+
# branches: [ "development" ]
7+
workflow_dispatch:
8+
9+
jobs:
10+
run_tests_functional_tests_update:
11+
runs-on: ubuntu-latest
12+
container: node:20-bookworm
13+
steps:
14+
15+
- name: install packs
16+
run: |
17+
apt update
18+
apt install -y libudev-dev libusb-1.0-0-dev curl jq
19+
apt install -y python3-pip python3.11-venv
20+
21+
- name: clone repo
22+
uses: actions/checkout@v3
23+
24+
- name: install pip packages
25+
run: |
26+
pip3 install -r requirements.txt --break-system-packages
27+
# pip3 install nose --break-system-packages
28+
# pip3 uninstall pyreadline --break-system-packages
29+
# pip3 install pyreadline3 --break-system-packages
30+
31+
- name: install snet-cli
32+
run: |
33+
# ./scripts/blockchain install
34+
pip3 install -e . --break-system-packages
35+
36+
# - name: install platform-contracts
37+
# run: |
38+
# cd ..
39+
# git clone https://github.com/singnet/platform-contracts.git
40+
# cd platform-contracts
41+
# npm install
42+
# npm install ganache-cli
43+
# npm run-script compile
44+
45+
# - name: build example service
46+
# run: |
47+
# git clone https://github.com/singnet/example-service.git
48+
# cd example-service
49+
# pip3 install -r requirements.txt --break-system-packages
50+
# sh buildproto.sh
51+
52+
# - name: unit tests
53+
# run: |
54+
# cd ./snet/cli/test
55+
# nosetests -v --with-doctest
56+
57+
- name: functional tests for cli
58+
run: |
59+
export SNET_TEST_WALLET_PRIVATE_KEY=${{ secrets.PRIV_KEY }}
60+
export SNET_TEST_INFURA_KEY=${{ secrets.INF_KEY }}
61+
export SNET_TEST_WALLET_ADDRESS=${{ secrets.ADDR }}
62+
export FORMER_SNET_TEST_INFURA_KEY=${{ secrets.FORM_INF_KEY }}
63+
export PIP_BREAK_SYSTEM_PACKAGES=1
64+
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
65+
# sh -ex ./snet/cli/test/utils/run_all_functional.sh
66+
python3 ./snet/cli/test/functional_tests/test_entry_point.py

pyproject.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=61.0",
4+
"wheel",
5+
"protobuf~=6.30",
6+
"grpcio-tools~=1.59"
7+
]
8+
build-backend = "setuptools.build_meta"
9+
10+
[project]
11+
name = "snet-cli"
12+
version = "3.1.0"
13+
description = "SingularityNET CLI"
14+
readme = "README.md"
15+
requires-python = ">=3.10"
16+
license = {text = "MIT"}
17+
authors = [
18+
{name = "SingularityNET Foundation", email = "info@singularitynet.io"}
19+
]
20+
urls = {Homepage = "https://github.com/singnet/snet-cli"}
21+
22+
# Cleaned dependencies list
23+
dependencies = [
24+
"protobuf~=6.30",
25+
"grpcio~=1.59",
26+
"grpcio-tools~=1.59",
27+
"wheel~=0.45",
28+
"rlp~=4.0",
29+
"web3~=7.0",
30+
"mnemonic==0.21",
31+
"pyyaml~=6.0.1",
32+
"ipfshttpclient==0.4.13.2",
33+
"pymultihash==0.8.2",
34+
"base58==2.1.1",
35+
"argcomplete~=3.1",
36+
"grpcio-health-checking~=1.59",
37+
"jsonschema~=4.1",
38+
"eth-account~=0.9",
39+
"trezor~=0.13.8",
40+
"ledgerblue~=0.1.48",
41+
"snet-contracts==1.0.1",
42+
"lighthouseweb3~=0.1.4",
43+
"cryptography~=46.0"
44+
]
45+
46+
[project.scripts]
47+
snet = "snet.cli:main"
48+
49+
[tool.setuptools.packages.find]
50+
include = ["snet*"]

requirements.txt

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
protobuf==4.21.6
2-
grpcio-tools==1.59.0
3-
wheel==0.41.2
4-
jsonrpcclient==4.0.3
5-
eth-hash==0.5.2
6-
rlp==3.0.0
7-
eth-rlp==0.3.0
8-
web3==6.11.1
9-
mnemonic==0.20
10-
pycoin==0.92.20230326
11-
pyyaml==6.0.1
1+
protobuf~=6.30
2+
grpcio~=1.59
3+
grpcio-tools~=1.59
4+
wheel~=0.45
5+
# jsonrpcclient~=4.0
6+
# eth-hash~=0.5
7+
rlp~=4.0
8+
# eth-rlp~=2.0
9+
web3~=7.0
10+
mnemonic==0.21
11+
# pycoin==0.92.20241201
12+
pyyaml~=6.0.1
1213
ipfshttpclient==0.4.13.2
1314
pymultihash==0.8.2
1415
base58==2.1.1
15-
argcomplete==3.1.2
16-
grpcio-health-checking==1.59.0
17-
jsonschema==4.0.0
18-
eth-account==0.9.0
19-
trezor==0.13.8
20-
ledgerblue==0.1.48
21-
snet-contracts==1.0.0
22-
lighthouseweb3==0.1.4
23-
cryptography==44.0.1
16+
argcomplete~=3.1
17+
grpcio-health-checking~=1.59
18+
jsonschema~=4.1
19+
eth-account~=0.9
20+
trezor~=0.13.8
21+
ledgerblue~=0.1.48
22+
snet-contracts==1.0.1
23+
lighthouseweb3~=0.1.4
24+
cryptography~=46.0

setup.py

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,71 @@
11
import os
22
from pathlib import Path
3-
from setuptools import find_namespace_packages, setup
3+
from setuptools import setup
44
from setuptools.command.develop import develop as _develop
55
from setuptools.command.install import install as _install
6+
from setuptools.command.build_py import build_py as _build_py
7+
from grpc_tools import protoc
8+
from pkg_resources import resource_filename
69

7-
from snet.cli.utils.utils import compile_proto
8-
from version import __version__
9-
10-
PACKAGE_NAME = 'snet-cli'
11-
12-
13-
this_directory = os.path.abspath(os.path.dirname(__file__))
14-
with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
15-
long_description = f.read()
10+
def install_and_compile_proto():
11+
"""
12+
Compiles protobuf files directly.
13+
"""
14+
proto_dir = Path(__file__).absolute().parent.joinpath(
15+
"snet", "cli", "resources", "proto")
1616

17+
# Locate the standard grpc_tools internal protos (google/protobuf/...)
18+
grpc_protos_include = resource_filename('grpc_tools', '_proto')
1719

18-
with open("./requirements.txt") as f:
19-
requirements_str = f.read()
20-
requirements = requirements_str.split("\n")
20+
print(f"Proto directory: {proto_dir}")
21+
print(f"Grpc include directory: {grpc_protos_include}")
2122

23+
if not proto_dir.exists():
24+
print(f"Warning: Proto directory not found at {proto_dir}")
25+
return
2226

23-
def install_and_compile_proto():
24-
proto_dir = Path(__file__).absolute().parent.joinpath(
25-
"snet", "cli", "resources", "proto")
26-
print(proto_dir, "->", proto_dir)
27+
# glob('*.proto') is non-recursive. It will NOT look inside subfolders.
2728
for fn in proto_dir.glob('*.proto'):
28-
print("Compiling protobuf", fn)
29-
compile_proto(proto_dir, proto_dir, proto_file=fn)
30-
29+
print(f"Compiling protobuf: {fn}")
30+
31+
command = [
32+
'grpc_tools.protoc',
33+
f'-I{proto_dir}',
34+
f'-I{grpc_protos_include}', # <--- CRITICAL FIX: Add standard protos to include path
35+
f'--python_out={proto_dir}',
36+
f'--grpc_python_out={proto_dir}',
37+
str(fn)
38+
]
39+
40+
if protoc.main(command) != 0:
41+
print(f"Error: Failed to compile {fn}")
42+
raise RuntimeError(f"Protocol buffer compilation failed for {fn}")
43+
44+
class build_py(_build_py):
45+
"""
46+
Override build_py to compile protos before building the wheel.
47+
This is the hook used by 'python -m build'.
48+
"""
49+
def run(self):
50+
self.execute(install_and_compile_proto, (), msg="Compile protocol buffers")
51+
_build_py.run(self)
3152

3253
class develop(_develop):
33-
"""Post-installation for development mode."""
34-
54+
"""Post-installation for development mode (pip install -e .)."""
3555
def run(self):
56+
self.execute(install_and_compile_proto, (), msg="Compile protocol buffers")
3657
_develop.run(self)
37-
self.execute(install_and_compile_proto, (),
38-
msg="Compile protocol buffers")
39-
4058

4159
class install(_install):
42-
"""Post-installation for installation mode."""
43-
60+
"""Post-installation for legacy installation mode."""
4461
def run(self):
62+
self.execute(install_and_compile_proto, (), msg="Compile protocol buffers")
4563
_install.run(self)
46-
self.execute(install_and_compile_proto, (),
47-
msg="Compile protocol buffers")
48-
4964

5065
setup(
51-
name=PACKAGE_NAME,
52-
version=__version__,
53-
packages=find_namespace_packages(include=['snet*']),
54-
url='https://github.com/singnet/snet-cli',
55-
author="SingularityNET Foundation",
56-
author_email="info@singularitynet.io",
57-
description="SingularityNET CLI",
58-
long_description=long_description,
59-
long_description_content_type='text/markdown',
60-
license="MIT",
61-
python_requires='>=3.10',
62-
install_requires=requirements,
63-
include_package_data=True,
6466
cmdclass={
6567
'develop': develop,
6668
'install': install,
69+
'build_py': build_py,
6770
},
68-
entry_points={
69-
'console_scripts': [
70-
'snet = snet.cli:main'
71-
],
72-
}
73-
)
71+
)

snet/cli/arguments.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,24 @@ def __init__(self, default_choice=None, *args, **kwargs):
2424
super().__init__(*args, **kwargs)
2525

2626
def error(self, message):
27-
sys.stderr.write("error: {}\n\n".format(message))
27+
sys.stderr.write(f"error: {message}\n\n")
2828
self.print_help(sys.stderr)
2929
sys.exit(2)
3030

3131
def _parse_known_args(self, arg_strings, *args, **kwargs):
32-
if self.default_choice and not len(list(filter(lambda option: option in arg_strings, {'-h', '--help'}))):
33-
for action in list(filter(
34-
lambda subparser_action: isinstance(
35-
subparser_action, argparse._SubParsersAction),
36-
self._subparsers._actions
37-
)):
38-
if not len(list(filter(lambda arg: arg in action._name_parser_map.keys(), arg_strings))):
32+
if self.default_choice and not any(arg in arg_strings for arg in {'-h', '--help'}):
33+
34+
subparser_action = next(
35+
(a for a in self._actions if isinstance(a, argparse._SubParsersAction)),
36+
None
37+
)
38+
39+
if subparser_action:
40+
is_subcommand_present = any(
41+
arg in subparser_action.choices for arg in arg_strings
42+
)
43+
44+
if not is_subcommand_present:
3945
arg_strings = [self.default_choice] + arg_strings
4046

4147
return super()._parse_known_args(
@@ -575,8 +581,8 @@ def add_mpe_account_options(parser):
575581
subparsers = parser.add_subparsers(title="Commands", metavar="COMMAND")
576582
subparsers.required = True
577583

578-
def add_p_snt_address_opt(p):
579-
p.add_argument(
584+
def add_p_snt_address_opt(_p):
585+
_p.add_argument(
580586
"--singularitynettoken-at", "--snt", default=None,
581587
help="Address of SingularityNetToken contract, if not specified we read address from \"networks\"")
582588

@@ -1153,7 +1159,7 @@ def add_mpe_service_options(parser):
11531159
p.add_argument("name", help="Name of the contributor")
11541160
p.add_argument("email_id", help="Email of the contributor")
11551161

1156-
p = subparsers.add_parser("metadata-remove-contributor", help="Add contributor")
1162+
p = subparsers.add_parser("metadata-remove-contributor", help="Remove contributor")
11571163
p.set_defaults(fn="metadata_remove_contributor")
11581164
add_p_metadata_file_opt(p)
11591165
p.add_argument("email_id", help="Email of the contributor")

0 commit comments

Comments
 (0)