コード例 #1
0
    def get_job_by_name(self, job_name: str, project_suuid: str = None) -> Job:
        job_name = job_name.strip()
        job_list = self.list(project_suuid=project_suuid)
        result = None

        matching_jobs = list(filter(lambda x: x.name == job_name, job_list))
        if len(matching_jobs) == 0:
            raise exceptions.GetError("A job with this name is not available. Did you push your code?")

        if len(matching_jobs) > 1:
            raise exceptions.GetError("There are multiple jobs with the same name. You can narrow the selection by "
                                      "providing the project SUUID.")
        result = matching_jobs[0]
        return result
コード例 #2
0
    def get(
        self,
        run,
        include_metrics: bool = False,
        include_variables: bool = False,
    ) -> RunInfo:
        if not run:
            raise exceptions.GetError(
                "Please specify the run SUUID to 'get' a run")

        runinfo = self.gateway.detail(suuid=run)
        if include_metrics:
            # also fetch the metrics for the runs
            metrics = self.gateway.metrics.get(run=runinfo.short_uuid)
            # run.metrics
            runinfo.metrics = metrics

        if include_variables:
            # also fetch the variables for the runs
            variables = self.gateway.variables.get(run=runinfo.short_uuid)
            # add the metrics to the runobjects
            # run.variables
            runinfo.variables = variables

        return runinfo
コード例 #3
0
 def list(self, query_params: dict = None) -> List[RunInfo]:
     url = f"{self.client.base_url}runinfo/"
     r = self.client.get(url, params=query_params)
     if r.status_code != 200:
         raise exceptions.GetError(
             "{} - Something went wrong while retrieving the status "
             "of the run: {}".format(r.status_code, r.reason))
     return [RunInfo(**r) for r in r.json().get("results")]
コード例 #4
0
    def list(self) -> list:
        r = self.client.get(self.base_url)

        if r.status_code != 200:
            raise exceptions.GetError(
                "{} - Something went wrong while retrieving "
                "workspaces: {}".format(r.status_code, r.json())
            )

        return [Workspace(**workspace) for workspace in r.json()]
コード例 #5
0
    def detail(self, suuid: str) -> Project:
        url = f"{self.base_url}{suuid}/"
        r = self.client.get(url)

        if r.status_code != 200:
            raise exceptions.GetError(
                "{} - Something went wrong while retrieving "
                "project info: {}".format(r.status_code, r.json())
            )

        return Project(**r.json())
コード例 #6
0
    def change(self, short_uuid, metrics):
        url = "{}{}/{}/{}/{}/".format(
            self.client.base_url, "runinfo", short_uuid, "metrics", short_uuid
        )

        r = self.client.put(url, json={"metrics": metrics})

        if r.status_code != 200:
            raise exceptions.GetError(
                "{} - Something went wrong while updating metrics "
                ": {}".format(r.status_code, r.json())
            )
コード例 #7
0
    def list(self, project_suuid: str = None) -> list:
        if project_suuid:
            # build url to select for project only
            url = f"{self.client.base_url}project/{project_suuid}/jobs/"
        else:
            url = self.base_url

        r = self.client.get(url)
        if r.status_code != 200:
            raise exceptions.GetError("{} - Something went wrong while retrieving "
                                      "jobs: {}".format(r.status_code, r.json()))

        return [Job(**job) for job in r.json()]
コード例 #8
0
    def get(self, run_suuid: str):
        result_url = f"{self.base_url}{run_suuid}/"

        try:
            result = self.client.get(result_url)
        except Exception as e:
            click.echo(e, err=True)
            sys.exit(1)

        if result.status_code != 200:
            raise exceptions.GetError(
                f"{result.status_code} - We cannot find this result for you")

        return result.content
コード例 #9
0
    def status(self, suuid: str = None) -> RunStatus:
        suuid = suuid or self.run_suuid

        if not suuid:
            raise exceptions.RunError(
                "There is no run SUUID provided. Did you start a run?")

        url = f"{self.client.base_url}status/{suuid}/"

        r = self.client.get(url)
        if r.status_code != 200:
            raise exceptions.GetError(
                "{} - Something went wrong while retrieving the status "
                "of the run: {}".format(r.status_code, r.reason))

        return RunStatus(**r.json())
コード例 #10
0
    def list(self, workspace_suuid: str = None) -> list:
        if not workspace_suuid and self.workspace:
            workspace_suuid = self.workspace.short_suuid

        if workspace_suuid:
            # build url to select for workspace only
            url = f"{self.client.base_url}workspace/{workspace_suuid}/projects/"
        else:
            url = self.base_url

        r = self.client.get(url)
        if r.status_code != 200:
            raise exceptions.GetError(
                "{} - Something went wrong while retrieving "
                "projects: {}".format(r.status_code, r.json())
            )

        return [Project(**project) for project in r.json()]
コード例 #11
0
    def detail(self, suuid: str = None) -> RunInfo:
        """
        Retrieve details on a Run
        The suuid is optional and can be retrieved from `self.run_suuid`
        if the gateway was instantiated with it.

        returns RunInfo
        """
        suuid = suuid or self.run_suuid
        url = f"{self.client.base_url}runinfo/{suuid}/"

        r = self.client.get(url)
        if r.status_code != 200:
            raise exceptions.GetError(
                "{} - Something went wrong while retrieving the status "
                "of the run: {}".format(r.status_code, r.reason))

        return RunInfo(**r.json())
コード例 #12
0
    def get(
        self,
        project: str = None,
        job: str = None,
        job_name: str = None,
        runs: list = None,
        limit: int = 100,
        offset: int = 0,
        ordering: str = "-created",
        include_metrics: bool = False,
        include_variables: bool = False,
    ) -> List[RunInfo]:
        if job and job_name:
            raise exceptions.GetError(
                "Parameters 'job' and 'job_name' are both set. Please use 'job' or 'job_name'."
            )
        if job_name:
            project_suuid = project or self.gateway.client.config.project.project_suuid
            job = self.gateway.job.get_job_by_name(
                job_name=job_name, project_suuid=project_suuid).short_uuid

        query = self.get_query(project, job, runs)
        query.update({
            "limit": limit,
            "offset": offset,
            "ordering": ordering,
        })
        rgw = RunGateway()
        runs = rgw.list(query_params=query)
        if include_metrics:
            # also fetch the metrics for the runs
            for run in runs:
                metrics = self.gateway.metrics.get(run=run.short_uuid)
                # run.metrics
                run.metrics = metrics

        if include_variables:
            # also fetch the variables for the runs
            for run in runs:
                variables = self.gateway.variables.get(run=run.short_uuid)
                # run.metrics
                run.variables = variables

        return runs