|
9 | 9 | except ImportError: |
10 | 10 | sys.exit('setuptools was not detected - please install setuptools and pip') |
11 | 11 | from solar_utils import __version__ as VERSION, __name__ as NAME |
| 12 | +import logging |
| 13 | + |
| 14 | +logging.basicConfig(level=logging.DEBUG) |
| 15 | +logger = logging.getLogger(__name__) |
12 | 16 |
|
13 | 17 | PLATFORM = sys.platform |
14 | 18 | if PLATFORM == 'win32': |
15 | | - SRCDIR = 'win32' |
| 19 | + SRC_DIR = 'win32' |
16 | 20 | elif PLATFORM == 'darwin': |
17 | | - SRCDIR = 'darwin' |
| 21 | + SRC_DIR = 'darwin' |
18 | 22 | elif PLATFORM == 'linux2': |
19 | | - SRCDIR = 'linux' |
| 23 | + SRC_DIR = 'linux' |
20 | 24 | else: |
21 | 25 | sys.exit('unknown platform - expected "win32", "darwin" or "linux2"') |
22 | 26 |
|
23 | | -CC = distutils.ccompiler.new_compiler() |
24 | | -CC.set_include_dirs('path\\to\\srcdir') |
25 | | -CC.compile(['win32\\solposAM.c','win32\\solpos.c']) |
26 | | -CC.link_shared_lib(['win32\\solposAM.obj','win32\\solpos.obj'], 'solposAM') |
| 27 | +PKG_DATA = [os.path.join(SRC_DIR, '*.*'), os.path.join(SRC_DIR, 'src', '*.*')] |
| 28 | +LIB_DIR = os.path.join(NAME, SRC_DIR) |
| 29 | +SRC_DIR = os.path.join(LIB_DIR, 'src') |
| 30 | +logger.debug(PKG_DATA) |
| 31 | +TESTS = '%s.tests' % NAME |
| 32 | +TEST_DATA = ['test_spectrl2_data.json'] |
| 33 | +SOLPOS = 'solpos.c' |
| 34 | +SOLPOSAM = 'solposAM.c' |
| 35 | +SOLPOSAM_LIB = 'solposAM' |
| 36 | +SPECTRL2 = 'spectrl2.c' |
| 37 | +SPECTRL2_2 = 'spectrl2_2.c' |
| 38 | +SPECTRL2_LIB = 'spectrl2' |
| 39 | +SOLPOS = os.path.join(SRC_DIR, SOLPOS) |
| 40 | +SOLPOSAM = os.path.join(SRC_DIR, SOLPOSAM) |
| 41 | +SPECTRL2 = os.path.join(SRC_DIR, SPECTRL2) |
| 42 | +SPECTRL2_2 = os.path.join(SRC_DIR, SPECTRL2_2) |
| 43 | +LIB_FILES = ['%s.dll', '%s.lib', '%s.exp', 'lib%s.so', 'lib%s.dylib', 'lib%s.a'] |
| 44 | +if 'clean' in sys.argv or 'distclean' in sys.argv: |
| 45 | + for lib_file in LIB_FILES: |
| 46 | + try: |
| 47 | + os.remove(os.path.join(LIB_DIR, lib_file % SOLPOSAM_LIB)) |
| 48 | + except OSError as err: |
| 49 | + sys.stderr.write(err.message) |
| 50 | + try: |
| 51 | + os.remove(os.path.join(LIB_DIR, lib_file % SPECTRL2_LIB)) |
| 52 | + except OSError as err: |
| 53 | + sys.stderr.write(err.message) |
| 54 | +else: |
| 55 | + # compile NREL source code |
| 56 | + CC = distutils.ccompiler.new_compiler() # initialize compiler object |
| 57 | + CC.set_include_dirs([SRC_DIR]) # set includes directory |
| 58 | + OBJS = CC.compile([SOLPOS, SOLPOSAM]) # compile solpos and solposAM objects |
| 59 | + # link objects and make shared library in library directory |
| 60 | + CC.link_shared_lib(OBJS, SOLPOSAM_LIB, output_dir=LIB_DIR) |
| 61 | + OBJS = CC.compile([SPECTRL2, SPECTRL2_2, SOLPOS]) # compile spectrl2 objects |
| 62 | + CC.set_libraries([SOLPOSAM_LIB]) # set linked libraries |
| 63 | + CC.set_library_dirs([LIB_DIR]) # set library directories |
| 64 | + # link objects and make shared library in library directory |
| 65 | + CC.link_shared_lib(OBJS, SPECTRL2_LIB, output_dir=LIB_DIR) |
27 | 66 |
|
28 | | -setup(name = NAME, |
29 | | - version = VERSION, |
30 | | - packages = [NAME], |
31 | | - package_data = {NAME: PKG_DATA}, |
32 | | - description = 'Python wrapper around NREL SOLPOS and SPECTRL2') |
| 67 | +setup(name=NAME, |
| 68 | + version=VERSION, |
| 69 | + packages=[NAME, TESTS], |
| 70 | + package_data={NAME: PKG_DATA, TESTS: TEST_DATA}, |
| 71 | + description='Python wrapper around NREL SOLPOS and SPECTRL2') |
0 commit comments