From 987edfa3265187a47b8688119943e7d96712d859 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Tue, 21 Sep 2021 13:45:50 -0700
Subject: [PATCH] Fix PyPy3.8 install locations

---
 setuptools/_distutils/command/install.py | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/setuptools/_distutils/command/install.py b/setuptools/_distutils/command/install.py
index 866e2d5..e98f049 100644
--- a/setuptools/_distutils/command/install.py
+++ b/setuptools/_distutils/command/install.py
@@ -29,16 +29,16 @@
 
 INSTALL_SCHEMES = {
     'unix_prefix': {
-        'purelib': '$base/lib/python$py_version_short/site-packages',
-        'platlib': '$platbase/$platlibdir/python$py_version_short/site-packages',
-        'headers': '$base/include/python$py_version_short$abiflags/$dist_name',
+        'purelib': '$base/lib/$implementation_lower$py_version_short/site-packages',
+        'platlib': '$platbase/$platlibdir/$implementation_lower$py_version_short/site-packages',
+        'headers': '$base/include/$implementation_lower$py_version_short$abiflags/$dist_name',
         'scripts': '$base/bin',
         'data'   : '$base',
         },
     'unix_home': {
-        'purelib': '$base/lib/python',
-        'platlib': '$base/$platlibdir/python',
-        'headers': '$base/include/python/$dist_name',
+        'purelib': '$base/lib/$implementation_lower',
+        'platlib': '$base/$platlibdir/$implementation_lower',
+        'headers': '$base/include/$implementation_lower/$dist_name',
         'scripts': '$base/bin',
         'data'   : '$base',
         },
@@ -64,8 +64,8 @@
     INSTALL_SCHEMES['nt_user'] = {
         'purelib': '$usersite',
         'platlib': '$usersite',
-        'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
-        'scripts': '$userbase/Python$py_version_nodot/Scripts',
+        'headers': '$userbase/$implementation$py_version_nodot/Include/$dist_name',
+        'scripts': '$userbase/$implementation$py_version_nodot/Scripts',
         'data'   : '$userbase',
         }
 
@@ -73,7 +73,7 @@
         'purelib': '$usersite',
         'platlib': '$usersite',
         'headers':
-            '$userbase/include/python$py_version_short$abiflags/$dist_name',
+            '$userbase/include/$implementation_lower$py_version_short$abiflags/$dist_name',
         'scripts': '$userbase/bin',
         'data'   : '$userbase',
         }
@@ -83,6 +83,12 @@
 # and to SCHEME_KEYS here.
 SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
 
+def _get_implementation():
+    if hasattr(sys, 'pypy_version_info'):
+        return 'PyPy'
+    else:
+        return 'Python'
+
 
 class install(Command):
 
@@ -313,6 +319,8 @@ def finalize_options(self):
                             'exec_prefix': exec_prefix,
                             'abiflags': abiflags,
                             'platlibdir': getattr(sys, 'platlibdir', 'lib'),
+                            'implementation_lower': _get_implementation().lower(),
+                            'implementation': _get_implementation(),
                            }
 
         if HAS_USER_SITE: