alid value for 'stop_after': {!r}".format(stop_after))

    global _setup_stop_after, _setup_distribution
    _setup_stop_after = stop_after

    save_argv = sys.argv.copy()
    g = {'__file__': script_name, '__name__': '__main__'}
    try:
        try:
            sys.argv[0] = script_name
            if script_args is not None:
                sys.argv[1:] = script_args
            # tokenize.open supports automatic encoding detection
            with tokenize.open(script_name) as f:
                code = f.read().replace(r'\r\n', r'\n')
                exec(code, g)
        finally:
            sys.argv = save_argv
            _setup_stop_after = None
    except SystemExit:
        # Hmm, should we do something if exiting with a non-zero code
        # (ie. error)?
        pass

    if _setup_distribution is None:
        raise RuntimeError(
            (
                "'distutils.core.setup()' was never called -- "
                "perhaps '%s' is not a Distutils setup script?"
            )
            % script_name
        )

    # I wonder if the setup script's namespace -- g and l -- would be of
    # any interest to callers?
    # print "_setup_distribution:", _setup_distribution
    return _setup_distribution


# run_setup ()
