Compile *.py in directory `dfn` to *.pyo

def compile_dir(dfn, optimize_python=True):
    '''
    Compile *.py in directory `dfn` to *.pyo
    '''

    if PYTHON is None:
        return

    if int(PYTHON_VERSION[0]) >= 3:
        args = [PYTHON, '-m', 'compileall', '-b', '-f', dfn]
    else:
        args = [PYTHON, '-m', 'compileall', '-f', dfn]
    if optimize_python:
        # -OO = strip docstrings
        args.insert(1, '-OO')
    return_code = subprocess.call(args)

    if return_code != 0:
        print('Error while running "{}"'.format(' '.join(args)))
        print('This probably means one of your Python files has a syntax '
              'error, see logs above')
        exit(1)