From 839b024edd25d7fdfb21753d2393dcacf73813b5 Mon Sep 17 00:00:00 2001 From: Travis McKee Date: Fri, 1 Nov 2024 15:31:08 -0400 Subject: [PATCH] Change get_project to raise error if no project is set --- src/gretel_client/gretel/interface.py | 17 ++++++++--------- src/gretel_client/projects/projects.py | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/gretel_client/gretel/interface.py b/src/gretel_client/gretel/interface.py index ee9f77f..954c5dd 100644 --- a/src/gretel_client/gretel/interface.py +++ b/src/gretel_client/gretel/interface.py @@ -29,7 +29,7 @@ ) from gretel_client.gretel.exceptions import ( GretelJobSubmissionError, - GretelProjectNotSetError + GretelProjectNotSetError, ) from gretel_client.gretel.job_results import ( GenerateJobResults, @@ -149,16 +149,16 @@ def _assert_project_is_set(self): def _generate_random_label(self) -> str: return f"{uuid.uuid4().hex[:5]}-{self._user_id}" - def get_project(self, **kwargs) -> Project: + def get_project(self) -> Project: """Returns the current Gretel project. If a project has not been set, a new one will be created. The optional kwargs are the same as those available for the `set_project` method. """ - if self._project is None: - logger.info("No project set -> creating a new one...") - self.set_project(**kwargs) - return self._project # type: ignore + if self._project: + return self._project # type: ignore + + raise GretelProjectNotSetError("No Gretel Project Set") def set_project( self, @@ -171,7 +171,7 @@ def set_project( """Set the current Gretel project. If a project with the given name does not exist, and create_if_missing is set to true, - then it will be created. + then it will be created. If the name is not unique, the user id will be appended to the name. @@ -179,7 +179,7 @@ def set_project( name: Name of new or existing project. If None, will create one. desc: Project description. display_name: Project display name. If None, will use project name. - create_if_missing: Whether to create a new project if one is missing + create_if_missing: Project display name. If None, will use project name. Raises: ApiException: If an error occurs while creating the project. @@ -200,7 +200,6 @@ def set_project( and "not found" not in exception.body # type: ignore ): raise exception - logger.warning( f"Project name `{name}` is not unique -> " "appending your user id to the name." diff --git a/src/gretel_client/projects/projects.py b/src/gretel_client/projects/projects.py index 54c94ae..9f379d3 100644 --- a/src/gretel_client/projects/projects.py +++ b/src/gretel_client/projects/projects.py @@ -475,7 +475,7 @@ def get_project( resp = api.create_project(project=models.Project(**project_args)) project = api.get_project(project_id=resp.get(DATA).get("id")) - print(f'No project found with that name. Creating new project {name}') + logger.info(f'No project found. Creating new project {name}') if name: try: @@ -486,7 +486,7 @@ def get_project( resp = api.create_project(project=models.Project(**project_args)) project = api.get_project(project_id=resp.get(DATA).get("id")) - print(f'No project found with that name. Creating new project {name}') + logger.info(f'No project found. Creating new project {name}') else: raise GretelProjectError(f"Could not get project using '{name}'.")