Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean build setup #142

Merged
merged 2 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ jobs:
os: osx
language: shell
env: TEST_PKG="dist" BLA_VENDOR="Apple"
- name: "MacOSX, pyenv 3.8.7"
- name: "MacOSX, pyenv 3.8.0"
os: osx
language: shell
env: TEST_PKG="dist" BLA_VENDOR="Apple" SLYCOT_PYTHON_VERSION=3.8.7

env: TEST_PKG="dist" BLA_VENDOR="Apple" SLYCOT_PYTHON_VERSION=3.8.0
allow_failures:
- python: "3.9"
env: TEST_PKG="conda" BLA_VENDOR="Intel10_64lp"

before_install:
- |
Expand Down
33 changes: 4 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,21 @@ if (CMAKE_VERSION VERSION_GREATER "3.11.99")
endif()

project(slycot VERSION ${SLYCOT_VERSION} LANGUAGES NONE)
# Fortran detection fails on windows, use the CMAKE_C_SIMULATE flag to
# force success
if(WIN32)
set(CMAKE_Fortran_SIMULATE_VERSION 19.0)
endif()

# this does not seem to work, maybe scikit-build's doing? the cxx compiler is
# still tested
enable_language(C)
enable_language(Fortran)

# base site dir, use python installation for location specific includes
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"import os,numpy; print(os.path.dirname(numpy.__path__[0]))"
OUTPUT_VARIABLE PYTHON_SITE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(WIN32)
string(REPLACE "\\" "/" PYTHON_SITE ${PYTHON_SITE})
endif()

find_package(PythonLibs REQUIRED)
find_package(PythonExtensions REQUIRED)
find_package(NumPy REQUIRED)
find_package(F2PY REQUIRED)
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)

message(STATUS "NumPy: ${NumPy_INCLUDE_DIR}")
message(STATUS "NumPy included from: ${NumPy_INCLUDE_DIR}")
message(STATUS "F2PY included from: ${F2PY_INCLUDE_DIR}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F2PY_INCLUDE_DIR isn't documented as being set (see https://github.com/scikit-build/scikit-build/blob/c0741f9a1de9dd97e0a1e6f0b3b02fcd76221418/skbuild/resources/cmake/FindF2PY.cmake). This is possibly just an oversight in the docs.

message(STATUS "LAPACK: ${LAPACK_LIBRARIES}")
message(STATUS "BLAS: ${BLAS_LIBRARIES}")
message(STATUS "Slycot version: ${SLYCOT_VERSION}")

# find python, standard packages, F2PY find flaky on Windows
if (NOT WIN32)
find_package(F2PY REQUIRED)
endif()

# pic option for flang not correct, remove for Windows
if (WIN32)
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "")
endif()

add_subdirectory(slycot)

6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ Riccati, Lyapunov, and Sylvester equations.
Dependencies
------------

Slycot supports Python versions 2.7, and 3.5 or later.
Slycot supports Python versions 3.6 or later.

To run the compiled Slycot package, the following must be installed as
dependencies:

- Python 2.7, 3.5+
- Python 3.6+
- NumPy

If you are compiling and installing Slycot from source, you will need the
following dependencies:

- Python 2.7, 3.5+
- 3.6+
- NumPy
- scikit-build >= 0.10.0
- CMake
Expand Down
80 changes: 7 additions & 73 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

