示例#1
0
 def on_any_event(self, event):
     click.echo("============ Detected Change ==============")
     click.echo("> {0} => {1}".format(event.event_type, event.src_path))
     click.echo("> recompiling...")
     compile_and_write_contracts(self.project_dir, *self.contract_filters,
                                 **self.compiler_kwargs)
     click.echo("> watching...")
示例#2
0
 def on_any_event(self, event):
     click.echo("============ Detected Change ==============")
     click.echo("> {0} => {1}".format(event.event_type, event.src_path))
     click.echo("> recompiling...")
     compile_and_write_contracts(
         self.project_dir,
         *self.contract_filters,
         **self.compiler_kwargs
     )
     click.echo("> watching...")
示例#3
0
def compile_project_contracts(project, optimize=True):
    click.echo("============ Compiling ==============")
    click.echo("> Loading source files from: ./{0}\n".format(project.contracts_dir))

    result = compile_and_write_contracts(
        project.project_dir,
        project.contracts_dir,
        optimize=optimize
    )
    contract_source_paths, compiled_sources, output_file_path = result

    click.echo("> Found {0} contract source files".format(
        len(contract_source_paths)
    ))
    for path in contract_source_paths:
        click.echo("- {0}".format(os.path.relpath(path)))
    click.echo("")
    click.echo("> Compiled {0} contracts".format(len(compiled_sources)))

    for contract_name in sorted(compiled_sources.keys()):
        click.echo("- {0}".format(contract_name))

    click.echo("")
    click.echo(
        "> Wrote compiled assets to: ./{0}".format(
            os.path.relpath(output_file_path)
        )
    )
def test_compilation(project_dir, write_project_file):
    write_project_file('contracts/ContractA.sol', CONTRACT_A_SOURCE)
    write_project_file('contracts/ContractB.sol', CONTRACT_B_SOURCE)
    write_project_file('contracts/ContractC.sol', CONTRACT_C_SOURCE)

    source_paths, compiled_sources, outfile_path = compile_and_write_contracts(project_dir)

    with open(outfile_path) as outfile:
        compiled_contract_data = json.load(outfile)

    assert 'A' in compiled_contract_data
    assert 'B' in compiled_contract_data
    assert 'C' in compiled_contract_data
示例#5
0
def test_compilation(project_dir, write_project_file):
    write_project_file('contracts/ContractA.sol', CONTRACT_A_SOURCE)
    write_project_file('contracts/ContractB.sol', CONTRACT_B_SOURCE)
    write_project_file('contracts/ContractC.sol', CONTRACT_C_SOURCE)

    source_paths, compiled_sources, outfile_path = compile_and_write_contracts(project_dir, DEFAULT_CONTRACTS_DIR)

    with open(outfile_path) as outfile:
        compiled_contract_data = json.load(outfile)

    assert 'A' in compiled_contract_data
    assert 'B' in compiled_contract_data
    assert 'C' in compiled_contract_data
