class Scaffold(object): """This class scaffolds a new machine learning project for the user. It takes a project name given by the user and make a copy of the /template directory to a new directory with the given project name. It works alongside a CLI which takes arguments to determine what actions the user wants to take. Arguments: project_name {str} -- Name of the project to scaffold """ def __init__(self, project_name): from foundations_core_cli.project import Project self._project = Project(project_name) def scaffold_project(self): """ Wrapping logic to check that user gave command and to start scaffolding if directory is unique and does not exist. """ if self._project.exists(): return False else: self._perform_scaffolding() return True def _perform_scaffolding(self): from distutils.dir_util import copy_tree copy_from = self._string_source_template_path() copy_to = self._project.string_path() copy_tree(copy_from, copy_to) def _string_source_template_path(self): return str(self._source_template_path()) def _source_template_path(self): import foundations_contrib return foundations_contrib.root().joinpath('resources/template')
def test_exists_returns_true_on_existing_project_different_project(self): with self._patch_path_exists('/path/to/cwd/subproj'): self.assertTrue(Project('subproj').exists())
def __init__(self, project_name): from foundations_core_cli.project import Project self._project = Project(project_name)
def test_string_path_returns_relative_path_different_working_directory( self): self.assertEqual('/path/to/different/cwd/superproj', Project('superproj').string_path())
def test_exists_returns_false_on_missing_project(self): with self._patch_path_exists('/path/to/cwd/superproj'): self.assertFalse(Project('superproj').exists())
def test_string_path_returns_relative_path_different_project(self): self.assertEqual('/path/to/cwd/apples_vs_oranges', Project('apples_vs_oranges').string_path())
def test_string_path_returns_relative_path(self): self.assertEqual('/path/to/cwd/superproj', Project('superproj').string_path())
def test_path_returns_relative_path(self): self.assertEqual(Path('/path/to/cwd/superproj'), Project('superproj').path())
def test_name_returns_project_name_different_name(self): self.assertEqual('rubber ducky', Project('rubber ducky').name())
def test_name_returns_project_name(self): self.assertEqual('superproj', Project('superproj').name())