Esempio n. 1
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()
Esempio n. 2
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()
Esempio n. 3
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()