Exemple #1
0
    def load(profile, name):
        """
        Loads a single package from a profile.

        Includes ancestors, which are merged in as appropriate. This
        involves a transform pipeline to put the spec on a simple
        format where all information in ancestors is inlined, and
        stages are ordered.

        Parameters
        ----------

        profile : :class:`~hashdist.spec.profile.Profile`
            The profile, which defines parameters to be used.

        name : str
            The package name. This may be different from the name of
            the yaml file if you override ``pkg_name: {use:
            alternate_name}`` in the profile.
        """
        package_parameters = defaultdict(str, profile.parameters)
        package_parameters.update(profile.packages.get(name, {}))
        package_parameters['package'] = name
        from package_loader import PackageLoader
        loader = PackageLoader(name,
                               package_parameters,
                               load_yaml=profile.load_package_yaml)
        return PackageSpec(name, loader.stages_topo_ordered(),
                           loader.get_hook_files(), loader.parameters)
Exemple #2
0
    def load(profile, name):
        """
        Loads a single package from a profile.

        Includes ancestors, which are merged in as appropriate. This
        involves a transform pipeline to put the spec on a simple
        format where all information in ancestors is inlined, and
        stages are ordered.

        Parameters
        ----------

        profile : :class:`~hashdist.spec.profile.Profile`
            The profile, which defines parameters to be used.

        name : str
            The package name. This may be different from the name of
            the yaml file if you override ``pkg_name: {use:
            alternate_name}`` in the profile.
        """
        package_parameters = defaultdict(str, profile.parameters)
        package_parameters.update(profile.packages.get(name, {}))
        package_parameters["package"] = name
        from package_loader import PackageLoader

        loader = PackageLoader(name, package_parameters, load_yaml=profile.load_package_yaml)
        return PackageSpec(name, loader.stages_topo_ordered(), loader.get_hook_files(), loader.parameters)
Exemple #3
0
def install():
    loader = PackageLoader()
    package = loader.load(os.getcwd())

    client_factory = DockerClientFactory()
    client = client_factory.get_client()

    container = client.create_container(
        image=package.current_image,
        stdin_open=True,
        tty=True,
        command="pip install flask",
        working_dir=MOUNT_DIRECTORY,
        host_config=client.create_host_config(binds={
            os.getcwd(): {
                "bind": MOUNT_DIRECTORY,
                "mode": "rw"
            }
        })
    )

    dockerpty.start(client, container)

    # Update package image
    package.current_image = client.commit(container.get("Id")).get("Id")
    loader.save(os.getcwd(), package)
Exemple #4
0
def init(name, version, description, entry_point, base_image):
    package = Package(name, version, description, entry_point, base_image)

    loader = PackageLoader()

    generator = loader.save(os.getcwd(), package,
                            should_require_confirmation=True)
    package_file_path, package_file_contents = generator.next()

    click.echo()
    click.echo(click.style("About to write to {}:".format(package_file_path),
                           fg="green", bold=True))
    click.echo()

    click.echo(package_file_contents)
    click.echo()

    if click.confirm(click.style("Is this OK?", fg="green"), default=True):
        generator.next()
    else:
        click.echo(click.style("Aborted.", fg="red", bold=True))
Exemple #5
0
def run():
    loader = PackageLoader()
    package = loader.load(os.getcwd())

    client_factory = DockerClientFactory()
    client = client_factory.get_client()

    container = client.create_container(
        image=package.current_image,
        stdin_open=True,
        tty=True,
        command="python {}".format(package.entry_point),
        working_dir=MOUNT_DIRECTORY,
        host_config=client.create_host_config(binds={
            os.getcwd(): {
                "bind": MOUNT_DIRECTORY,
                "mode": "rw"
            }
        })
    )

    dockerpty.start(client, container)
