Skip to content

Commit

Permalink
Revert setup.py to exclude ROSCO build, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzalkind committed Dec 18, 2020
1 parent 0e53372 commit e4a1c7f
Showing 1 changed file with 23 additions and 92 deletions.
115 changes: 23 additions & 92 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,9 @@
import io
import os
import sys
from shutil import rmtree, copy
import glob
import platform
from setuptools import find_packages, setup, Command
from numpy.distutils.command.build_ext import build_ext
from numpy.distutils.core import setup, Extension
from shutil import rmtree

import multiprocessing as mp
from distutils.core import run_setup
from setuptools import find_packages
from numpy.distutils.command.build_ext import build_ext
from numpy.distutils.core import setup, Extension
from io import open
from setuptools import find_packages, setup, Command

# Package meta-data.
NAME = 'rosco-toolbox'
Expand All @@ -41,7 +31,7 @@
EMAIL = '[email protected]'
AUTHOR = 'NREL National Wind Technology Center'
REQUIRES_PYTHON = '>=3.4'
VERSION = '3.0.0'
VERSION = '2.1.4'

# These packages are required for all of the code to be executed.
# - Maybe you can get away with older versions...
Expand All @@ -62,64 +52,6 @@
}
}


# For the CMake Extensions
this_directory = os.path.abspath(os.path.dirname(__file__))
ncpus = mp.cpu_count()
class CMakeExtension(Extension):

def __init__(self, name, sourcedir='', **kwa):
Extension.__init__(self, name, sources=[], **kwa)
self.sourcedir = os.path.abspath(sourcedir)

class CMakeBuildExt(build_ext):

def copy_extensions_to_source(self):
newext = []
for ext in self.extensions:
if isinstance(ext, CMakeExtension): continue
newext.append( ext )
self.extensions = newext
super().copy_extensions_to_source()

def build_extension(self, ext):
if isinstance(ext, CMakeExtension):
# Ensure that CMake is present and working
try:
self.spawn(['cmake', '--version'])
except OSError:
raise RuntimeError('Cannot find CMake executable')

# Refresh build directory
localdir = os.path.join(this_directory, 'ROSCO','install')
os.makedirs(localdir, exist_ok=True)

cmake_args = ['-DBUILD_SHARED_LIBS=OFF']
cmake_args += ['-DCMAKE_Fortran_FLAGS=-ffree-line-length-0']

if platform.system() == 'Windows':
cmake_args += ['-DCMAKE_INSTALL_PREFIX={}'.format(localdir)]
if self.compiler.compiler_type == 'msvc':
cmake_args += ['-DCMAKE_GENERATOR_PLATFORM=x64']
else:
cmake_args += ['-G', 'MinGW Makefiles']
cmake_args += ['-D', 'CMAKE_Fortran_COMPILER=gfortran']

self.build_temp += '_'+ext.name
os.makedirs(localdir, exist_ok=True)
# Need fresh build directory for CMake
os.makedirs(self.build_temp, exist_ok=True)

self.spawn(['cmake', '-S', ext.sourcedir, '-B', self.build_temp] + cmake_args)
self.spawn(['cmake', '--build', self.build_temp, '--target', 'install', '--config', 'Release'])

else:
super().build_extension(ext)


# All of the extensions
roscoExt = CMakeExtension('rosco','ROSCO')

# The rest you shouldn't have to touch too much :)
# ------------------------------------------------
# Except, perhaps the License and Trove Classifiers!
Expand Down Expand Up @@ -181,25 +113,24 @@ def run(self):
sys.exit()



metadata = dict(
name = NAME,
version = about['__version__'],
description = DESCRIPTION,
long_description = long_description,
long_description_content_type = 'text/markdown',
author = AUTHOR,
author_email = EMAIL,
url = URL,
install_requires = REQUIRED,
python_requires = REQUIRES_PYTHON,
extras_require = EXTRAS,
include_package_date = True,
packages = find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
license = 'Apache License, Version 2.0',
ext_modules = [roscoExt],
cmdclass = {'build_ext': CMakeBuildExt, 'upload': UploadCommand},
zip_safe = False,
# Where the magic happens:
setup(
name=NAME,
version=about['__version__'],
description=DESCRIPTION,
long_description=long_description,
long_description_content_type='text/markdown',
author=AUTHOR,
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
url=URL,
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
install_requires=REQUIRED,
extras_require=EXTRAS,
include_package_data=True,
license='Apache License, Version 2.0',

cmdclass={
'upload': UploadCommand,
},
)

setup(**metadata)

0 comments on commit e4a1c7f

Please sign in to comment.