FastSurferCNN.version

class FastSurferCNN.version.VersionDict[source]

Dictionary with keys ‘version_line’, ‘version’, ‘git_hash’, ‘git_branch’, ‘checkpoints’, ‘git_status’, and ‘pypackages’. The last 3 are optional and may be missing depending on the content of the file.

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(key[, default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

FastSurferCNN.version.filter_git_status(git_process)[source]

Filter the output of a running git status process.

Parameters:
git_processFastSurferCNN.utils.run_tools.Popen

The Popen process object that will return the git status output.

Returns:
str

The git status string filtered to exclude lines containing “__pycache__”.

FastSurferCNN.version.get_default_version_info()[source]

Get the blank version information.

Returns:
VersionDict

A dictionary with blank version information.

FastSurferCNN.version.has_git()[source]

Determine whether FastSurfer is installed as a git directory.

Returns:
bool

Whether git commands on the FastSurfer dir likely work.

FastSurferCNN.version.main(sections='', project_file=None, build_cache=None, file=None, prefer_cache=False)[source]

Print version info to stdout or file.

Prints/writes version info of FastSurfer in the style: ` <version number>[+<git hash>][ (<git active branch>)] [========== checkpoints: ========== <md5sum> <file> ...] [========== git status: ========== <git status text>] [========== python packages: ========== Package         Version    Location   [Installer] <package name>  <version>  <path>     <pip|conda> ...] `

$PROJECT_ROOT is the root directory of the project determined as the parent to this file’s directory.

Parameters:
sectionsstr

String describing which sections the output should include. Can be ‘all’ or a concatenated list of ‘+branch’, ‘+checkpoints’, ‘+git’, and ‘+pip’, e.g. ‘+git+checkpoints’. The order does not matter, ‘+checkpoints’, ‘+git’ or ‘+pip’ also implicitly activate ‘+branch’.

project_fileTextIO, optional

A file-like object to read the projects toml file, with the ‘[project]’ section with a ‘version’ attribute. Defaults to $PROJECT_ROOT/pyproject.toml.

build_cacheFalse, TextIO, optional

A file-like object to read cached version information, the format should be formatted like the output of main. Defaults to $PROJECT_ROOT/BUILD.info. If build_cache is False, it is ignored.

fileTextIO, optional

A file-like object to write the output to, defaults to stdout if None or not passed.

prefer_cachebool, default=False

Whether to prefer information from the build_cache over online generation.

Returns:
int or str

Returns 0, if the function was successful, or an error message.

FastSurferCNN.version.make_parser()[source]

Generate the argument parser for the version script.

Returns:
argparse.ArgumentParser

The argument parser for the version script.

FastSurferCNN.version.parse_build_file(build_file)[source]

Read and parse a build file (same as output of main).

Read and parse a file with version information in the format that is also the output of the main function. The format is documented in main.

Parameters:
build_fileTextIO, optional

File-like object, will be closed.

Returns:
VersionDict

Dictionary with keys ‘version_line’, ‘version’, ‘git_hash’, ‘git_branch’, ‘checkpoints’, ‘git_status’, and ‘pypackages’. The last 3 are optional and may be missing depending on the content of the file.

Notes

See also main.

FastSurferCNN.version.print_build_file(version, git_hash='', git_branch='', git_status='', checkpoints='', pypackages='', file=None)[source]

Format and print the build file.

Parameters:
versionstr

The version number to print.

git_hashstr, optional

The git hash associated with the build, may be empty.

git_branchstr, optional

The git branch associated with the build, may be empty.

git_statusstr, optional

The md5sums of the checkpoint files, leave empty to skip.

checkpointsstr, optional

The md5sums of the checkpoint files, leave empty to skip.

pypackagesstr, optional

The md5sums of the checkpoint files, leave empty to skip.

fileTextIO, optional

A file-like object to write the build file to, default: stdout.

Notes

See also main.

FastSurferCNN.version.read_and_close_version(project_file=None)[source]

Read and close the version from the pyproject file. Also fill default.

Always closes the file pointer.

Parameters:
project_fileTextIO, optional

Project file.

Returns:
str

The version read from the pyproject file.

Notes

See also FastSurferCNN.version.read_version_from_project_file

FastSurferCNN.version.read_version_from_project_file(project_file)[source]

Read the version entry from the pyproject file.

Searches for the [project] section in project_file, therein the version attribute. Extracts the Value. The file pointer is right after the version attribute at return time.

Parameters:
project_fileTextIO

File pointer to the project file to read from.

Returns:
str

The version string.

FastSurferCNN.version.section(arg)[source]

Validate the argument is a valid sections string.

A valid sections string is either ‘all’ or a concatenated list of ‘+checkpoints’, ‘+git’, and ‘+pip’, e.g. ‘+git+checkpoints’. The order does not matter.

Parameters:
argstr

The input string to be validated.

Returns:
str

The validated sections string.