示例#6
0
def compile_contracts(watch, contracts):
    """
    Compile project contracts, storing their output in `./build/contracts.json`

    Call bare to compile all contracts or specify contract names or file paths
    to restrict to only compiling those contracts.

    Pass in a file path and a contract name separated by a colon(":") to
    specify only named contracts in the specified file.
    """
    project_dir = os.getcwd()

    click.echo("============ Compiling ==============")
    click.echo("> Loading contracts from: {0}".format(
        get_contracts_dir(project_dir)))

    result = compile_and_write_contracts(project_dir, *contracts)
    contract_source_paths, compiled_sources, output_file_path = result

    click.echo("> Found {0} contract source files".format(
        len(contract_source_paths)))
    for path in contract_source_paths:
        click.echo("- {0}".format(os.path.basename(path)))
    click.echo("")
    click.echo("> Compiled {0} contracts".format(len(compiled_sources)))
    for contract_name in sorted(compiled_sources.keys()):
        click.echo("- {0}".format(contract_name))
    click.echo("")
    click.echo("> Outfile: {0}".format(output_file_path))

    if watch:
        # The path to watch
        watch_path = utils.get_contracts_dir(project_dir)

        click.echo("============ Watching ==============")

        event_handler = ContractChangedEventHandler(
            project_dir=project_dir,
            contract_filters=contracts,
        )
        observer = PollingObserver()
        observer.schedule(event_handler, watch_path, recursive=True)
        observer.start()
        try:
            while observer.is_alive():
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join()
示例#7
0
def compile_contracts(watch, optimize, filters):
    """
    Compile project contracts, storing their output in `./build/contracts.json`

    Call bare to compile all contracts or specify contract names or file paths
    to restrict to only compiling those contracts.

    Pass in a file path and a contract name separated by a colon(":") to
    specify only named contracts in the specified file.
    """
    project_dir = os.getcwd()

    click.echo("============ Compiling ==============")
    click.echo("> Loading contracts from: {0}".format(get_contracts_dir(project_dir)))

    result = compile_and_write_contracts(project_dir, *filters, optimize=optimize)
    contract_source_paths, compiled_sources, output_file_path = result

    click.echo("> Found {0} contract source files".format(len(contract_source_paths)))
    for path in contract_source_paths:
        click.echo("- {0}".format(os.path.basename(path)))
    click.echo("")
    click.echo("> Compiled {0} contracts".format(len(compiled_sources)))
    for contract_name in sorted(compiled_sources.keys()):
        click.echo("- {0}".format(contract_name))
    click.echo("")
    click.echo("> Outfile: {0}".format(output_file_path))

    if watch:
        # The path to watch
        click.echo("============ Watching ==============")

        observer = get_contracts_observer(project_dir, filters, {'optimize': optimize})
        observer.start()
        try:
            while observer.is_alive():
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join()
def test_compilation():
    compile_and_write_contracts(project_dir)
def test_compilation():
    compile_and_write_contracts(project_dir)
示例#10
0
def web_runserver(debug):
    """
    Run the development server.
    """
    project_dir = os.getcwd()
    # Do initial setup
    click.echo("Compiling contracts...")
    compile_and_write_contracts(project_dir)
    click.echo("Compiling contracts.js...")
    compile_js_contracts(project_dir)
    click.echo("Collectind static assets...")
    collect_static_assets(project_dir)

    all_threads = []

    # Contract Builder Thread
    contracts_observer_thread = get_contracts_observer(project_dir)
    contracts_observer_thread.daemon = True

    # Contract JS Builder Thread
    contracts_code_observer_thread = get_contracts_code_observer(project_dir)
    contracts_code_observer_thread.daemon = True

    # Assets Collector Thread
    static_assets_observer_thread = get_static_assets_observer(project_dir)
    static_assets_observer_thread.daemon = True

    # Webserver Thread
    flask_app = get_flask_app(project_dir)
    webserver_thread = multiprocessing.Process(
        target=flask_app.run,
        kwargs={'use_reloader': False, 'debug': debug},
    )
    webserver_thread.daemon = True

    # Start all the threads
    contracts_observer_thread.start()
    contracts_code_observer_thread.start()
    static_assets_observer_thread.start()
    webserver_thread.start()

    try:
        all_threads = (
            contracts_observer_thread,
            contracts_code_observer_thread,
            static_assets_observer_thread,
            webserver_thread,
        )
        while any(t.is_alive() for t in all_threads):
            if not all(t.is_alive() for t in all_threads):
                raise click.Abort("Some threads died!")
            time.sleep(1)
    except KeyboardInterrupt:
        for t in all_threads:
            if hasattr(t, 'stop'):
                t.stop()
            elif hasattr(t, 'terminate'):
                t.terminate()
            else:
                raise ValueError("wat")
        for t in all_threads:
            t.join()