def run_setup(script_path, egg_base=None):
    # type: (str, Optional[str]) -> Distribution
    """Run a `setup.py` script with a target **egg_base** if provided.

    :param S script_path: The path to the `setup.py` script to run
    :param Optional[S] egg_base: The metadata directory to build in
    :raises FileNotFoundError: If the provided `script_path` does not exist
    :return: The metadata dictionary
    :rtype: Dict[Any, Any]
    """

    if not os.path.exists(script_path):
        raise FileNotFoundError(script_path)
    target_cwd = os.path.dirname(os.path.abspath(script_path))
    if egg_base is None:
        egg_base = os.path.join(target_cwd, "reqlib-metadata")
    with temp_path(), cd(target_cwd), _suppress_distutils_logs():
        # This is for you, Hynek
        # see https://github.com/hynek/environ_config/blob/69b1c8a/setup.py
        args = ["egg_info"]
        if egg_base:
            args += ["--egg-base", egg_base]
        script_name = os.path.basename(script_path)
        g = {"__file__": script_name, "__name__": "__main__"}
        sys.path.insert(0, target_cwd)
        local_dict = {}
        if sys.version_info < (3, 5):
            save_argv = sys.argv
        else:
            save_argv = sys.argv.copy()
        try:
            global _setup_distribution, _setup_stop_after
            _setup_stop_after = "run"
            sys.argv[0] = script_name
            sys.argv[1:] = args
            with open(script_name, "rb") as f:
                contents = f.read()
                if six.PY3:
                    contents.replace(br"\r\n", br"\n")
                else:
                    contents.replace(r"\r\n", r"\n")
                if sys.version_info < (3, 5):
                    exec(contents, g, local_dict)
                else:
                    exec(contents, g)
        # We couldn't import everything needed to run setup
        except Exception:
            python = os.environ.get("PIP_PYTHON_PATH", sys.executable)
            out, _ = run(
                [python, "setup.py"] + args,
                cwd=target_cwd,
                block=True,
                combine_stderr=False,
                return_object=False,
                nospin=True,
            )
        finally:
            _setup_stop_after = None
            sys.argv = save_argv
            _setup_distribution = get_metadata(egg_base, metadata_type="egg")
        dist = _setup_distribution
    return dist
def run_setup ( script_path , egg_base = None ) : if not os . path . exists ( script_path ) : raise FileNotFoundError ( script_path ) target_cwd = os . path . dirname ( os . path . abspath ( script_path ) ) if egg_base is None : egg_base = os . path . join ( target_cwd , "reqlib-metadata" ) with temp_path ( ) , cd ( target_cwd ) , _suppress_distutils_logs ( ) : args = [ "egg_info" ] if egg_base : args += [ "--egg-base" , egg_base ] script_name = os . path . basename ( script_path ) g = { "__file__" : script_name , "__name__" : "__main__" } sys . path . insert ( 0 , target_cwd ) local_dict = { } if sys . version_info < ( 3 , 5 ) : save_argv = sys . argv else : save_argv = sys . argv . copy ( ) try : global _setup_distribution , _setup_stop_after _setup_stop_after = "run" sys . argv [ 0 ] = script_name sys . argv [ 1 : ] = args with open ( script_name , "rb" ) as f : contents = f . read ( ) if six . PY3 : contents . replace ( br"\r\n" , br"\n" ) else : contents . replace ( r"\r\n" , r"\n" ) if sys . version_info < ( 3 , 5 ) : exec ( contents , g , local_dict ) else : exec ( contents , g ) except Exception : python = os . environ . get ( "PIP_PYTHON_PATH" , sys . executable ) out , _ = run ( [ python , "setup.py" ] + args , cwd = target_cwd , block = True , combine_stderr = False , return_object = False , nospin = True , ) finally : _setup_stop_after = None sys . argv = save_argv _setup_distribution = get_metadata ( egg_base , metadata_type = "egg" ) dist = _setup_distribution return dist
Run a `setup.py` script with a target **egg_base** if provided.

    :param S script_path: The path to the `setup.py` script to run
    :param Optional[S] egg_base: The metadata directory to build in
    :raises FileNotFoundError: If the provided `script_path` does not exist
    :return: The metadata dictionary
    :rtype: Dict[Any, Any]