isofit.data.download

Utility functions for the downloader modules

Functions

release_metadata(org, repo[, tag])

Fetch GitHub metadata for the latest tagged release.

download_file(url[, dstname, overwrite])

Stream downloads a file

unzip(file[, path, rename, overwrite, cleanup])

Unzips a zipfile

untar(file, output)

Untars a .tar file. Removes the tar file after extracting

prepare_output(output, default[, isdir, overwrite])

Prepares the output path by ensuring the parents exist and itself doesn't presently exist.

cli()

Download extra ISOFIT files that do not come with the default installation

preview_paths()

Preview download path locations. Paths can be changed from the default by using the overrides on the isofit command. See more via isofit --help

isUpToDateGithub(owner, repo, name[, path, debug, error])

Checks the installed version against the latest release on Github

pullFromRepo(owner, repo, tag, output[, version, ...])

Pulls a release zipfile from a Github repository

Module Contents

release_metadata(org, repo, tag='latest')[source]

Fetch GitHub metadata for the latest tagged release.

Credit to Kevin Wurster https://github.com/isofit/isofit/pull/448#issuecomment-1966747551

Parameters:
  • org (str) – GitHub organization name

  • repo (str) – GitHub repository name

  • tag (str) – Release tag to pull

Returns:

Metadata returned by the retrieved release

Return type:

dict

download_file(url, dstname=None, overwrite=True)[source]

Stream downloads a file

Parameters:
  • url (str) – URL to download

  • dstname (str) – Destination file name

  • overwrite (bool, default=True) – Overwrite the destination file if it already exists

Returns:

outfile – Output downloaded filepath

Return type:

str

unzip(file, path=None, rename=None, overwrite=False, cleanup=True)[source]

Unzips a zipfile

Parameters:
  • path (str, default=None) – Path to extract the zipfile to. Defaults to the directory the zip is found in

  • rename (str, default=None) – Renames the extracted data to this

  • overwrite (bool, default=False) – Overwrites the path destination with the zip contents if enabled

  • cleanup (bool, default=True) – Removes the zip file after completion

Returns:

dst – The extracted output path

Return type:

str

untar(file, output)[source]

Untars a .tar file. Removes the tar file after extracting

Parameters:
  • file (str) – .tar file to extract

  • output (str) – Path to output to

Returns:

output – The extracted output path

Return type:

str

prepare_output(output, default, isdir=False, overwrite=False)[source]

Prepares the output path by ensuring the parents exist and itself doesn’t presently exist.

Parameters:
  • output (str | None) – Path to download to

  • default (str) – Default path defined by the ini file

  • isdir (bool, default=False) – This is supposed to be a directory

  • overwrite (bool, default=False) – Ignore if the output already exists

cli()[source]

Download extra ISOFIT files that do not come with the default installation

preview_paths()[source]

Preview download path locations. Paths can be changed from the default by using the overrides on the isofit command. See more via isofit –help

 Example: Change the default data and examples paths $ isofit –data /path/to/data –examples /different/path/examples download paths

Download paths will default to: - data = /path/to/data - examples = /different/path/examples

 These will be saved and may be reviewed: $ isofit download paths

Download paths will default to: - data = /path/to/data - examples = /different/path/examples

isUpToDateGithub(owner, repo, name, path=None, debug=print, error=print, **_)[source]

Checks the installed version against the latest release on Github

Parameters:
  • owner (str) – Github repository owner

  • repo (str) – Repository name

  • name (str) – Name of the downloader module to retrieve the path from the env ini if path is not provided

  • path (str, default=None) – Path to update. If None, defaults to the ini path

  • debug (function, default=print) – Print function to use for debug messages, eg. logging.debug

  • error (function, default=print) – Print function to use for error messages, eg. logging.error

  • **_ (dict) – Ignores unused params that may be used by other validate functions. This is to maintain compatibility with other functions

Returns:

True if the path is up to date, False otherwise

Return type:

bool

Notes

The Github workflows watch for the string “[x]” to determine if the cache needs to update the data of this module. If your module does not include this string, the workflows will never detect updates.

pullFromRepo(owner, repo, tag, output, version=True, overwrite=False)[source]

Pulls a release zipfile from a Github repository

Parameters:
  • owner (str) – Github repository owner

  • repo (str) – Repository name

  • tag (str) – Tag of the release to pull

  • output (pathlib.Path) – Output path to write to

  • version (bool, default=True) – Write the tag’s name in a version.txt file

  • overwrite (bool, default=False) – Ignore if the output already exists

Returns:

avail – Available path

Return type:

pathlib.Path