utils

Utilities for builders and environments

disseminate.builders.utils.generate_mock_parameters(env, parameters, project_root=None, subpath=None, ext=None, context=None, gen_hash=True)

Generate a mock set of parameters.

This function is used by builders, like JinjaRender and SaveTempFile, that do not use an input file but need to save to an output file. It includes an option to rename the filename with a hash.

Parameters
envbuilders.Environment

The build environment.

parametersTuple[paths.SourcePath, str, tuple, list]

The parameters for the builder.

project_rootOptional[Union[paths.SourcePath, str]]

If given, use the specified project root for the mock infilepath.

subpathOptional[Union[paths.SourcePath, str]]

If given, use the specified subpath for the mock infilepath.

extOptional[str]

If given, use the specified extension for the mock infilepath.

gen_hashOptional[bool]

If True, append the hash from the given parameters to append to the infilepath filename.

disseminate.builders.utils.generate_outfilepath(env, parameters, target=None, append=None, ext=None, use_cache=False, use_media=False)

Given a set of parameters, generate an outfilepath.

Parameters
envbuilders.Environment

The build environment.

parametersTuple[pathlib.Path]

The parameters for the builder. The first pathlib.Path will be used.

targetOptional[str]

If specified, use the given target as a subdirectory in the target_root.

appendOptional[str]

If specified, append the given string to the returned filename

extOptional[str]

If specified, return a cache_filepath with the given target format.

use_cachebool

If True, return a path in the cache directory.

use_mediabool

If True, return a path with a subpath prepended with the media_path. ex: ‘media/’

Returns
outfilepathUnion[paths.TargetPath, None]

The outfilepath based on the parameters given, or None if no outfilepath could be generated

Note

When dealing with absolute paths, only the filename is kept in formulating the subpath. So for

target_root = ‘.’ target = ‘html’ use_media = True parameters = [‘/usr/local/bin/2to3’]

The generated outfilepath will be:

TargetPath(‘html/media/2to3’)

disseminate.builders.utils.sort_key(parameter)

Sort key function for a series of parameters to give a consisting ordering.