Buck has restrictions on importing arbitrary Python modules in build file
s which make it harder to accidentally violate assumptions about determinism of build file
s and build rules. The
function may be used to create a context that lifts the restrictions on module importing.
Using this function should be avoided, and done carefully when necessary. Buck's internal caches invalidate build files based on known inputs, and using arbitrary Python code can introduce nondeterministic behavior or inputs that Buck won't know about.
Whitelist and safe versions
Some modules can be imported in a normal way (without using
) because they were whitelisted or a safe version was configured. After checking if they are safe to use in build files, more modules (e.g. local ones) can be added to the whitelist using
|Whitelist||copy, re, functools, itertools, json, hashlib, types, string, ast, __future__, collections, operator, fnmatch|
In the safe versions of modules only selected parts can be used.
|os||environ, getenv, path, sep, pathsep, linesep|
|os.path||basename, commonprefix, dirname, isabs, join, normcase, relpath, split, splitdrive, splitext, sep, pathsep|
Buck has no way to know if the results of uncontrolled file system or network access change, and will not reevaluate the build file if that happens.
import copy # whitelisted
import os # safe version will be imported
from os.path import isfile
# Warning! Buck will not detect that the existence of file A affects
# the results of the parsing. The build file will not be processed
# again when A is added/removed.