Source

pyyaml / setup.py

Diff from to
     "Topic :: Text Processing :: Markup",
 ]
 
-from ez_setup import use_setuptools
-use_setuptools(version='0.6c5')
 
-from setuptools import setup, Extension, Feature
+from distutils.core import setup, Command
+from distutils.core import Distribution as _Distribution
+from distutils.core import Extension as _Extension
+from distutils.command.build_ext import build_ext as _build_ext
+
+try:
+    from Pyrex.Distutils import Extension as _Extension
+    from Pyrex.Distutils import build_ext as _build_ext
+    with_pyrex = True
+except ImportError:
+    with_pyrex = False
+
+import sys, os.path
+
+
+class Distribution(_Distribution):
+
+    def __init__(self, attrs=None):
+        _Distribution.__init__(self, attrs)
+        if not self.ext_modules:
+            return
+        for ext in reversed(self.ext_modules):
+            if not isinstance(ext, Extension):
+                continue
+            setattr(self, ext.attr_name, None)
+            self.global_options = [
+                    (ext.option_name, None,
+                        "include %s" % ext.feature_description),
+                    (ext.neg_option_name, None,
+                        "exclude %s (default)" % ext.feature_description),
+            ] + self.global_options
+            self.negative_opt = self.negative_opt.copy()
+            self.negative_opt[ext.neg_option_name] = ext.option_name
+
+
+class Extension(_Extension):
+
+    def __init__(self, name, sources, feature_name, feature_description, **kwds):
+        if not with_pyrex:
+            for filename in sources[:]:
+                base, ext = os.path.splitext(filename)
+                if ext == 'pyx':
+                    sources.replace(filename, '%s.c' % base)
+        _Extension.__init__(self, name, sources, **kwds)
+        self.feature_name = feature_name
+        self.feature_description = feature_description
+        self.attr_name = 'with_' + feature_name.replace('-', '_')
+        self.option_name = 'with-' + feature_name
+        self.neg_option_name = 'without-' + feature_name
+
+
+class build_ext(_build_ext):
+
+    def get_source_files(self):
+        self.check_extensions_list(self.extensions)
+        filenames = []
+        for ext in self.extensions:
+            if with_pyrex:
+                self.pyrex_sources(ext.sources, ext)
+            for filename in ext.sources:
+                filenames.append(filename)
+                base = os.path.splitext(filename)[0]
+                for ext in ['c', 'h', 'pyx', 'pxd']:
+                    filename = '%s.%s' % (base, ext)
+                    if filename not in filenames and os.path.isfile(filename):
+                        filenames.append(filename)
+        return filenames
+
+    def build_extensions(self):
+        self.check_extensions_list(self.extensions)
+        for ext in self.extensions:
+            if isinstance(ext, Extension):
+                if not getattr(self.distribution, ext.attr_name):
+                    continue
+            if with_pyrex:
+                ext.sources = self.pyrex_sources(ext.sources, ext)
+            self.build_extension(ext)
+
+
+class test(Command):
+
+    user_options = []
+
+    def initialize_options(self):
+        pass
+
+    def finalize_options(self):
+        pass
+
+    def run(self):
+        build_cmd = self.get_finalized_command('build')
+        build_cmd.run()
+        sys.path.insert(0, build_cmd.build_lib)
+        sys.path.insert(0, 'tests')
+        import test_all
+        test_all.main()
+
 
 if __name__ == '__main__':
 
 
         package_dir={'': 'lib'},
         packages=['yaml'],
+        ext_modules=[
+            Extension('yaml/_yaml', ['ext/_yaml.pyx'],
+                'libyaml', "LibYAML bindings",
+                libraries=['yaml']),
+        ],
 
-        features = {
-            'libyaml': Feature(
-                description="LibYAML bindings",
-                ext_modules=[
-                    Extension('_yaml', ['ext/_yaml.pyx'], libraries=['yaml']),
-                ],
-            ),
+        distclass=Distribution,
+        cmdclass={
+            'build_ext': build_ext,
+            'test': test,
         },
     )