diff --git a/python/hopsworks/__init__.py b/python/hopsworks/__init__.py index ca734a427..32b130080 100644 --- a/python/hopsworks/__init__.py +++ b/python/hopsworks/__init__.py @@ -47,6 +47,7 @@ _secrets_api = None _project_api = None + def hw_formatwarning(message, category, filename, lineno, line=None): return "{}: {}\n".format(category.__name__, message) @@ -144,7 +145,7 @@ def login( elif host is None: # Always do a fallback to Serverless Hopsworks if not defined host = constants.HOSTS.APP_HOST - is_app = (host == constants.HOSTS.APP_HOST) + is_app = host == constants.HOSTS.APP_HOST # If port same as default, get HOPSWORKS_HOST environment variable if port == 443 and "HOPSWORKS_PORT" in os.environ: @@ -211,7 +212,9 @@ def login( raise e if _connected_project is None: - print("Could not find any project, use hopsworks.create_project('my_project') to create one") + print( + "Could not find any project, use hopsworks.create_project('my_project') to create one" + ) else: print("\nLogged in to project, explore it here " + _connected_project.get_url()) @@ -273,7 +276,9 @@ def _prompt_project(valid_connection, project, is_app): for index in range(len(saas_projects)): print("\t (" + str(index + 1) + ") " + saas_projects[index].name) while True: - project_index = input("\nEnter number corresponding to the project to use: ") + project_index = input( + "\nEnter number corresponding to the project to use: " + ) # Handle invalid input type try: project_index = int(project_index) @@ -300,8 +305,7 @@ def _prompt_project(valid_connection, project, is_app): def logout(): - """Cleans up and closes the connection for the hopsworks, hsfs and hsml libraries. - """ + """Cleans up and closes the connection for the hopsworks, hsfs and hsml libraries.""" global _hw_connection global _project_api global _secrets_api @@ -314,10 +318,12 @@ def logout(): _secrets_api = None _hw_connection = Connection.connection + def _is_connection_active(): global _hw_connection return isinstance(_hw_connection, Connection) + def get_current_project() -> project.Project: """Get a reference to the current logged in project. @@ -341,15 +347,15 @@ def get_current_project() -> project.Project: raise ProjectException("No project is set for this session") return _connected_project + def _initialize_module_apis(): global _project_api global _secrets_api _project_api = project_api.ProjectApi() _secrets_api = secret_api.SecretsApi() -def create_project( - name: str, description: str = None, feature_store_topic: str = None -): + +def create_project(name: str, description: str = None, feature_store_topic: str = None): """Create a new project. Example for creating a new project @@ -377,13 +383,24 @@ def create_project( if not _is_connection_active(): raise NoHopsworksConnectionError() - new_project = _hw_connection._project_api._create_project(name, description, feature_store_topic) + new_project = _hw_connection._project_api._create_project( + name, description, feature_store_topic + ) if _connected_project is None: _connected_project = new_project - print("Setting {} as the current project, a reference can be retrieved by calling hopsworks.get_current_project()".format(_connected_project.name)) + print( + "Setting {} as the current project, a reference can be retrieved by calling hopsworks.get_current_project()".format( + _connected_project.name + ) + ) return _connected_project else: - print("You are already using the project {}, to access the new project use hopsworks.login(..., project='{}')".format(_connected_project.name, new_project.name)) + print( + "You are already using the project {}, to access the new project use hopsworks.login(..., project='{}')".format( + _connected_project.name, new_project.name + ) + ) + def get_secrets_api(): """Get the secrets api. @@ -394,4 +411,4 @@ def get_secrets_api(): global _secrets_api if not _is_connection_active(): raise NoHopsworksConnectionError() - return _secrets_api \ No newline at end of file + return _secrets_api