示例#1
0
    def __init__(self, filepaths, params=None, debug_ttl=False):
        filepaths = to_list(filepaths)
        for filepath in filepaths:
            if not os.path.isfile(filepath):
                raise PolyaxonfileError(
                    "`{}` must be a valid file".format(filepath))
        self._filenames = [
            os.path.basename(filepath) for filepath in filepaths
        ]
        if params:
            if not isinstance(params, Mapping):
                raise PolyaxonfileError(
                    "Params: `{}` must be a valid mapping".format(params))
            filepaths.append({'params': params})
        if debug_ttl:
            if not isinstance(debug_ttl, int):
                raise PolyaxonfileError(
                    "Debug TTL `{}` must be a valid integer".format(debug_ttl))
            filepaths.append({'run': {'cmd': 'sleep {}'.format(debug_ttl)}})
        data = rhea.read(filepaths)
        kind = BaseSpecification.get_kind(data=data)

        debug_cond = (debug_ttl
                      and not (BaseSpecification.check_kind_experiment(kind)
                               or BaseSpecification.check_kind_job(kind)))
        if debug_cond:
            raise PolyaxonfileError(
                'You can only trigger debug mode on a job or an experiment specification, '
                'received instead a `{}` specification'.format(kind))
        try:
            self.specification = SPECIFICATION_BY_KIND[kind](data)
        except PolyaxonConfigurationError as e:
            raise PolyaxonfileError(e)
示例#2
0
def resume(ctx, file, u):  # pylint:disable=redefined-builtin
    """Resume experiment.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon experiment --experiment=1 resume
    ```
    """
    config = None
    update_code = None
    if file:
        config = rhea.read(file)

    # Check if we need to upload
    if u:
        ctx.invoke(upload, sync=False)
        update_code = True

    user, project_name, _experiment = get_project_experiment_or_local(ctx.obj.get('project'),
                                                                      ctx.obj.get('experiment'))
    try:
        response = PolyaxonClient().experiment.resume(
            user, project_name, _experiment, config=config, update_code=update_code)
        Printer.print_success('Experiment was resumed with id {}'.format(response.id))
    except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e:
        Printer.print_error('Could not resume experiment `{}`.'.format(_experiment))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)
示例#3
0
def resume(ctx, polyaxonfile, u):
    """Resume run.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon runs --uid=8aac02e3a62a4f0aaa257c59da5eab80 resume
    ```
    """
    content = None
    if polyaxonfile:
        content = "{}".format(rhea.read(polyaxonfile))

    # Check if we need to upload
    if u:
        ctx.invoke(upload, sync=False)

    owner, project_name, run_uuid = get_project_run_or_local(
        ctx.obj.get("project"), ctx.obj.get("run_uuid"))
    try:
        polyaxon_client = PolyaxonClient()
        body = V1Run(content=content)
        response = polyaxon_client.runs_v1.resume_run(owner, project_name,
                                                      run_uuid, body)
        Printer.print_success("Run was resumed with uid {}".format(
            response.uuid))
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not resume run `{}`.".format(run_uuid))
        sys.exit(1)
示例#4
0
    def __init__(self, filepaths):
        filepaths = to_list(filepaths)
        for filepath in filepaths:
            if not os.path.isfile(filepath):
                raise PolyaxonfileError(
                    "`{}` must be a valid file".format(filepath))
        self._filenames = [
            os.path.basename(filepath) for filepath in filepaths
        ]

        self.specification = get_specification(data=rhea.read(filepaths))
示例#5
0
 def __init__(self, filepaths):
     filepaths = to_list(filepaths)
     for filepath in filepaths:
         if not os.path.isfile(filepath):
             raise PolyaxonfileError(
                 "`{}` must be a valid file".format(filepath))
     self._filenames = [
         os.path.basename(filepath) for filepath in filepaths
     ]
     data = rhea.read(filepaths)
     kind = BaseSpecification.get_kind(data=data)
     try:
         self.specification = SPECIFICATION_BY_KIND[kind](data)
     except PolyaxonConfigurationError as e:
         raise PolyaxonfileError(e)
示例#6
0
文件: base.py 项目: klonggan/polyaxon
    def __init__(self, values):
        self._values = to_list(values)

        try:
            self._data = rhea.read([{
                "kind": self._SPEC_KIND,
                "version": SCHEMA_VERSION
            }] + self._values)
        except rhea.RheaError as e:
            raise PolyaxonSchemaError("%s" % e)
        try:
            self._config = self.CONFIG.from_dict(copy.deepcopy(self.data))
        except (ValidationError, TypeError) as e:
            raise PolyaxonfileError(
                "Received a non valid config `{}`: `{}`".format(
                    self._SPEC_KIND, e))
        self.check_data()
        self._extra_validation()
