How to use the jovian.utils.misc.get_file_extension function in jovian

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
config = read_creds().get("DEFAULT_CONFIG", {})

    whitelist = config.get("EXTENSION_WHITELIST")
    upload_wd = config.get("UPLOAD_WORKING_DIRECTORY", False)

    if not isinstance(whitelist, list):
        whitelist = DEFAULT_EXTENSION_WHITELIST

    if not paths:
        if output or not upload_wd:
            return

        paths = [
            f
            for f in glob.glob('**/*', recursive=True)
            if get_file_extension(f) in whitelist
        ]

    if exclude_files:
        if not isinstance(exclude_files, list):
            exclude_files = [exclude_files]

        for filename in exclude_files:
            try:
                paths.remove(filename)
            except ValueError:
                pass

    log('Uploading additional ' + ('outputs' if output else 'files') + '...')

    # Convert single path to list
    if type(paths) == str:
github JovianML / jovian-py / jovian / utils / commit.py View on Github external
def _parse_filename(filename):
    """Perform the required checks and get the final filename"""
    # Get the filename of the notebook (if not provided)
    if filename is None:
        if in_script():
            filename = get_script_filename()
        elif in_notebook():
            filename = get_notebook_name()

    # Add the right extension to the filename
    elif get_file_extension(filename) not in ['.py', '.ipynb']:
        filename += '.py' if in_script() else '.ipynb'
    return filename
github JovianML / jovian-py / jovian / utils / commit.py View on Github external
def _list_ipynb_files(path):
    """Return list of ipynb files in a path"""
    if os.path.isfile(path) and get_file_extension(path) == ".ipynb":
        files = [os.path.normpath(path)]
    elif os.path.isdir(path):
        files = [os.path.normpath(f) for f in sorted(glob.glob(os.path.join(path, '*.ipynb')))]
    else:
        files = []
    return files
github JovianML / jovian-py / jovian / utils / commit.py View on Github external
paths.remove(filename)
            except ValueError:
                pass

    log('Uploading additional ' + ('outputs' if output else 'files') + '...')

    # Convert single path to list
    if type(paths) == str:
        paths = [paths]

    for path in paths:
        if os.path.isdir(path):
            files = [
                f
                for f in glob.glob(os.path.join(path, '**/*'), recursive=True)
                if get_file_extension(f) in whitelist
            ]
            for file in files:
                _attach_file(file, gist_slug, version, output)
        elif os.path.exists(path):
            _attach_file(path, gist_slug, version, output)
        else:
            log('Ignoring "' + path + '" (not found)', error=True)