def init(dataset_name): """ Initialize a new dataset at the current dir. Then run the upload command to copy all the files in this directory to FloydHub. floyd data upload """ dataset_obj = DatasetClient().get_by_name(dataset_name) if not dataset_obj: namespace, name = get_namespace_from_name(dataset_name) create_dataset_base_url = "{}/datasets/create".format( floyd.floyd_web_host) create_dataset_url = "{}?name={}&namespace={}".format( create_dataset_base_url, name, namespace) floyd_logger.info( ("Dataset name does not match your list of datasets. " "Create your new dataset in the web dashboard:\n\t%s"), create_dataset_base_url) webbrowser.open(create_dataset_url) name = click.prompt( 'Press ENTER to use dataset name "%s" or enter a different name' % dataset_name, default=dataset_name, show_default=False) dataset_name = name.strip() or dataset_name dataset_obj = DatasetClient().get_by_name(dataset_name) if not dataset_obj: raise FloydException( 'Dataset "%s" does not exist on floydhub.com. Ensure it exists before continuing.' % dataset_name) namespace, name = get_namespace_from_name(dataset_name) data_config = DataConfig(name=name, namespace=namespace, family_id=dataset_obj.id) DataConfigManager.set_config(data_config) floyd_logger.info( "Data source \"{}\" initialized in current directory".format( dataset_name)) floyd_logger.info(""" You can now upload your data to Floyd by: floyd data upload """)
def init(project_name): """ Initialize new project at the current dir. After init run your command. Example: floyd run 'python tensorflow.py > /output/model.1' """ project_obj = ProjectClient().get_by_name(project_name) if not project_obj: namespace, name = get_namespace_from_name(project_name) create_project_base_url = "{}/projects/create".format( floyd.floyd_web_host) create_project_url = "{}?name={}&namespace={}".format( create_project_base_url, name, namespace) floyd_logger.info(('Project name does not yet exist on floydhub.com. ' 'Create your new project on floydhub.com:\n\t%s'), create_project_base_url) webbrowser.open(create_project_url) name = click.prompt( 'Press ENTER to use project name "%s" or enter a different name' % project_name, default=project_name, show_default=False) project_name = name.strip() or project_name project_obj = ProjectClient().get_by_name(project_name) if not project_obj: raise FloydException( 'Project "%s" does not exist on floydhub.com. Ensure it exists before continuing.' % project_name) namespace, name = get_namespace_from_name(project_name) experiment_config = ExperimentConfig(name=name, namespace=namespace, family_id=project_obj.id) ExperimentConfigManager.set_config(experiment_config) FloydIgnoreManager.init() yaml_config = read_yaml_config() if not yaml_config: copyfile(os.path.join(os.path.dirname(__file__), 'default_floyd.yml'), 'floyd.yml') floyd_logger.info("Project \"%s\" initialized in current directory", project_name)
def get_by_name(self, name, namespace=None): """ name: can be either <namespace>/<project_name> or just <project_name> namespace: if specified, will skip name parsing, defaults to current user's username """ if not namespace: namespace, name = get_namespace_from_name(name) if not namespace: namespace = AuthConfigManager.get_access_token().username try: response = self.request('GET', '%s/%s/%s' % (self.url, namespace, name)) return Project.from_dict(response.json()) except NotFoundException: return None
def test_get_namespace_from_name(self, _0): """ Test Regex for args of dataset and project initialization """ from floyd.cli.utils import get_namespace_from_name # PATTERN: <dataset_or_project_name> assert get_namespace_from_name('test') == ('pete', 'test') # PATTERN: <namespace>/[dataset|project]/<dataset_or_project_name> assert get_namespace_from_name('fo.o_user/datasets/test_1') == ( 'fo.o_user', 'test_1') assert get_namespace_from_name('fo.o_user/projects/test_1') == ( 'fo.o_user', 'test_1') # PATTERN: <namespace>/<dataset_or_project_name> assert get_namespace_from_name('fo.o_user/test_1-1') == ('fo.o_user', 'test_1-1') # BAD PATTERN: Bad argument (/) with self.assertRaises(SystemExit) as cm: get_namespace_from_name('/') error = ( "Argument '/' doesn't match any recognized pattern:\n" "\tfloyd [data] init <project_or_dataset_name>\n" "\tfloyd [data] init <namespace>/<project_or_dataset_name>\n" "\tfloyd [data] init <namespace>/[projects|dataset]/<project_or_dataset_name>\n" "\n Note: Argument can only contain alphanumeric, hyphen-minus '-' , underscore '_' and dot '.' characters." ) self.assertEqual(cm.exception.code, error) # BAD PATTERN: Characters not allowed (:?) with self.assertRaises(SystemExit) as cm: get_namespace_from_name('test_:?1-1') error = ( "Argument 'test_:?1-1' doesn't match any recognized pattern:\n" "\tfloyd [data] init <project_or_dataset_name>\n" "\tfloyd [data] init <namespace>/<project_or_dataset_name>\n" "\tfloyd [data] init <namespace>/[projects|dataset]/<project_or_dataset_name>\n" "\n Note: Argument can only contain alphanumeric, hyphen-minus '-' , underscore '_' and dot '.' characters." ) self.assertEqual(cm.exception.code, error)