__init__.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:pipless 作者: d0c-s4vage 项目源码 文件源码
def activate(self):
        """Activate the virtual environment.

        This actually restarts the pipless script using `os.execve()` to
        replace itself with a subprocess that uses the correct python binary
        from the venv/bin directory with the correct environment variables.
        """
        if self.no_venv:
            self._debug("no_venv was set, not activating")
            return

        new_environ = dict(os.environ)
        new_environ["PATH"] = os.path.join(self.venv_home, "bin") + ":" + new_environ["PATH"]
        new_environ["VIRTUAL_ENV"] = os.path.abspath(self.venv_home)
        new_environ["_"] = os.path.join(self.venv_home, "bin", "python")

        self._debug("replacing current process with new python in new env from venv")
        self._debug("venv found at {!r}".format(self.venv_home))
        venv_python_path = os.path.join(self.venv_home, "bin", "python")

        new_args = [
            venv_python_path,
            "-m", "pipless",
            "--no-venv",

            # even though we say to not use the venv, this is still
            # used to determine where to save the requirements.txt file
            "--venv", self.venv_home
        ]
        if self.debug:
            new_args.append("--debug")
        if self.quiet:
            new_args.append("--quiet")
        if self.no_requirements:
            new_args.append("--no-requirements")
        if self.venv_clear:
            new_args.append("--clear")
        if self._should_color():
            new_args.append("--color")
        if self.venv_system_site_packages:
            new_args.append("--system-site-packages")
        if self.venv_python is not None:
            new_args.append("--python")
            new_args.append(self.venv_python)

        if self.python_opts.get("module", None) is not None:
            new_args.append("-m")
            new_args.append(self.python_opts.get("module"))
        if self.python_opts.get("cmd", None) is not None:
            new_args.append("-c")
            new_args.append(self.python_opts.get("cmd"))

        os.execve(
            venv_python_path,
            new_args + sys.argv,
            new_environ
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号