Skip to content

Commit

Permalink
BLD: generate sources using Cython at setup.py time
Browse files Browse the repository at this point in the history
  • Loading branch information
pv committed Feb 16, 2013
1 parent 907e47e commit 1040b16
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bscript
@@ -1,4 +1,6 @@
import sys
import os
import subprocess

from numpy.distutils.misc_util \
import \
Expand Down Expand Up @@ -122,6 +124,12 @@ def _set_mangling_var(conf, u, du, case, f2pycompat=True):

env.DEFINES.extend(macros)

def _generate_cython():
cwd = os.path.dirname(__file__)
subprocess.call([sys.executable,
os.path.join(cwd, 'tools', 'cythonize'),
os.path.join(cwd, 'scipy')])

@hooks.post_configure
def post_configure(context):
opts = context.waf_options_context
Expand Down Expand Up @@ -174,6 +182,8 @@ def post_configure(context):
def pre_build(context):
bld = context.waf_context

_generate_cython()

context.register_category("gen_pymodule")
bld(features="gen_pymodule",
target="scipy/__config__.py",
Expand Down
16 changes: 16 additions & 0 deletions setup.py
Expand Up @@ -125,6 +125,19 @@ def write_version_py(filename='scipy/version.py'):
a.close()


def generate_cython():
cwd = os.path.dirname(__file__)
p = subprocess.Popen([sys.executable,
os.path.join(cwd, 'tools', 'cythonize'),
os.path.join(cwd, 'scipy')],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
out, err = p.communicate()
if p.returncode != 0:
print(out)
raise RuntimeError("Running cythonize failed!")


def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path)
Expand All @@ -147,6 +160,9 @@ def setup_package():
# Rewrite the version file everytime
write_version_py()

# Generate Cython sources
generate_cython()

setup(
name = 'scipy',
maintainer = "SciPy Developers",
Expand Down
3 changes: 3 additions & 0 deletions setupscons.py
Expand Up @@ -50,6 +50,7 @@
try:
setup_py = __import__("setup")
write_version_py = setup_py.write_version_py
generate_cython = setup_py.generate_cython
finally:
sys.path.pop(0)

Expand Down Expand Up @@ -87,6 +88,8 @@ def setup_package():

write_version_py()

generate_cython()

try:
setup(
name = 'scipy',
Expand Down

0 comments on commit 1040b16

Please sign in to comment.