-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a262f3a
commit 00f5a98
Showing
1 changed file
with
2 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
import os | ||
import platform | ||
import re | ||
import shutil | ||
import tempfile | ||
from glob import glob | ||
from itertools import chain | ||
from pathlib import Path | ||
|
||
import numpy | ||
from setuptools import Extension, find_packages, setup | ||
from setuptools.command.build_ext import build_ext | ||
from distutils.errors import CompileError, LinkError | ||
from setuptools import find_packages, setup | ||
|
||
PACKAGE_NAME = "crystals" | ||
DESCRIPTION = "Data structures for crystallography" | ||
URL = "http://crystals.readthedocs.io" | ||
DOWNLOAD_URL = "http://github.com/LaurentRDC/crystals" | ||
AUTHOR = "Laurent P. René de Cotret" | ||
AUTHOR_EMAIL = "laurent.[email protected]" | ||
AUTHOR_EMAIL = "laurent.[email protected]" | ||
|
||
CIF_FILES = chain.from_iterable([glob("crystals\\cifs\\*.cif")]) | ||
|
||
|
@@ -40,64 +33,6 @@ | |
REQUIREMENTS = [line for line in f.read().split("\n") if len(line.strip())] | ||
|
||
|
||
# Support for openmp | ||
# This idea is from scikit-image: | ||
# https://github.com/scikit-image/scikit-image/ | ||
class BuildExtWithOpenMP(build_ext): | ||
""" | ||
Try to compile extensions with OpenMP if possible | ||
""" | ||
|
||
def can_compile_link(self, compile_flags, link_flags): | ||
cc = self.compiler | ||
fname = "test.c" | ||
cwd = os.getcwd() | ||
tmpdir = tempfile.mkdtemp() | ||
|
||
code = "#include <omp.h>" "int main(int argc, char** argv) { return(0); }" | ||
|
||
if self.compiler.compiler_type == "msvc": | ||
# make sure we build a DLL on Windows | ||
local_link_flags = link_flags + ["/DLL"] | ||
else: | ||
local_link_flags = link_flags | ||
|
||
try: | ||
os.chdir(tmpdir) | ||
with open(fname, "wt") as fobj: | ||
fobj.write(code) | ||
try: | ||
objects = cc.compile([fname], extra_postargs=compile_flags) | ||
except CompileError: | ||
return False | ||
try: | ||
# Link shared lib rather then executable to avoid | ||
# http://bugs.python.org/issue4431 with MSVC 10+ | ||
cc.link_shared_lib(objects, "testlib", extra_postargs=local_link_flags) | ||
except (LinkError, TypeError): | ||
return False | ||
finally: | ||
os.chdir(cwd) | ||
shutil.rmtree(tmpdir) | ||
return True | ||
|
||
def build_extensions(self): | ||
"""Hook into extension building to set compiler flags""" | ||
if self.compiler.compiler_type == "msvc": | ||
compile_flags = ["/openmp"] | ||
link_flags = [] | ||
else: | ||
compile_flags = ["-fopenmp"] | ||
link_flags = ["-fopenmp"] | ||
|
||
if self.can_compile_link(compile_flags, link_flags): | ||
for ext in self.extensions: | ||
ext.extra_compile_args += compile_flags | ||
ext.extra_link_args += link_flags | ||
|
||
return super().build_extensions() | ||
|
||
|
||
if __name__ == "__main__": | ||
setup( | ||
name=PACKAGE_NAME, | ||
|
@@ -122,7 +57,6 @@ def build_extensions(self): | |
packages=find_packages(), | ||
data_files=[("crystals\\cifs", CIF_FILES)], | ||
include_package_data=True, | ||
cmdclass=dict(build_ext=BuildExtWithOpenMP), | ||
zip_safe=False, | ||
entry_points={"console_scripts": ["crystals = crystals.__main__:main"]}, | ||
# list of possible classifiers: | ||
|