Commits

Aleš Erjavec committed bef07df

Ensure 'build_clib' command is run before 'build_ext'.

(setuptools command 'develop' does not run it).

  • Participants
  • Parent commits fe7189e

Comments (0)

Files changed (1)

 from numpy.distutils.misc_util import Configuration
 
 from setuptools import setup, find_packages
+from setuptools.command.build_ext import build_ext as _build_ext
 
 
 from ConfigParser import SafeConfigParser
 PACKAGES = find_packages()
 
 
-lib_config = namedtuple("lib_config", ["libs", "linkflags", "library_dirs"])
+class build_ext(_build_ext):
+    def run(self):
+        # Run make sure the c libraries are build
+        # (develop and other commands only call build_ext but we
+        # need the libraries to be build before.
+        self.run_command("build_clib")
+        _build_ext.run(self)
+
+
+lib_config = namedtuple(
+    "lib_config", ["libraries", "library_dirs"])
+
 earth_config = namedtuple("earth_config", ["blas", "R"])
 
 
 def libs_parse(text):
-    return map(str.strip, text.split(","))
+    return [lib.strip() for lib in text.split(",")]
 
 
-def library_dirs_parse(text):
-    return text.strip()
+def dirs_parse(text):
+    return text.strip().split(os.path.pathsep)
 
 
 def parse_lib_opt(parser, section):
-    libs, library_dirs = None, None
-    if parser.has_option(section, "libs"):
-        libs = libs_parse(parser.get_option(section, "libs"))
+    libs, library_dirs = [], []
+
+    if parser.has_option(section, "libraries"):
+        libs = libs_parse(parser.get(section, "libraries"))
     if parser.has_option(section, "library_dirs"):
-        library_dirs = \
-            library_dirs_parse(parser.get_option(section, "library_dirs"))
+        library_dirs = dirs_parse(parser.get(section, "library_dirs"))
 
     if libs or library_dirs:
-        return lib_config(libs, [], library_dirs)
+        return lib_config(libs, library_dirs)
     else:
         return None
 
 def site_config():
     blas = R = None
     parser = SafeConfigParser()
-    parser.read(["setup-site.cfg",
-                 os.path.expanduser("~/.orangekit-earth.cfg")])
+    parser.read(["site.cfg",
+                 os.path.expanduser("~/.orangekit-earth-site.cfg")])
 
     if parser.has_section("blas_opt"):
         blas = parse_lib_opt(parser, "blas_opt")
 
 def configuration(parent_package="", top_path=None):
     config = Configuration("earth", parent_package, top_path)
-    link_flags = []
     libraries = []
     library_dirs = []
 
     site = site_config()
+
     if site.blas:
         # Link to provided blas library
-        libraries += site.blas.libs
-        link_flags += site.blas.linkflags
+        libraries += site.blas.libraries
         library_dirs += site.blas.library_dirs
     else:
         # Compile and link the included blas subset
 
     if site.R:
         # Link to the provided R library
-        libraries += site.R.libs
-        link_flags += site.R.linkflags
+        libraries += site.R.libraries
         library_dirs += site.R.library_dirs
     else:
         config.add_library("R", sources=sources("src/rlib/*.c"))
                        ("USE_BLAS", 1),
                        ("MAIN", 1)],
         libraries=libraries + ["m"],
+        library_dirs=library_dirs,
         extra_compile_args=["-std=c99"],
     )
 
     return config
 
-ENTRY_POINTS = {
-    "orange.addons": (
-        "regression__earth = orangekit.earth.earth"
-    ),
-    "orange.widgets": (
-        "Earth = orangekit.earth.widgets.OWEarth"
-    )
-}
-
 INSTALL_REQUIRES = (
     "Orange >= 2.7"
 )
     "Intended Audience :: Developers",
 )
 
+ENTRY_POINTS = {
+    "orange.addons": (
+        "regression__earth = orangekit.earth.earth"
+    ),
+    "orange.widgets": (
+        "Earth = orangekit.earth.widgets.OWEarth"
+    )
+}
+
 
 def setup_package():
     config = configuration("orangekit").todict()
     del config["name"]
-    print config
+
     setup(name=NAME,
           version=VERSION,
           description=DESCRIPTION,
           entry_points=ENTRY_POINTS,
           zip_safe=False,
           include_package_data=True,
+          cmdclass={"build_ext": build_ext},
           **config)
 
 if __name__ == "__main__":