From e754d7f93a01e166bcc1a770773393b283a6a61c Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Sun, 21 Aug 2011 18:21:06 -0700 Subject: [PATCH] Clean up the Cython build process. --- r2/Makefile | 19 +++++++++-------- r2/pyx_setup.py | 54 ------------------------------------------------- r2/setup.py | 18 +++++++++++++++-- 3 files changed, 27 insertions(+), 64 deletions(-) delete mode 100644 r2/pyx_setup.py diff --git a/r2/Makefile b/r2/Makefile index 41b68cdcf..9bee7e867 100644 --- a/r2/Makefile +++ b/r2/Makefile @@ -58,6 +58,7 @@ RTLCSS = $(CSSTARGETS:.css=-rtl.css) NAMES = $(static_dir)/names.json PYX_FILES := $(shell find . -name \*.pyx) +PYXC_FILES := $(PYX_FILES:.pyx=.c) PYXSO_FILES := $(PYX_FILES:.pyx=.so) NAMED = $(JSOUTPUTS) $(CSSTARGETS) $(RTLCSS) $(SPRITES) @@ -78,7 +79,7 @@ endif all: pyx static names $(INIS) -.PHONY: pyx js css rtl static names clean clean_static all +.PHONY: pyx js css rtl static names clean clean_static clean_pyx all $(NAMES): $(JSTARGETS) $(CSSTARGETS) $(RTLCSS) $(SPRITES) $(UPDATE_NAMES) $(NAMES) $(NAMED) @@ -101,12 +102,11 @@ $(RTLCSS): %-rtl.css : %.css -e "s/>#### $@ -$(PYXSO_FILES): %.so : %.pyx - rm -f $(<:.pyx=.pyc) +%.c: %.pyx cython $< - mkdir -p tmp - PYTHONPATH=tmp $(PYTHON) pyx_setup.py develop -d tmp -b tmp $< - rm -r tmp + +$(PYXSO_FILES): $(PYXC_FILES) + python setup.py build_ext --inplace pyx: $(PYXSO_FILES) @@ -120,8 +120,11 @@ rtl: $(RTLCSS) names: $(NAMES) -clean: clean_static - rm -f $(PYXSO_FILES) $(INIS) +clean: clean_static clean_pyx + rm -f $(INIS) + +clean_pyx: + rm -f $(PYXSO_FILES) $(PYXC_FILES) clean_static: clean_names rm -f $(JSOUTPUTS) $(CSSTARGETS) $(RTLCSS) $(SPRITES) diff --git a/r2/pyx_setup.py b/r2/pyx_setup.py deleted file mode 100644 index fc387b1fe..000000000 --- a/r2/pyx_setup.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python - -# The contents of this file are subject to the Common Public Attribution -# License Version 1.0. (the "License"); you may not use this file except in -# compliance with the License. You may obtain a copy of the License at -# http://code.reddit.com/LICENSE. The License is based on the Mozilla Public -# License Version 1.1, but Sections 14 and 15 have been added to cover use of -# software over a computer network and provide for limited attribution for the -# Original Developer. In addition, Exhibit A has been modified to be consistent -# with Exhibit B. -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for -# the specific language governing rights and limitations under the License. -# -# The Original Code is Reddit. -# -# The Original Developer is the Initial Developer. The Initial Developer of the -# Original Code is CondeNet, Inc. -# -# All portions of the code written by CondeNet are Copyright (c) 2006-2010 -# CondeNet, Inc. All Rights Reserved. -################################################################################ - -from ez_setup import use_setuptools -use_setuptools() -from setuptools import find_packages#, setup -from distutils.core import setup, Extension -from Cython.Distutils import build_ext -import os, sys -import shutil - -def build_so(pyx_file): - if not pyx_file.endswith(".pyx"): - raise ValueError, "expected a pyx file, got %s" % pyx_file - if not os.path.exists(pyx_file): - raise ValueError, "pyx file does not exist: %s" % pyx_file - lib = pyx_file[:-4].replace('/', '.').lstrip(".") - name = lib.split('.')[-1] - ext_modules = [ Extension(lib, [pyx_file]) ] - setup( - name=name, - version="", - packages=find_packages(), - include_package_data=True, - test_suite = 'nose.collector', - cmdclass = {'build_ext': build_ext}, - ext_modules = ext_modules, - ) - shutil.rmtree(name + '.egg-info') - - -if __name__ == "__main__": - build_so(sys.argv.pop()) diff --git a/r2/setup.py b/r2/setup.py index ecc318840..4d382a4b3 100644 --- a/r2/setup.py +++ b/r2/setup.py @@ -27,9 +27,11 @@ use_setuptools() from setuptools import find_packages from distutils.core import setup, Extension +from Cython.Distutils import build_ext import os +import fnmatch -commands = {} +commands = {"build_ext": build_ext} try: from babel.messages import frontend as babel commands.update({ @@ -41,6 +43,18 @@ try: except ImportError: pass + +# add the cython modules +pyx_extensions = [] +for root, directories, files in os.walk('.'): + for f in fnmatch.filter(files, '*.pyx'): + path = os.path.join(root, f) + module_name, _ = os.path.splitext(path) + module_name = os.path.normpath(module_name) + module_name = module_name.replace(os.sep, '.') + pyx_extensions.append(Extension(module_name, [path])) + + discount_path = "r2/lib/contrib/discount" setup( @@ -72,7 +86,7 @@ setup( ], packages=find_packages(exclude=["ez_setup"]), cmdclass=commands, - ext_modules=[ + ext_modules=pyx_extensions + [ Extension( "Cfilters", sources=[