How to use jovian - 10 common examples

To help you get started, we’ve selected a few jovian examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JovianML / jovian-py / jovian / utils / commit.py View on Github external
# Skip if unsupported environment
    if not in_script() and not in_notebook() and not is_cli:
        log('Failed to detect Jupyter notebook or Python script. Skipping..', error=True)
        return

    # Attempt to save Jupyter notebook
    if in_notebook():
        save_notebook()
        log('Attempting to save notebook..')
        sleep(1)

    # Extract notebook/script filename
    filename = _parse_filename(filename)
    if filename is None:
        log(FILENAME_MSG, error=True)
        return

    # Commit from Kaggle (After many bug reports of empty notebook)
    if filename == '__notebook_source__.ipynb':
        log("Detected Kaggle notebook...")
        if not project:
            log("Please provide the project argument e.g. jovian.commit(project='my-project')", error=True)
            return

        perform_kaggle_commit(message,
                              files,
                              outputs,
                              environment,
                              privacy,
                              project,
                              new_project)
github JovianML / jovian-py / jovian / utils / commit.py View on Github external
# Deprecated argument (artifacts)
    if 'artifacts' in kwargs:
        outputs = kwargs['artifacts']
        log('"artifacts" is deprecated. Use "outputs" instead', error=True)

    is_cli = kwargs.get('is_cli', False)

    # Skip if unsupported environment
    if not in_script() and not in_notebook() and not is_cli:
        log('Failed to detect Jupyter notebook or Python script. Skipping..', error=True)
        return

    # Attempt to save Jupyter notebook
    if in_notebook():
        save_notebook()
        log('Attempting to save notebook..')
        sleep(1)

    # Extract notebook/script filename
    filename = _parse_filename(filename)
    if filename is None:
        log(FILENAME_MSG, error=True)
        return

    # Commit from Kaggle (After many bug reports of empty notebook)
    if filename == '__notebook_source__.ipynb':
        log("Detected Kaggle notebook...")
        if not project:
            log("Please provide the project argument e.g. jovian.commit(project='my-project')", error=True)
            return

        perform_kaggle_commit(message,
github JovianML / jovian-py / jovian / utils / commit.py View on Github external
if num_files >= 50:
        log("Can't upload more than 50 files at once")
        return

    if num_files == 1:
        log('Uploading 1 notebook: {}'.format(files[0]))
    else:
        log('Uploading {} notebooks:'.format(num_files))
        log('\n'.join(files), pre=False)

    if click.confirm('\n[jovian] Do you want to continue?', default=True):
        for filename in files:
            reset_notebook_slug()
            commit(filename=filename, **kwargs)
            log("", pre=False)
            sleep(1)
github JovianML / jovian-py / jovian / utils / clone.py View on Github external
def get_gist(slug, version, fresh):
    """Download a gist"""
    if '/' in slug:
        parts = slug.split('/')
        username, title = parts[0], parts[1]
        url = _u('user/' + username + '/gist/' + title + _v(version))
    else:
        url = _u('gist/' + slug + _v(version))
    res = get(url, headers=_h(fresh))
    if res.status_code == 200:
        return res.json()['data']
    raise Exception('Failed to retrieve Gist: ' + pretty(res))
github JovianML / jovian-py / jovian / utils / clone.py View on Github external
def get_gist(slug, version, fresh):
    """Download a gist"""
    if '/' in slug:
        parts = slug.split('/')
        username, title = parts[0], parts[1]
        url = _u('user/' + username + '/gist/' + title + _v(version))
    else:
        url = _u('gist/' + slug + _v(version))
    res = get(url, headers=_h(fresh))
    if res.status_code == 200:
        return res.json()['data']
    raise Exception('Failed to retrieve Gist: ' + pretty(res))
github JovianML / jovian-py / jovian / utils / api.py View on Github external
def get_gist(slug, version=None, check_exists=True):
    """Get the metadata for a gist"""
    if '/' in slug:
        parts = slug.split('/')
        username, title = parts[0], parts[1]
        url = _u('user/' + username + '/gist/' + title + _v(version))
    else:
        url = _u('gist/' + slug + _v(version))
    res = get(url=url, headers=_h())
    if res.status_code == 200:
        return res.json()['data']
    elif check_exists and res.status_code == 404:
        return False
    raise Exception('Failed to retrieve metadata for notebook "' +
                    slug + '": ' + pretty(res))
github JovianML / jovian-py / jovian / utils / clone.py View on Github external
def get_gist(slug, version, fresh):
    """Download a gist"""
    if '/' in slug:
        parts = slug.split('/')
        username, title = parts[0], parts[1]
        url = _u('user/' + username + '/gist/' + title + _v(version))
    else:
        url = _u('gist/' + slug + _v(version))
    res = get(url, headers=_h(fresh))
    if res.status_code == 200:
        return res.json()['data']
    raise Exception('Failed to retrieve Gist: ' + pretty(res))
github JovianML / jovian-py / jovian / utils / commit.py View on Github external
if project is None:
        return None, None

    # Get project metadata for UUID & username/title
    if is_uuid(project):
        project_title = None
        metadata = api.get_gist(project)
    elif '/' in project:
        project_title = project.split('/')[1]
        username = api.get_current_user()['username']
        metadata = api.get_gist(project)
    # Attach username to the title
    else:
        project_title = project
        username = api.get_current_user()['username']
        metadata = api.get_gist(username + '/' + project)

    # Skip if metadata could not be found
    if not metadata:
        log('Creating a new project "' + username + '/' + project_title + '"')
        return project_title, None

    # Extract information from metadata
    username = metadata['owner']['username']
    project_title = metadata['title']
    project_id = metadata['slug']

    # Check if the current user can commit to this project
    permissions = api.get_gist_access(project_id)
    if not permissions['write']:
        return project_title, None
github JovianML / jovian-py / jovian / utils / commit.py View on Github external
project,
                              new_project)
        return

    # Ensure that the file exists
    if not os.path.exists(filename):
        log('The detected/provided file "' + filename +
            '" does not exist. Please provide the correct notebook filename ' +
            'as the "filename" argument to "jovian.commit".', error=True)
        return

    # Retrieve Gist ID & title
    project_title, project_id = _parse_project(project, filename, new_project)

    # Create or update gist (with title and )
    res = api.create_gist_simple(filename, project_id, privacy, project_title, message)
    slug, owner, version, title = res['slug'], res['owner'], res['version'], res['title']
    username = owner['username']

    # Cache slug for further commits
    set_notebook_slug(filename, slug)

    # Attach environment, files and outputs
    _capture_environment(environment, slug, version)
    _attach_files(files, slug, version, exclude_files=filename)
    _attach_files(outputs, slug, version, output=True)

    if not git_message or git_message == 'auto':
        git_message = message or 'jovian commit ' + username + '/' + title + ' v' + str(version)
    _perform_git_commit(filename, git_commit, git_message)
    _attach_records(slug, version)
github JovianML / jovian-py / jovian / utils / commit.py View on Github external
project = current_slug
        # From .jovianrc file
        else:
            project = get_notebook_slug(filename)

    # Skip if project is not provided & can't be read
    if project is None:
        return None, None

    # Get project metadata for UUID & username/title
    if is_uuid(project):
        project_title = None
        metadata = api.get_gist(project)
    elif '/' in project:
        project_title = project.split('/')[1]
        username = api.get_current_user()['username']
        metadata = api.get_gist(project)
    # Attach username to the title
    else:
        project_title = project
        username = api.get_current_user()['username']
        metadata = api.get_gist(username + '/' + project)

    # Skip if metadata could not be found
    if not metadata:
        log('Creating a new project "' + username + '/' + project_title + '"')
        return project_title, None

    # Extract information from metadata
    username = metadata['owner']['username']
    project_title = metadata['title']
    project_id = metadata['slug']