Download
source module isofit.data.download
Utility functions for the downloader modules
Functions
-
release_metadata — Fetch GitHub metadata for the latest tagged release.
-
download_file — Stream downloads a file
-
unzip — Unzips a zipfile
-
untar — Untars a .tar file. Removes the tar file after extracting
-
prepare_output — 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
isofitcommand. See more viaisofit --help -
isUpToDateGithub — Checks the installed version against the latest release on Github
-
pullFromRepo — Pulls a release zipfile from a Github repository
source release_metadata(org, repo, tag='latest')
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
-
dict — Metadata returned by the retrieved release
Raises
-
e
source download_file(url, dstname=None, overwrite=True)
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 : str — Output downloaded filepath
Raises
-
FileExistsError
-
e
source unzip(file, path=None, rename=None, overwrite=False, cleanup=True)
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 : str — The extracted output path
Raises
-
FileExistsError
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 : str — The extracted output path
source prepare_output(output, default, isdir=False, overwrite=False)
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
Download extra ISOFIT files that do not come with the default installation
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
source isUpToDateGithub(owner, repo, name, path=None, debug=print, error=print, **_)
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
-
bool — True if the path is up to date, False otherwise
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.
source pullFromRepo(owner, repo, tag, output, version=True, overwrite=False)
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 : pathlib.Path — Available path