示例#1
0
def init(project):
    """
    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)
    if not project_obj:
        create_project_base_url = "{}/projects/create".format(
            floyd.floyd_web_host)
        create_project_url = "{}?name={}".format(create_project_base_url,
                                                 project)
        floyd_logger.error(
            ("Project name does not match your list of projects. "
             "Create your new project in the web dashboard:\n\t%s"),
            create_project_base_url)
        webbrowser.open(create_project_url)
        return

    experiment_config = ExperimentConfig(name=project,
                                         family_id=project_obj.id)
    ExperimentConfigManager.set_config(experiment_config)
    FloydIgnoreManager.init()
    floyd_logger.info(
        "Project \"{}\" initialized in current directory".format(project))
示例#2
0
    def get_config(cls):
        if not os.path.isfile(cls.CONFIG_FILE_PATH):
            raise FloydException(
                "Missing .floydexpt file, run floyd init first")

        with open(cls.CONFIG_FILE_PATH, "r") as config_file:
            experiment_config_str = config_file.read()
        return ExperimentConfig.from_dict(json.loads(experiment_config_str))
示例#3
0
def init(project):
    """
    Initialize new project at the current dir.
    After init run your command. Example:

        floyd run python tensorflow.py > /output/model.1
    """
    experiment_config = ExperimentConfig(name=project,
                                         family_id=generate_uuid())
    ExperimentConfigManager.set_config(experiment_config)
    FloydIgnoreManager.init()
    floyd_logger.info(
        "Project \"{}\" initialized in current directory".format(project))
示例#4
0
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)
示例#5
0
class TestDataDelete(unittest.TestCase):
    """
    Tests CLI's data delete functionality `floyd data delete`
    """
    def setUp(self):
        self.runner = CliRunner()

    @patch('floyd.cli.data.DataClient')
    def test_with_no_arguments(self, data_client):
        result = self.runner.invoke(delete)

        # No calls to api, exit 0
        data_client.assert_not_called()

        assert_exit_code(result, 0)

    @patch('floyd.manager.data_config.DataConfigManager.get_config',
           side_effect=mock_data_config)
    @patch(
        'floyd.manager.experiment_config.ExperimentConfigManager.get_config',
        return_value=ExperimentConfig('foo', '12345'))
    @patch('floyd.client.project.ProjectClient',
           side_effect=mock_project_client)
    @patch('floyd.manager.auth_config.AuthConfigManager.get_access_token',
           side_effect=mock_access_token)
    @patch('floyd.manager.auth_config.AuthConfigManager.get_auth_header',
           return_value="Bearer " + mock_access_token().token)
    @patch('floyd.model.access_token.assert_token_not_expired')
    @patch('floyd.cli.data.DataClient.get', side_effect=mock_data)
    @patch('floyd.cli.data.DataClient.delete', return_value=True)
    def test_with_multiple_ids_and_yes_option(self, delete_data, get_data,
                                              assert_token_not_expired,
                                              get_auth_header,
                                              get_access_token, get_project,
                                              get_expt_config,
                                              get_data_config):
        id_1 = 'mckay/datasets/foo/1'
        id_2 = 'mckay/datasets/bar/1'
        id_3 = 'mckay/datasets/foo/1'

        result = self.runner.invoke(delete, ['-y', id_1, id_2, id_3])

        assert_exit_code(result, 0)
        # Trigger a get and a delete for each id
        calls = [call(id_1), call(id_2), call(id_3)]
        get_data.assert_has_calls(calls, any_order=True)
        delete_data.assert_has_calls(calls, any_order=True)

    @patch('floyd.manager.data_config.DataConfigManager.get_config',
           side_effect=mock_data_config)
    @patch(
        'floyd.manager.experiment_config.ExperimentConfigManager.get_config',
        return_value=ExperimentConfig('foo', '12345'))
    @patch('floyd.client.project.ProjectClient',
           side_effect=mock_project_client)
    @patch('floyd.manager.auth_config.AuthConfigManager.get_access_token')
    @patch('floyd.manager.auth_config.AuthConfigManager.get_auth_header')
    @patch('floyd.model.access_token.assert_token_not_expired')
    @patch('floyd.cli.data.DataClient.get', side_effect=mock_data)
    @patch('floyd.cli.data.DataClient.delete', return_value=True)
    def test_delete_without_yes_option(self, delete_data, get_data,
                                       assert_token_not_expired,
                                       get_auth_header, get_access_token,
                                       project_client, get_expt_config,
                                       get_data_config):
        id_1 = 'mckay/datasets/foo/1'
        id_2 = 'mckay/datasets/bar/1'
        id_3 = 'mckay/datasets/foo/1'

        # Tell prompt to skip id_1 and id_3
        result = self.runner.invoke(delete, [id_1, id_2, id_3],
                                    input='n\nY\nn\n')

        # Triggers a get for all ids
        calls = [call(id_1), call(id_2), call(id_3)]
        get_data.assert_has_calls(calls, any_order=True)

        # Calls delete for only id_2
        delete_data.assert_called_once_with(id_2)

        assert_exit_code(result, 0)

    @patch('floyd.manager.data_config.DataConfigManager.get_config',
           side_effect=mock_data_config)
    @patch(
        'floyd.manager.experiment_config.ExperimentConfigManager.get_config',
        return_value=ExperimentConfig('foo', '12345'))
    @patch('floyd.client.project.ProjectClient',
           side_effect=mock_project_client)
    @patch('floyd.manager.auth_config.AuthConfigManager.get_access_token')
    @patch('floyd.manager.auth_config.AuthConfigManager.get_auth_header')
    @patch('floyd.model.access_token.assert_token_not_expired')
    @patch('floyd.cli.data.DataClient.get', side_effect=mock_data)
    @patch('floyd.cli.data.DataClient.delete', return_value=False)
    def test_failed_delete(self, delete_data, get_data,
                           assert_token_not_expired, get_auth_header,
                           get_access_token, project_client, get_expt_config,
                           get_data_config):
        id_1 = 'mckay/datasets/foo/1'
        id_2 = 'mckay/datasets/bar/1'
        id_3 = 'mckay/datasets/foo/1'

        result = self.runner.invoke(delete, ['-y', id_1, id_2, id_3])

        # Trigger a get and a delete for each id, even though each delete
        # fails. All deletes are attempted regardless of previous failures.
        calls = [call(id_1), call(id_2), call(id_3)]
        get_data.assert_has_calls(calls, any_order=True)
        delete_data.assert_has_calls(calls, any_order=True)

        # Exit 1 for failed deletes
        assert_exit_code(result, 1)

    @patch('floyd.manager.data_config.DataConfigManager.get_config',
           side_effect=mock_data_config)
    @patch(
        'floyd.manager.experiment_config.ExperimentConfigManager.get_config',
        return_value=ExperimentConfig('foo', '12345'))
    @patch('floyd.manager.auth_config.AuthConfigManager.get_access_token')
    @patch('floyd.manager.auth_config.AuthConfigManager.get_auth_header')
    @patch('floyd.model.access_token.assert_token_not_expired')
    @patch('floyd.cli.data.DataClient.get', return_value=None)
    @patch('floyd.cli.data.DataClient.delete')
    def test_failed_get(self, delete_data, get_data, assert_token_not_expired,
                        get_auth_header, get_access_token, get_expt_config,
                        get_data_config):
        id_1 = 'mckay/datasets/foo/1'
        id_2 = 'mckay/datasets/bar/1'
        id_3 = 'mckay/datasets/foo/1'

        result = self.runner.invoke(delete, ['-y', id_1, id_2, id_3])

        # Trigger a get for each id, even though each fails. (No early exit)
        calls = [call(id_1), call(id_2), call(id_3)]
        get_data.assert_has_calls(calls, any_order=True)

        # Deletes are not triggered for ids that are not found
        delete_data.assert_not_called()

        # Exit 1 for failed get requests
        assert_exit_code(result, 1)
示例#6
0
def mock_experiment_config():
    return ExperimentConfig(name="name", family_id="family_id")