Ejemplo n.º 1
0
def generate_doc() -> None:
    """Compile solidity contracts, extract json docs and generate rst files from them"""

    GlobalLoggerSettings.start_console_logging()

    base_dir = Path(__file__).parent.parent.parent.resolve()
    solidity_source_root = base_dir / 'nucypher' / 'blockchain' / 'eth' / 'sol' / 'source'

    bundle = SourceBundle(base_path=solidity_source_root)
    contracts = multiversion_compile(source_bundles=[bundle])

    # Prepare folders
    base_path = base_dir / 'docs' / 'source' / 'contracts_api'
    base_path.mkdir(exist_ok=True)
    for dir in CONTRACTS.keys():
        category_path = base_path / dir
        category_path.mkdir(exist_ok=True)

    contract_names = {
        contract
        for contracts in CONTRACTS.values() for contract in contracts
    }
    patch()
    for contract, data in contracts.items():
        if contract not in contract_names:
            continue

        # Merge, update and generate resulting rst
        no_version = next(iter(data.values()))
        docs = merge_and_update(no_version["userdoc"], dict())
        docs = merge_and_update(no_version["devdoc"], docs)
        rst = schema2rst(docs, "kind,version,title", contract)

        # Find proper category and write file
        category_path = base_path
        for category, contracts in CONTRACTS.items():
            if contract in contracts:
                category_path /= category
        with open(category_path / f"{contract}.rst", 'w') as file:
            file.write(rst)
Ejemplo n.º 2
0
from nucypher.blockchain.eth.signers.base import Signer
from nucypher.characters.lawful import Alice, Bob
from nucypher.characters.lawful import Enrico as Enrico
from nucypher.crypto.powers import SigningPower, DecryptingPower
from nucypher.policy.payment import SubscriptionManagerPayment
from nucypher.utilities.ethereum import connect_web3_provider
from nucypher.utilities.logging import GlobalLoggerSettings

######################
# Boring setup stuff #
######################

LOG_LEVEL = 'info'
GlobalLoggerSettings.set_log_level(log_level_name=LOG_LEVEL)
GlobalLoggerSettings.start_console_logging()

BOOK_PATH = Path('finnegans-wake-excerpt.txt')

try:

    # Replace with ethereum RPC endpoint
    L1_PROVIDER = os.environ['DEMO_L1_PROVIDER_URI']
    L2_PROVIDER = os.environ['DEMO_L2_PROVIDER_URI']

    # Replace with wallet filepath.
    WALLET_FILEPATH = os.environ['DEMO_L2_WALLET_FILEPATH']
    SIGNER_URI = f'keystore://{WALLET_FILEPATH}'

    # Replace with alice's ethereum address
    ALICE_ADDRESS = os.environ['DEMO_ALICE_ADDRESS']
Ejemplo n.º 3
0
    def __init__(self, json_ipc: bool, verbose: bool, quiet: bool,
                 no_logs: bool, console_logs: bool, file_logs: bool,
                 sentry_logs: bool, log_level: bool, debug: bool):

        self.log = Logger(self.__class__.__name__)

        # Session Emitter for pre and post character control engagement.
        if verbose and quiet:
            raise click.BadOptionUsage(
                option_name="quiet",
                message="--verbose and --quiet are mutually exclusive "
                "and cannot be used at the same time.")

        if verbose:
            GroupGeneralConfig.verbosity = 2
        elif quiet:
            GroupGeneralConfig.verbosity = 0
        else:
            GroupGeneralConfig.verbosity = 1

        if json_ipc:
            GlobalLoggerSettings._json_ipc = True  # TODO #1754
            emitter = JSONRPCStdoutEmitter(
                verbosity=GroupGeneralConfig.verbosity)
        else:
            emitter = StdoutEmitter(verbosity=GroupGeneralConfig.verbosity)

        self.emitter = emitter

        if verbose:
            self.emitter.message("Verbose mode is enabled", color='blue')

        # Logging
        if debug and no_logs:
            message = "--debug and --no-logs cannot be used at the same time."
            raise click.BadOptionUsage(option_name="no-logs", message=message)

        # Defaults
        if file_logs is None:
            file_logs = self.log_to_file
        if sentry_logs is None:
            sentry_logs = self.log_to_sentry

        if debug:
            console_logs = True
            file_logs = True
            sentry_logs = False
            log_level = 'debug'

        if no_logs:
            console_logs = False
            file_logs = False
            sentry_logs = False
        if json_ipc:
            console_logs = False

        GlobalLoggerSettings.set_log_level(log_level_name=log_level)

        if console_logs:
            GlobalLoggerSettings.start_console_logging()
        if file_logs:
            GlobalLoggerSettings.start_text_file_logging()
            GlobalLoggerSettings.start_json_file_logging()
        if sentry_logs:
            GlobalLoggerSettings.start_sentry_logging(self.sentry_endpoint)
        if json_ipc:
            GlobalLoggerSettings.stop_console_logging()  # JSON-RPC Protection

        self.debug = debug
        self.json_ipc = json_ipc
Ejemplo n.º 4
0
def setup():
    """Prepares the filesystem and logger for grant metrics collection"""
    shutil.rmtree(TEMP_ALICE_DIR, ignore_errors=True)
    GlobalLoggerSettings.start_console_logging()
    GlobalLoggerSettings.set_log_level('info')
Ejemplo n.º 5
0
    def set_options(self, mock_networking, no_registry, json_ipc, verbose,
                    quiet, no_logs, console_logs, file_logs, sentry_logs,
                    log_level, debug):

        # Session Emitter for pre and post character control engagement.
        if verbose and quiet:
            raise click.BadOptionUsage(
                option_name="quiet",
                message="--verbose and --quiet are mutually exclusive "
                "and cannot be used at the same time.")

        if verbose:
            verbosity = 2
        elif quiet:
            verbosity = 0
        else:
            verbosity = 1

        if json_ipc:
            emitter = JSONRPCStdoutEmitter(verbosity=verbosity)
        else:
            emitter = StdoutEmitter(verbosity=verbosity)

        self.attach_emitter(emitter)

        if verbose:
            self.emitter.message("Verbose mode is enabled", color='blue')

        # Logging

        if debug and no_logs:
            raise click.BadOptionUsage(
                option_name="no-logs",
                message="--debug and --no-logs cannot be used at the same time."
            )

        # Defaults
        if file_logs is None:
            file_logs = self.log_to_file
        if sentry_logs is None:
            sentry_logs = self.log_to_sentry

        if debug:
            console_logs = True
            file_logs = True
            sentry_logs = False
            log_level = 'debug'

        if no_logs:
            console_logs = False
            file_logs = False
            sentry_logs = False

        GlobalLoggerSettings.set_log_level(log_level_name=log_level)

        if console_logs:
            GlobalLoggerSettings.start_console_logging()
        if file_logs:
            GlobalLoggerSettings.start_text_file_logging()
            GlobalLoggerSettings.start_json_file_logging()
        if sentry_logs:
            GlobalLoggerSettings.start_sentry_logging(self.sentry_endpoint)

        # CLI Session Configuration
        self.mock_networking = mock_networking
        self.no_registry = no_registry
        self.debug = debug
        self.json_ipc = json_ipc

        # Only used for testing outputs;
        # Redirects outputs to in-memory python containers.
        if mock_networking:
            self.emitter.message("WARNING: Mock networking is enabled")
            self.middleware = MockRestMiddleware()
        else:
            self.middleware = RestMiddleware()