示例#7
0
    def __init__(self, values):
        self._values = to_list(values)

        try:
            self._data = rhea.read(self._values)
        except rhea.RheaError as e:
            raise PolyaxonConfigurationError(e)
        self.check_data()
        headers = Parser.get_headers(spec=self, data=self._data)
        try:
            self._headers = validator.validate_headers(spec=self, data=headers)
        except ValidationError as e:
            raise PolyaxonConfigurationError(e)
        self._parsed_data = None
        self._validated_data = None
        self._config = None
        self._set_parsed_data()
        self._extra_validation()
示例#8
0
def restart(ctx, copy, file, u):  # pylint:disable=redefined-builtin
    """Restart job.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon job --job=1 restart
    ```
    """
    content = None
    update_code = None
    if file:
        content = '{}'.format(rhea.read(file))

    # Check if we need to upload
    if u:
        ctx.invoke(upload, sync=False)
        update_code = True

    user, project_name, _job = get_job_or_local(ctx.obj.get('project'),
                                                ctx.obj.get('job'))
    try:
        if copy:
            response = PolyaxonClient().job.copy(user,
                                                 project_name,
                                                 _job,
                                                 content=content,
                                                 update_code=update_code)
        else:
            response = PolyaxonClient().job.restart(user,
                                                    project_name,
                                                    _job,
                                                    content=content,
                                                    update_code=update_code)
    except (PolyaxonHTTPError, PolyaxonShouldExitError,
            PolyaxonClientException) as e:
        Printer.print_error('Could not restart job `{}`.'.format(_job))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    get_job_details(response)
示例#9
0
def resume(ctx, file, u):  # pylint:disable=redefined-builtin
    """Resume job.

    Uses [Caching](/polyaxon_cli/introduction#Caching)

    Examples:

    \b
    ```bash
    $ polyaxon job --job=1 resume
    ```
    """
    config = None
    update_code = None
    if file:
        config = rhea.read(file)

    # Check if we need to upload
    if u:
        ctx.invoke(upload)
        update_code = True

    user, project_name, _job = get_job_or_local(ctx.obj.get('project'),
                                                ctx.obj.get('job'))
    try:
        response = PolyaxonClient().job.resume(user,
                                               project_name,
                                               _job,
                                               config=config,
                                               update_code=update_code)
    except (PolyaxonHTTPError, PolyaxonShouldExitError,
            PolyaxonClientException) as e:
        Printer.print_error('Could not resume job `{}`.'.format(_job))
        Printer.print_error('Error message `{}`.'.format(e))
        sys.exit(1)

    get_job_details(response)
示例#10
0
def generate(polyaxonfile, build_context, destination, params):
    """Generate a dockerfile given the polyaxonfile."""
    if all([polyaxonfile, build_context]):
        Printer.print_error(
            "Only a polyaxonfile or a build context option is required.")
        sys.exit(1)

    if build_context:
        try:
            build_context = BuildContextConfig.from_dict(
                rhea.read(build_context))
        except (RheaError, ValidationError) as e:
            Printer.print_error("received a non valid build context.")
            Printer.print_error("Error message: {}.".format(e))
            sys.exit(1)
    else:
        specification = check_polyaxonfile(polyaxonfile,
                                           params=params,
                                           log=False)

        try:
            run_spec = get_specification(specification.generate_run_data())
            run_spec.apply_params(params=specification.config.params)
            run_spec.apply_context()
        except PolyaxonSchemaError:
            Printer.print_error(
                "Could not run this polyaxonfile locally, "
                "a context is required to resolve it dependencies.")
            sys.exit(1)

        build_context = run_spec.build_context

    generator = DockerFileGenerator(build_context=build_context,
                                    destination=destination or ".")
    generator.create()
    Printer.print_success("Dockerfile was generated: `{}`".format(
        generator.dockerfile_path))
示例#11
0
def get_specification(data):
    data = rhea.read(data)
    kind = BaseSpecification.get_kind(data=data)
    return SPECIFICATION_BY_KIND[kind](data)
示例#12
0
def read(filepaths):
    data = rhea.read(filepaths)
    return DeploymentConfig.from_dict(data)