Anonymous avatar Anonymous committed 56e6df6

Using a subclass of build_py to filter out unwanted modules based on Python version

Comments (0)

Files changed (1)

     from distutils.core import setup
 
 from distutils.command.install import INSTALL_SCHEMES
+from distutils.command.build_py import build_py
 import sys
 import os
+import re
+
+class cherrypy_build_py(build_py):
+    "Custom version of build_py that selects Python-specific wsgiserver"
+    def build_module(self, module, module_file, package):
+        python3 = sys.version_info >= (3,)
+        exclude_pattern = re.compile(
+            'wsgiserver2|ssl_pyopenssl' if python3 else 'wsgiserver3'
+        )
+        if exclude_pattern.match(module):
+            return # skip it
+        return build_py.build_module(self, module, module_file, package)
+
 
 ###############################################################################
 # arguments for the setup command
     "cherrypy.tutorial", "cherrypy.test",
     "cherrypy.process",
     "cherrypy.scaffold",
+    "cherrypy.wsgiserver",
 ]
 download_url="http://download.cherrypy.org/cherrypy/3.2.1/"
 data_files=[
             'cherrypy/tutorial/custom_error.html',
         ]
     ),
-    ("cherrypy/wsgiserver", ["cherrypy/wsgiserver/__init__.py",
-                             "cherrypy/wsgiserver/wsgiserver2.py",
-                             "cherrypy/wsgiserver/wsgiserver3.py",
-                             "cherrypy/wsgiserver/ssl_builtin.py",
-                             "cherrypy/wsgiserver/ssl_pyopenssl.py",
-                             ]),
 ]
 scripts = ["cherrypy/cherryd"]
 
+cmd_class = dict(
+    build_py = cherrypy_build_py,
+)
+
 if sys.version_info >= (3, 0):
     required_python_version = '3.0'
 else:
     """
     def fix_dest_path(path):
         return '\\PURELIB\\%(path)s' % vars()
-    
+
     if not 'bdist_wininst' in sys.argv: return
-    
+
     data_files[:] = [
         (fix_dest_path(path), files)
         for path, files in data_files]
     # platform specific "site-packages" location
     for scheme in list(INSTALL_SCHEMES.values()):
         scheme['data'] = scheme['purelib']
-    
+
     dist = setup(
         name=name,
         version=version,
         download_url=download_url,
         data_files=data_files,
         scripts=scripts,
+        cmdclass=cmd_class,
     )
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.