def test_name_check(): invalid_names = ['test-name,', 'test,name', 'test.name'] valid_names = ['test-name', 'testname'] for name in invalid_names: result = valid_name_check(name) assert result == False for name in valid_names: result = valid_name_check(name) assert result == True
def get_project(self, project_name: str) -> Project: """ Get a project in Merlin and optionally assign list of readers and administrators. The identity used for creating the project will be automatically included as project's administrators. :param project_name: project name :return: project """ if not valid_name_check(project_name): raise ValueError( '''Your project/model name contains invalid characters.\ \nUse only the following characters\ \n- Characters: a-z (Lowercase ONLY)\ \n- Numbers: 0-9\ \n- Symbols: - ''') p_list = self._project_api.projects_get(name=project_name) p = None for prj in p_list: if prj.name == project_name: p = prj if p is None: raise Exception( f"{project_name} does not exist or you don't have access to the project. Please create new " f"project using MLP console or ask the project's administrator to be able to access " f"existing project.") return Project(p, self.url, self._api_client)
def scaffold(project, model_name, env): if not valid_name_check(project) or not valid_name_check(model_name): print('''Your project/model name contains invalid characters.\ \nUse only the following characters\ \n- Characters: a-z (Lowercase ONLY)\ \n- Numbers: 0-9\ \n- Symbols: - ''') else: try: cookiecutter( "[email protected]:gojek/merlin/python/pyfunc-scaffolding", checkout="tags/v0.1", no_input=True, directory="python/pyfunc-scaffolding", extra_context={ 'project_name': project, 'model_name': model_name, 'environment_name': env }) except Exception as e: print(e)
def get_or_create_model(self, model_name: str, project_name: str, model_type: ModelType = None) -> Model: """ Get or create a model under a project If project_name is not given it will use currently active project otherwise will raise Exception :param model_type: :param model_name: model name :param project_name: project name (optional) :param model_type: model type :return: Model """ if not valid_name_check(project_name): raise ValueError( '''Your project/model name contains invalid characters.\ \nUse only the following characters\ \n- Characters: a-z (Lowercase ONLY)\ \n- Numbers: 0-9\ \n- Symbols: - ''') prj = self.get_project(project_name) m_list = self._model_api.projects_project_id_models_get( project_id=int(prj.id), name=model_name) model = None for mdl in m_list: if mdl.name == model_name: model = mdl if model is None: if model_type is None: raise ValueError(f"model {model_name} is not found, specify " f"{model_type} to create it") model = self._model_api.projects_project_id_models_post( project_id=int(prj.id), body={ "name": model_name, "type": model_type.value }) return Model(model, prj, self._api_client)