|
| 1 | +#!/usr/bin/env python3 |
| 2 | +from distutils.core import setup |
| 3 | +from distutils.command.sdist import sdist |
| 4 | +from distutils.command.build_clib import build_clib |
| 5 | +import os |
| 6 | +import sys |
| 7 | +import subprocess |
| 8 | +import shutil |
| 9 | + |
| 10 | +class custom_sdist(sdist): |
| 11 | + def run(self): |
| 12 | + # copy files to somewhere whose paths don't contain "../", and included via MANIFEST.in |
| 13 | + srcfiles = [] |
| 14 | + srctrees = [] |
| 15 | + srcfiles += [ '../../CMakeLists.txt' ] |
| 16 | + srctrees += [ '../../src' ] |
| 17 | + srctrees += [ '../../include' ] |
| 18 | + for src in srcfiles: |
| 19 | + dst = os.path.join('proofofwork', os.path.basename(src)) |
| 20 | + if os.path.exists(dst): |
| 21 | + os.remove(dst) |
| 22 | + print('copying {} -> {}'.format(src, dst)) |
| 23 | + shutil.copy2(src, dst) |
| 24 | + for src in srctrees: |
| 25 | + dst = os.path.join('proofofwork', os.path.basename(src)) |
| 26 | + if os.path.exists(dst): |
| 27 | + shutil.rmtree(dst) |
| 28 | + print('copying {} -> {}'.format(src, dst)) |
| 29 | + shutil.copytree(src, dst) |
| 30 | + return sdist.run(self) |
| 31 | + |
| 32 | +class custom_build_clib(build_clib): |
| 33 | + def build_libraries(self, libraries): |
| 34 | + # workaround |
| 35 | + subprocess.check_call([ 'cmake', 'proofofwork', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=build/lib/proofofwork' ], stdout=sys.stdout, stderr=sys.stderr) |
| 36 | + subprocess.check_call([ 'make' ], stdout=sys.stdout, stderr=sys.stderr) |
| 37 | + |
| 38 | +setup( |
| 39 | + name='proofofwork', |
| 40 | + version='0.0.1', |
| 41 | + description='', # TODO |
| 42 | + # long_description=readme, |
| 43 | + author='Kimiyuki Onaka', |
| 44 | + |
| 45 | + url='https://github.com/kmyk/', # TODO |
| 46 | + license='MIT License', |
| 47 | + packages=[ 'proofofwork' ], |
| 48 | + cmdclass=dict( |
| 49 | + sdist=custom_sdist, |
| 50 | + build_clib=custom_build_clib, |
| 51 | + ), |
| 52 | + package_data={ |
| 53 | + 'proofofwork' : [ |
| 54 | + 'CMakeLists.txt', |
| 55 | + 'src/*.c', |
| 56 | + 'include/*.h', |
| 57 | + ], |
| 58 | + }, |
| 59 | + libraries=[( |
| 60 | + 'proofofwork', dict( |
| 61 | + package='proofofwork', |
| 62 | + sources=[], # dummy |
| 63 | + ), |
| 64 | + )], |
| 65 | + classifiers=[ |
| 66 | + 'Environment :: Console', |
| 67 | + 'Intended Audience :: Developers', |
| 68 | + 'License :: OSI Approved :: MIT License', |
| 69 | + 'Operating System :: OS Independent', |
| 70 | + 'Programming Language :: Python :: 3', |
| 71 | + ], |
| 72 | +) |
0 commit comments