Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[build-system]
requires = [
"setuptools>=61.0",
"wheel",
"protobuf~=6.30",
"grpcio-tools~=1.59"
]
build-backend = "setuptools.build_meta"

[project]
name = "snet-cli"
version = "3.0.1"
description = "SingularityNET CLI"
readme = "README.md"
requires-python = ">=3.10"
license = {text = "MIT"}
authors = [
{name = "SingularityNET Foundation", email = "info@singularitynet.io"}
]
urls = {Homepage = "https://github.com/singnet/snet-cli"}

# Cleaned dependencies list
dependencies = [
"protobuf~=6.30",
"grpcio~=1.59",
"grpcio-tools~=1.59",
"wheel~=0.45",
"rlp~=4.0",
"web3~=7.0",
"mnemonic==0.21",
"pyyaml~=6.0.1",
"ipfshttpclient==0.4.13.2",
"pymultihash==0.8.2",
"base58==2.1.1",
"argcomplete~=3.1",
"grpcio-health-checking~=1.59",
"jsonschema~=4.1",
"eth-account~=0.9",
"trezor~=0.13.8",
"ledgerblue~=0.1.48",
"snet-contracts==1.0.1",
"lighthouseweb3~=0.1.4",
"cryptography~=46.0"
]

[project.scripts]
snet = "snet.cli:main"

[tool.setuptools.packages.find]
include = ["snet*"]
41 changes: 21 additions & 20 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
protobuf==4.21.6
grpcio-tools==1.59.0
wheel==0.41.2
jsonrpcclient==4.0.3
eth-hash==0.5.2
rlp==3.0.0
eth-rlp==0.3.0
web3==6.11.1
mnemonic==0.20
pycoin==0.92.20230326
pyyaml==6.0.1
protobuf~=6.30
grpcio~=1.59
grpcio-tools~=1.59
wheel~=0.45
# jsonrpcclient~=4.0
# eth-hash~=0.5
rlp~=4.0
# eth-rlp~=2.0
web3~=7.0
mnemonic==0.21
# pycoin==0.92.20241201
pyyaml~=6.0.1
ipfshttpclient==0.4.13.2
pymultihash==0.8.2
base58==2.1.1
argcomplete==3.1.2
grpcio-health-checking==1.59.0
jsonschema==4.0.0
eth-account==0.9.0
trezor==0.13.8
ledgerblue==0.1.48
snet-contracts==1.0.0
lighthouseweb3==0.1.4
cryptography==44.0.1
argcomplete~=3.1
grpcio-health-checking~=1.59
jsonschema~=4.1
eth-account~=0.9
trezor~=0.13.8
ledgerblue~=0.1.48
snet-contracts==1.0.1
lighthouseweb3~=0.1.4
cryptography~=46.0
96 changes: 47 additions & 49 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,71 @@
import os
from pathlib import Path
from setuptools import find_namespace_packages, setup
from setuptools import setup
from setuptools.command.develop import develop as _develop
from setuptools.command.install import install as _install
from setuptools.command.build_py import build_py as _build_py
from grpc_tools import protoc
from pkg_resources import resource_filename

from snet.cli.utils.utils import compile_proto
from version import __version__

PACKAGE_NAME = 'snet-cli'


this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
def install_and_compile_proto():
"""
Compiles protobuf files directly.
"""
proto_dir = Path(__file__).absolute().parent.joinpath(
"snet", "cli", "resources", "proto")

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

with open("./requirements.txt") as f:
requirements_str = f.read()
requirements = requirements_str.split("\n")
print(f"Proto directory: {proto_dir}")
print(f"Grpc include directory: {grpc_protos_include}")

if not proto_dir.exists():
print(f"Warning: Proto directory not found at {proto_dir}")
return

def install_and_compile_proto():
proto_dir = Path(__file__).absolute().parent.joinpath(
"snet", "cli", "resources", "proto")
print(proto_dir, "->", proto_dir)
# glob('*.proto') is non-recursive. It will NOT look inside subfolders.
for fn in proto_dir.glob('*.proto'):
print("Compiling protobuf", fn)
compile_proto(proto_dir, proto_dir, proto_file=fn)

print(f"Compiling protobuf: {fn}")

command = [
'grpc_tools.protoc',
f'-I{proto_dir}',
f'-I{grpc_protos_include}', # <--- CRITICAL FIX: Add standard protos to include path
f'--python_out={proto_dir}',
f'--grpc_python_out={proto_dir}',
str(fn)
]

if protoc.main(command) != 0:
print(f"Error: Failed to compile {fn}")
raise RuntimeError(f"Protocol buffer compilation failed for {fn}")

class build_py(_build_py):
"""
Override build_py to compile protos before building the wheel.
This is the hook used by 'python -m build'.
"""
def run(self):
self.execute(install_and_compile_proto, (), msg="Compile protocol buffers")
_build_py.run(self)

class develop(_develop):
"""Post-installation for development mode."""

"""Post-installation for development mode (pip install -e .)."""
def run(self):
self.execute(install_and_compile_proto, (), msg="Compile protocol buffers")
_develop.run(self)
self.execute(install_and_compile_proto, (),
msg="Compile protocol buffers")


class install(_install):
"""Post-installation for installation mode."""

"""Post-installation for legacy installation mode."""
def run(self):
self.execute(install_and_compile_proto, (), msg="Compile protocol buffers")
_install.run(self)
self.execute(install_and_compile_proto, (),
msg="Compile protocol buffers")


setup(
name=PACKAGE_NAME,
version=__version__,
packages=find_namespace_packages(include=['snet*']),
url='https://github.com/singnet/snet-cli',
author="SingularityNET Foundation",
author_email="info@singularitynet.io",
description="SingularityNET CLI",
long_description=long_description,
long_description_content_type='text/markdown',
license="MIT",
python_requires='>=3.10',
install_requires=requirements,
include_package_data=True,
cmdclass={
'develop': develop,
'install': install,
'build_py': build_py,
},
entry_points={
'console_scripts': [
'snet = snet.cli:main'
],
}
)
)
26 changes: 16 additions & 10 deletions snet/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@ def __init__(self, default_choice=None, *args, **kwargs):
super().__init__(*args, **kwargs)

def error(self, message):
sys.stderr.write("error: {}\n\n".format(message))
sys.stderr.write(f"error: {message}\n\n")
self.print_help(sys.stderr)
sys.exit(2)

def _parse_known_args(self, arg_strings, *args, **kwargs):
if self.default_choice and not len(list(filter(lambda option: option in arg_strings, {'-h', '--help'}))):
for action in list(filter(
lambda subparser_action: isinstance(
subparser_action, argparse._SubParsersAction),
self._subparsers._actions
)):
if not len(list(filter(lambda arg: arg in action._name_parser_map.keys(), arg_strings))):
if self.default_choice and not any(arg in arg_strings for arg in {'-h', '--help'}):

subparser_action = next(
(a for a in self._actions if isinstance(a, argparse._SubParsersAction)),
None
)

if subparser_action:
is_subcommand_present = any(
arg in subparser_action.choices for arg in arg_strings
)

if not is_subcommand_present:
arg_strings = [self.default_choice] + arg_strings

return super()._parse_known_args(
Expand Down Expand Up @@ -575,8 +581,8 @@ def add_mpe_account_options(parser):
subparsers = parser.add_subparsers(title="Commands", metavar="COMMAND")
subparsers.required = True

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

Expand Down
Loading