Skip to content

Commit

Permalink
Merge pull request #2191 from opentensor/feat/roman/btsdk
Browse files Browse the repository at this point in the history
Part1: Removing content related to the wallet. Start use the pip installable package.
  • Loading branch information
roman-opentensor authored Jul 30, 2024
2 parents 36b9b0c + 7b770a8 commit 15ee01f
Show file tree
Hide file tree
Showing 49 changed files with 285 additions and 6,873 deletions.
28 changes: 16 additions & 12 deletions bittensor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
# Copyright © 2022-2023 Opentensor Foundation
# Copyright © 2023 Opentensor Technologies Inc

# Copyright © 2024 Opentensor Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

import os
import warnings

Expand Down Expand Up @@ -277,7 +276,6 @@ def debug(on: bool = True):
IdentityError,
InternalServerError,
InvalidRequestNameError,
KeyFileError,
MetadataError,
NominationError,
NotDelegateError,
Expand All @@ -295,9 +293,16 @@ def debug(on: bool = True):
UnstakeError,
)

from bittensor_wallet.errors import KeyFileError

from substrateinterface import Keypair # noqa: F401
from .config import InvalidConfigFile, DefaultConfig, config, T
from .keyfile import (
from bittensor_wallet.config import (
InvalidConfigFile,
DefaultConfig,
Config as config,
T,
)
from bittensor_wallet.keyfile import (
serialized_keypair_to_keyfile_data,
deserialize_keypair_from_keyfile_data,
validate_password,
Expand All @@ -311,10 +316,9 @@ def debug(on: bool = True):
encrypt_keyfile_data,
get_coldkey_password_from_environment,
decrypt_keyfile_data,
keyfile,
Mockkeyfile,
Keyfile as keyfile,
)
from .wallet import display_mnemonic_msg, wallet
from bittensor_wallet.wallet import display_mnemonic_msg, Wallet as wallet

from .utils import (
ss58_to_vec_u8,
Expand Down
27 changes: 15 additions & 12 deletions bittensor/axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,31 +333,31 @@ def __init__(
"max_workers", bittensor.defaults.axon.max_workers
)
axon.check_config(config)
self.config = config # type: ignore [method-assign]
self.config = config # type: ignore

# Get wallet or use default.
self.wallet = wallet or bittensor.wallet()

# Build axon objects.
self.uuid = str(uuid.uuid1())
self.ip = self.config.axon.ip
self.port = self.config.axon.port
self.ip = self.config.axon.ip # type: ignore
self.port = self.config.axon.port # type: ignore
self.external_ip = (
self.config.axon.external_ip
if self.config.axon.external_ip is not None
self.config.axon.external_ip # type: ignore
if self.config.axon.external_ip is not None # type: ignore
else bittensor.utils.networking.get_external_ip()
)
self.external_port = (
self.config.axon.external_port
if self.config.axon.external_port is not None
else self.config.axon.port
self.config.axon.external_port # type: ignore
if self.config.axon.external_port is not None # type: ignore
else self.config.axon.port # type: ignore
)
self.full_address = str(self.config.axon.ip) + ":" + str(self.config.axon.port)
self.full_address = str(self.config.axon.ip) + ":" + str(self.config.axon.port) # type: ignore
self.started = False

# Build middleware
self.thread_pool = bittensor.PriorityThreadPoolExecutor(
max_workers=self.config.axon.max_workers
max_workers=self.config.axon.max_workers # type: ignore
)
self.nonces: Dict[str, int] = {}

Expand All @@ -372,9 +372,12 @@ def __init__(
self.app = FastAPI()
log_level = "trace" if bittensor.logging.__trace_on__ else "critical"
self.fast_config = uvicorn.Config(
self.app, host="0.0.0.0", port=self.config.axon.port, log_level=log_level
self.app,
host="0.0.0.0",
port=self.config.axon.port, # type: ignore
log_level=log_level, # type: ignore
)
self.fast_server = FastAPIThreadedServer(config=self.fast_config)
self.fast_server = FastAPIThreadedServer(config=self.fast_config) # type: ignore
self.router = APIRouter()
self.app.include_router(self.router)

Expand Down
24 changes: 12 additions & 12 deletions bittensor/btlogging/loggingmachine.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# The MIT License (MIT)
# Copyright © 2023 OpenTensor Foundation

# Copyright © 2024 Opentensor Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
# the Software.

#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
Expand All @@ -31,9 +31,9 @@
from logging.handlers import QueueHandler, QueueListener, RotatingFileHandler
from typing import NamedTuple

from bittensor_wallet.config import Config
from statemachine import State, StateMachine

import bittensor.config
from bittensor.btlogging.defines import (
BITTENSOR_LOGGER_NAME,
DATE_FORMAT,
Expand All @@ -42,8 +42,8 @@
DEFAULT_MAX_ROTATING_LOG_FILE_SIZE,
TRACE_LOG_FORMAT,
)
from bittensor.btlogging.format import BtFileFormatter, BtStreamFormatter
from bittensor.btlogging.helpers import all_loggers
from .format import BtFileFormatter, BtStreamFormatter
from .helpers import all_loggers


class LoggingConfig(NamedTuple):
Expand Down Expand Up @@ -89,7 +89,7 @@ class LoggingMachine(StateMachine):
| Disabled.to(Disabled)
)

def __init__(self, config: bittensor.config, name: str = BITTENSOR_LOGGER_NAME):
def __init__(self, config: "Config", name: str = BITTENSOR_LOGGER_NAME):
# basics
super(LoggingMachine, self).__init__()
self._queue = mp.Queue(-1)
Expand Down Expand Up @@ -429,7 +429,7 @@ def get_level(self) -> int:
"""Returns Logging level."""
return self._logger.level

def check_config(self, config: bittensor.config):
def check_config(self, config: "Config"):
assert config.logging

def help(self):
Expand Down Expand Up @@ -475,19 +475,19 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None):
pass

@classmethod
def config(cls) -> bittensor.config:
def config(cls) -> "Config":
"""Get config from the argument parser.
Return:
config (bittensor.config): config object
"""
parser = argparse.ArgumentParser()
cls.add_args(parser)
return bittensor.config(parser, args=[])
return Config(parser, args=[])

def __call__(
self,
config: bittensor.config = None,
config: "Config" = None,
debug: bool = None,
trace: bool = None,
record_log: bool = None,
Expand Down
Loading

0 comments on commit 15ee01f

Please sign in to comment.