Esempio n. 1
0
    def create(self):
        """Perform operations needed to make the created environment work on Python 2"""
        super(Python2, self).create()
        # install a patched site-package, the default Python 2 site.py is not smart enough to understand pyvenv.cfg,
        # so we inject a small shim that can do this
        site_py = self.stdlib / "site.py"
        custom_site = get_custom_site()
        if IS_ZIPAPP:
            custom_site_text = read_from_zipapp(custom_site)
        else:
            custom_site_text = custom_site.read_text()
        expected = json.dumps([
            os.path.relpath(ensure_text(str(i)), ensure_text(str(site_py)))
            for i in self.libs
        ])

        custom_site_text = custom_site_text.replace(
            "___EXPECTED_SITE_PACKAGES___", expected)

        reload_code = os.linesep.join(
            "    {}".format(i)
            for i in self.reload_code.splitlines()).lstrip()
        custom_site_text = custom_site_text.replace("# ___RELOAD_CODE___",
                                                    reload_code)

        skip_rewrite = os.linesep.join(
            "            {}".format(i)
            for i in self.skip_rewrite.splitlines()).lstrip()
        custom_site_text = custom_site_text.replace("# ___SKIP_REWRITE____",
                                                    skip_rewrite)

        site_py.write_text(custom_site_text)
Esempio n. 2
0
    def create(self):
        """Perform operations needed to make the created environment work on Python 2"""
        super().create()
        # install a patched site-package, the default Python 2 site.py is not smart enough to understand pyvenv.cfg,
        # so we inject a small shim that can do this, the location of this depends where it's on host
        sys_std_plat = Path(self.interpreter.system_stdlib_platform)
        site_py_in = (
            self.stdlib_platform
            if ((sys_std_plat / "site.py").exists() or (sys_std_plat / "site.pyc").exists())
            else self.stdlib
        )
        site_py = site_py_in / "site.py"

        custom_site = get_custom_site()
        if IS_ZIPAPP:
            custom_site_text = read_from_zipapp(custom_site)
        else:
            custom_site_text = custom_site.read_text()
        expected = json.dumps([os.path.relpath(str(i), str(site_py)) for i in self.libs])

        custom_site_text = custom_site_text.replace("___EXPECTED_SITE_PACKAGES___", expected)

        reload_code = os.linesep.join(f"    {i}" for i in self.reload_code.splitlines()).lstrip()
        custom_site_text = custom_site_text.replace("# ___RELOAD_CODE___", reload_code)

        skip_rewrite = os.linesep.join(f"            {i}" for i in self.skip_rewrite.splitlines()).lstrip()
        custom_site_text = custom_site_text.replace("# ___SKIP_REWRITE____", skip_rewrite)

        site_py.write_text(custom_site_text)
 def create(self):
     """Perform operations needed to make the created environment work on Python 2"""
     super(Python2, self).create()
     # install a patched site-package, the default Python 2 site.py is not smart enough to understand pyvenv.cfg,
     # so we inject a small shim that can do this
     site_py = self.stdlib / "site.py"
     custom_site = get_custom_site()
     if IS_ZIPAPP:
         custom_site_text = read_from_zipapp(custom_site)
     else:
         custom_site_text = custom_site.read_text()
     expected = json.dumps([
         os.path.relpath(six.ensure_text(str(i)),
                         six.ensure_text(str(site_py))) for i in self.libs
     ])
     site_py.write_text(
         custom_site_text.replace("___EXPECTED_SITE_PACKAGES___", expected))