def METHOD_NAME(env):
    '''Find the path to nanopb root directory.'''
    if 'NANOPB' in env:
        # Use nanopb dir given by user
        return env['NANOPB']
    p = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
    if os.path.isdir(p) and os.path.isfile(os.path.join(p, 'pb.h')):
        # Assume we are running under tests/site_scons/site_tools
        return p
    raise SCons.Errors.StopError(NanopbWarning,
        "Could not find the nanopb root directory")