Exemple #6
0
def main():
    sys.setrecursionlimit(10000)

    PackageName = lambda s: Name.fromString(s, isPackageName=True)
    cmdline = argparse.ArgumentParser(
        description="Compile source files into CodeSwitch packages")
    cmdline.add_argument("sources",
                         metavar="source",
                         type=str,
                         nargs="+",
                         help="Source file names")
    cmdline.add_argument("-p",
                         "--package-name",
                         action="store",
                         type=PackageName,
                         default=PackageName("default"),
                         help="Name of the package being compiled")
    cmdline.add_argument("-v",
                         "--package-version",
                         action="store",
                         type=PackageVersion.fromString,
                         default=PackageVersion([0]),
                         help="Version of the package being compiled")
    cmdline.add_argument("-d",
                         "--depends",
                         action="append",
                         type=str,
                         default=[],
                         help="Additional package dependencies")
    cmdline.add_argument(
        "--no-std",
        action="store_true",
        help="Do not add a dependency on the standard library")
    cmdline.add_argument(
        "-P",
        "--package-path",
        action="append",
        type=str,
        default=[],
        help="Directories containing packages that could be imported")
    cmdline.add_argument("-o",
                         "--output",
                         action="store",
                         default="out.csp",
                         help="Name of the output file")
    cmdline.add_argument("--print-tokens",
                         action="store_true",
                         help="Print tokens after lexical analysis")
    cmdline.add_argument(
        "--print-ast",
        action="store_true",
        help="Print abstract syntax tree after syntax analysis")
    cmdline.add_argument("--print-scope",
                         action="store_true",
                         help="Print scope info after scope analysis")
    cmdline.add_argument("--print-types",
                         action="store_true",
                         help="Print types after type analysis")
    cmdline.add_argument(
        "--print-ir",
        action="store_true",
        help="Print intermediate representation after compilation")
    cmdline.add_argument("--print-stack",
                         action="store_true",
                         help="Print compiler stack on error")
    args = cmdline.parse_args()

    try:
        astModules = []
        for sourceFileName in args.sources:
            with open(sourceFileName) as inFile:
                source = inFile.read()
            tokens = lex(sourceFileName, source)
            if args.print_tokens:
                for tok in tokens:
                    sys.stdout.write(str(tok) + "\n")
            astModule = parse(sourceFileName, tokens)
            if args.print_ast:
                printer = ast.Printer(sys.stdout)
                printer.visit(astModule)
            astModules.append(astModule)
        astPackage = ast.Package(astModules, NoLoc)
        astPackage.id = AstId(-1)

        package = Package(TARGET_PACKAGE_ID, args.package_name,
                          args.package_version)
        loader = PackageLoader(
            args.package_path if len(args.package_path) > 0 else None)
        loader.ensurePackageInfo()
        if len(args.depends) > 0:
            depPackages = loader.loadPackageFiles(args.depends)
            each(package.ensureDependency, depPackages)
        isUsingStd = not args.no_std
        if isUsingStd:
            stdPackage = loader.loadPackage(STD_NAME, NoLoc)
            package.ensureDependency(stdPackage)
        info = CompileInfo(astPackage, package, loader, isUsingStd=isUsingStd)

        analyzeDeclarations(info)
        if args.print_scope:
            sys.stderr.write("--print-scope not supported right now\n")
        analyzeTypeDeclarations(info)
        analyzeInheritance(info)
        analyzeTypes(info)
        if args.print_types:
            sys.stderr.write("--print-types not supported right now\n")
        convertClosures(info)
        externalize(info)
        compile(info)

        package = info.package
        if args.print_ir:
            sys.stdout.write("%s\n" % str(package))
        serialize(package, args.output)

    except (CompileException, IOError) as err:
        if args.print_stack:
            raise
        if isinstance(err, CompileException):
            sys.stderr.write("%s\n" % str(err))
        else:
            sys.stderr.write("%s: error: %s\n" % (sourceFileName, str(err)))
        sys.exit(1)