"""

import builtins
import os
import sys
import subprocess
Expand All @@ -16,19 +17,14 @@
except ImportError:
import ConfigParser as configparser

if sys.version_info[0] >= 3:
import builtins
else:
import __builtin__ as builtins

try:
from skbuild import setup
from skbuild.command.sdist import sdist
except ImportError:
raise ImportError('scikit-build must be installed before running setup.py')

if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[0:2] < (3, 5):
raise RuntimeError("Python version 2.7 or >= 3.5 required.")
if sys.version_info[0:2] < (3, 6):
raise RuntimeError("Python version >= 3.6 required.")

DOCLINES = __doc__.split("\n")

Expand All @@ -41,8 +37,10 @@
Programming Language :: C
Programming Language :: Fortran
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Topic :: Software Development
Topic :: Scientific/Engineering
Operating System :: Microsoft :: Windows
Expand Down Expand Up @@ -190,35 +188,6 @@ def get_version_info(srcdir=None):
return FULLVERSION, GIT_REVISION


def check_submodules():
""" verify that the submodules are checked out and clean
use `git submodule update --init`; on failure
"""
if not os.path.exists('.git'):
return
with open('.gitmodules') as f:
for l in f:
if 'path' in l:
p = l.split('=')[-1].strip()
if not os.path.exists(p):
raise ValueError('Submodule %s missing' % p)

proc = subprocess.Popen(['git', 'submodule', 'status'],
stdout=subprocess.PIPE)
status, _ = proc.communicate()
status = status.decode("ascii", "replace")
for line in status.splitlines():
if line.startswith('-') or line.startswith('+'):
raise ValueError('Submodule not clean: %s' % line)


class sdist_checked(sdist):
""" check submodules on sdist to prevent incomplete tarballs """
def run(self):
# slycot had no submodules currently
# check_submodules()
sdist.run(self)


def setup_package():
src_path = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -241,7 +210,6 @@ def setup_package():
license='GPL-2.0',
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
cmdclass={"sdist": sdist_checked},
cmake_args=['-DSLYCOT_VERSION:STRING=' + VERSION,
'-DGIT_REVISION:STRING=' + gitrevision,
'-DISRELEASE:STRING=' + str(ISRELEASED),
Expand All @@ -250,40 +218,6 @@ def setup_package():
install_requires=['numpy'],
)

# Windows builds use Flang.
# Flang detection and configuration is not automatic yet; the CMAKE
# settings below are to circumvent that; when scikit-build and cmake
# tools have improved, most of this might be removed?
if platform.system() == 'Windows':

pbase = r'/'.join(sys.executable.split(os.sep)[:-1])
env2cmakearg = {
'FC': ('-DCMAKE_Fortran_COMPILER=',
pbase + r'/Library/bin/flang.exe'),
'F2PY': ('-DF2PY_EXECUTABLE=',
pbase + r'/Scripts/f2py.exe'),
'NUMPY_INCLUDE': ('-DNumPy_INCLUDE_DIR=',
pbase + r'/Include')
}

metadata['cmake_args'].extend(['-GNMake Makefiles'])

for k, v in env2cmakearg.items():
print(k, v, os.environ.get(k, ''))
envval = os.environ.get(k, None)
if envval:
# get from environment
metadata['cmake_args'].append(
v[0] + envval.replace('\\', '/'))
else:
# default
metadata['cmake_args'].append(v[0] + v[1])

metadata['cmake_args'].extend([
'-DCMAKE_Fortran_SIMULATE_VERSION=5.0.0',
'-DCMAKE_Fortran_COMPILER_ID=Flang',
'-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON'])
print(metadata['cmake_args'])
try:
setup(**metadata)
finally:
Expand Down
6 changes: 2 additions & 4 deletions slycot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ set(PYSOURCE
${CMAKE_CURRENT_BINARY_DIR}/version.py)

set(SLYCOT_MODULE "_wrapper")
find_package(PythonExtensions REQUIRED)

set(GENERATED_MODULE
${CMAKE_CURRENT_BINARY_DIR}/${SLYCOT_MODULE}${PYTHON_EXTENSION_MODULE_SUFFIX})
Expand All @@ -141,7 +140,7 @@ add_custom_command(
add_library(
${SLYCOT_MODULE} MODULE
_wrappermodule.c
${PYTHON_SITE}/numpy/f2py/src/fortranobject.c
${F2PY_INCLUDE_DIR}/fortranobject.c
_wrapper-f2pywrappers.f
${FSOURCES})

Expand All @@ -150,8 +149,7 @@ target_link_libraries(${SLYCOT_MODULE}

target_include_directories(
${SLYCOT_MODULE} PUBLIC
${PYTHON_SITE}/numpy/core/include
${PYTHON_SITE}/numpy/f2py/src
${F2PY_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
)

Expand Down