1from __future__ import absolute_import, unicode_literals
2
3import abc
4
5from six import add_metaclass
6
7from virtualenv.create.describe import PosixSupports, Python3Supports, WindowsSupports
8from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
9from virtualenv.util.path import Path
10
11from .common import PyPy
12
13
14@add_metaclass(abc.ABCMeta)
15class PyPy3(PyPy, Python3Supports):
16    @classmethod
17    def exe_stem(cls):
18        return "pypy3"
19
20    @property
21    def stdlib(self):
22        """
23        PyPy3 seems to respect sysconfig only for the host python...
24        virtual environments purelib is instead lib/pythonx.y
25        """
26        return self.dest / "lib" / "python{}".format(self.interpreter.version_release_str) / "site-packages"
27
28    @classmethod
29    def exe_names(cls, interpreter):
30        return super(PyPy3, cls).exe_names(interpreter) | {"pypy"}
31
32
33class PyPy3Posix(PyPy3, PosixSupports):
34    """PyPy 2 on POSIX"""
35
36    @classmethod
37    def _shared_libs(cls):
38        return ["libpypy3-c.so", "libpypy3-c.dylib"]
39
40    def to_lib(self, src):
41        return self.dest / "lib" / src.name
42
43    @classmethod
44    def sources(cls, interpreter):
45        for src in super(PyPy3Posix, cls).sources(interpreter):
46            yield src
47        host_lib = Path(interpreter.system_prefix) / "lib"
48        if host_lib.exists() and host_lib.is_dir():
49            for path in host_lib.iterdir():
50                yield PathRefToDest(path, dest=cls.to_lib)
51
52
53class Pypy3Windows(PyPy3, WindowsSupports):
54    """PyPy 2 on Windows"""
55
56    @property
57    def bin_dir(self):
58        """PyPy3 needs to fallback to pypy definition"""
59        return self.dest / "Scripts"
60
61    @classmethod
62    def _shared_libs(cls):
63        return ["libpypy3-c.dll"]
64