Skip to content
Snippets Groups Projects
Commit a617e4cf authored by Andreas Dedner's avatar Andreas Dedner
Browse files

use correct version number for python package

add numpy, mpi4py to required packages

remove some python 2 related code and fixed up some other issues
pointed out by Timo
deprecated old compatibility file - move Python 3 code to dune.common.utility
parent 454fad5f
No related branches found
No related tags found
No related merge requests found
Showing
with 34 additions and 194 deletions
from __future__ import print_function
try:
from dune.common.module import resolve_dependencies, resolve_order, select_modules
......
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function, unicode_literals
import getopt
import os
import shlex
......
......@@ -72,8 +72,6 @@ function(dune_add_pybind11_module)
add_library(${PYBIND11_MODULE_NAME} SHARED ${PYBIND11_MODULE_SOURCES})
set_target_properties(${PYBIND11_MODULE_NAME} PROPERTIES PREFIX "")
#set_target_properties(${PYBIND11_MODULE_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
#set_target_properties(${PYBIND11_MODULE_NAME} PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)
target_compile_definitions(${PYBIND11_MODULE_NAME} PRIVATE ${PYBIND11_MODULE_COMPILE_DEFINITIONS})
dune_target_enable_all_packages(${PYBIND11_MODULE_NAME})
......
......@@ -421,7 +421,7 @@ macro(dune_process_dependency_leafs modules versions is_required next_level_deps
math(EXPR length "${mlength}-1")
foreach(i RANGE 0 ${length})
list(GET mmodules ${i} _mod)
list(GET mversions ${i} _ver)
list(GET mversions ${i} _ver)
find_dune_package(${_mod} ${is_required} VERSION "${_ver}")
set(${_mod}_SEARCHED ON)
if(NOT "${is_required}" STREQUAL "")
......
......@@ -29,10 +29,6 @@ function(dune_sphinx_doc)
configure_file(${SPHINX_DOC_CONF}.in ${CMAKE_CURRENT_BINARY_DIR}/conf.py)
elseif(EXISTS ${CMAKE_CURRENT_SOUREC_DIR}/${SPHINX_DOC_CONF})
configure_file(${SPHINX_DOC_CONF} ${CMAKE_CURRENT_BINARY_DIR}/conf.py COPYONLY)
# elseif(EXISTS ${CMAKE_SOURCE_DIR}/${SPHINX_DOC_CONF}.in)
# configure_file(${CMAKE_SOURCE_DIR}/${SPHINX_DOC_CONF}.in ${CMAKE_BINARY_DIR}/conf.py)
# elseif(EXISTS ${CMAKE_SOUREC_DIR}/${SPHINX_DOC_CONF})
# configure_file(${CMAKE_SOURCE_DIR}/${SPHINX_DOC_CONF} ${CMAKE_BINARY_DIR}/conf.py COPYONLY)
else()
message(SEND_ERROR "Sphinx configuration '${SPHINX_DOC_CONF}' not found.")
endif()
......
......@@ -50,7 +50,7 @@ namespace Dune
cls.def("__repr__",
[] (const DM& m) {
std::string repr = "DUNE DynamicMatrix:\n(";
std::string repr = "Dune::DynamicMatrix:\n(";
for(unsigned int r = 0; r < m.rows(); r++)
{
......
......@@ -44,7 +44,7 @@ namespace Dune
cls.def("__repr__",
[] (const DV &v) {
std::string repr = "DUNE DynamicVector: (";
std::string repr = "Dune::DynamicVector: (";
for (std::size_t i = 0; i < v.size(); ++i)
repr += (i > 0 ? ", " : "") + std::to_string(v[i]);
......
......@@ -12,9 +12,6 @@ struct GetDimension;
template< class T >
struct GetDimension< T, std::enable_if_t<std::is_arithmetic<T>::value>>
: public std::integral_constant< int, 1 > {};
// template<>
// struct GetDimension<double>
// : public std::integral_constant< int, 1 > {};
template< class FT, int dim >
struct GetDimension<Dune::FieldVector<FT,dim>>
: public std::integral_constant< int, dim > {};
......
#ifndef DUNE_PYTHON_COMMON_ITERATORRANGE_HH
#define DUNE_PYTHON_COMMON_ITERATORRANGE_HH
#include <dune/python/pybind11/pybind11.h>
namespace Dune {
namespace Python {
/**
* Simple range between a begin and an end iterator, with optional length.
*
* This class is similar to dune-common's IteratorRange, but allows
* for different types for begin and end, and includes an optional length
* for Python's `len(...)` operator.
*
* Instances of this type should be registered with
* \seealso registerIteratorRange
*
* \tparam BeginIt type of begin iterator
* \tparam EndIt type of end iterator
*/
template<typename BeginIt, typename EndIt = BeginIt>
class PyIteratorRange
{
public:
using BeginIterator = BeginIt;
using EndIterator = EndIt;
/**
* construct a new iterator range
*/
PyIteratorRange(const BeginIterator& begin, const EndIterator& end, std::size_t length = 0)
: begin_(begin)
, end_(end)
, length_(length)
{}
/**
* returns begin iterator
*/
const BeginIterator& begin() const
{ return begin_; }
/**
* returns end iterator
*/
const EndIterator& end() const
{ return end_; }
/**
* returns distance between begin and end iterator.
* Used to implement Python's `__len__` protocol.
*/
std::size_t length() const
{ return length_; }
private:
BeginIterator begin_;
EndIterator end_;
std::size_t length_;
};
/**
* register a new iterator range Python type
*
* \tparam Range type of iterator range; should be an instance of \ref PyIteratorRange
*
* \param scope Python scope for the new class
* \param name Python name for the new class
* \param hasLength indicates whether Python type should implement `__len__` protocol or not
*/
template<typename Range>
auto registerIteratorRange(pybind11::handle scope, const char* name, bool hasLength = false)
{
using BeginIterator = typename Range::BeginIterator;
using EndIterator = typename Range::EndIterator;
// TODO use insertClass
auto cls = pybind11::class_<Range>(scope, name)
.def("__iter__",
[](const Range& range) { return pybind11::make_iterator(range.begin(), range.end()); },
pybind11::keep_alive<0, 1>());
if (hasLength) {
cls.def(pybind11::init<const BeginIterator&, const EndIterator&, std::size_t>());
cls.def("__len__", &Range::length);
}
else {
cls.def(pybind11::init<const BeginIterator&, const EndIterator&>());
}
return cls;
}
} /* namespace Python */
} /* namespace Dune */
#endif
......@@ -67,11 +67,7 @@ namespace Dune
template< class... Args >
void log ( int level, const std::string &msg, Args &&... args ) const
{
#if PY_MAJOR_VERSION < 3
pybind11::object pyLevel = pybind11::reinterpret_steal< pybind11::object >( PyInt_FromLong( level ) );
#else // #if PY_MAJOR_VERSION < 3
pybind11::object pyLevel = pybind11::int_( level );
#endif // #else // #if PY_MAJOR_VERSION < 3
logger_.attr( "log" )( pyLevel, msg, *pybind11::make_tuple( std::forward< Args >( args )... ) );
}
......
......@@ -375,9 +375,6 @@ namespace Dune
std::vector<std::string> includes = typeName.includes();
includes.insert(includes.end(), inc.begin(), inc.end());
detail::insertIntoTypeRegistry<DuneType>(typeName.name(),"",includes);
// if (!entry.second)
// throw std::invalid_argument( (std::string("adding a class (") +
// typeid(DuneType).name() + ") twice to the type registry").c_str() );
}
......@@ -435,7 +432,6 @@ namespace Dune
cls.def_property_readonly_static( "_typeName", [ entry ] ( pybind11::object ) { return entry.first->second.name; } );
cls.def_property_readonly_static( "_includes", [ entry ] ( pybind11::object ) { return entry.first->second.includes; } );
// cls.def( "__str__", [ entry ] ( pybind11::object ) { return entry.first->second.name; } );
return std::make_pair( cls, true );
}
......
......@@ -164,7 +164,7 @@ namespace Dune
template< std::size_t... i, class T, class... X >
inline static constexpr auto extendArray ( std::index_sequence< i... >, const std::array< T, sizeof...( i ) > &array, X &&... x )
-> std::enable_if_t< Std::conjunction< std::is_convertible< X, T >... >::value, std::array< T, sizeof...( i )+sizeof...( X ) > >
-> std::enable_if_t< std::conjunction< std::is_convertible< X, T >... >::value, std::array< T, sizeof...( i )+sizeof...( X ) > >
{
return {{ array[ i ]..., std::forward< X >( x )... }};
}
......@@ -283,7 +283,7 @@ namespace Dune
return vectorize( std::forward< F >( f ), static_cast< pybind11::detail::function_signature_t< F > * >( nullptr ), std::move( xArray ) );
}
} // namespace Corepy
} // namespace Python
} // namespace Dune
......
# dune_symlink_to_source_files(FILES myclass.hh test_class_export.py)
dune_python_add_test(NAME pythontests
COMMAND ${PYTHON_EXECUTABLE} pythontests.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
LABELS quick)
dune_add_test(SOURCES test_embed1.cc
LINK_LIBRARIES ${DUNE_LIBS} ${PYTHON_LIBRARIES}
LABELS quick
)
add_executable(test_embed2 EXCLUDE_FROM_ALL test_embed2.cc)
target_link_libraries(test_embed2 ${DUNE_LIBS} ${PYTHON_LIBRARIES})
add_subdirectory(dune)
if((${DUNE_COMMON_VERSION} VERSION_LESS 2.6))
configure_file(setup.py.in setup.py)
endif()
configure_file(setup.py.in setup.py)
add_python_targets(common
__init__
compatibility
deprecated
deprecated # deprecated 2.8
module
checkconfiguration
hashit
pickle
pickle # deprecated 2.8
project
utility
)
dune_add_pybind11_module(NAME _common)
set_property(TARGET _common PROPERTY LINK_LIBRARIES dunecommon)
......@@ -20,17 +20,6 @@ PYBIND11_MODULE( _common, module )
Dune::Python::addToTypeRegistry<int>(Dune::Python::GenerateTypeName("int"));
Dune::Python::addToTypeRegistry<std::size_t>(Dune::Python::GenerateTypeName("std::size_t"));
// to reduce compile during dune-common build don't preregister any FV/FM classes
/*
Dune::Python::registerFieldVector<double>(module, std::make_integer_sequence<int, 3>());
Dune::Hybrid::forEach( std::make_integer_sequence< int, 3 >(), [ module ] ( auto rows ) {
Dune::Hybrid::forEach( std::make_integer_sequence< int, 3 >(), [ module ] ( auto cols ) {
Dune::Python::registerFieldMatrix< double, decltype(rows)::value, cols >( module );
} );
} );
*/
Dune::Python::registerDynamicVector<double>(module);
Dune::Python::registerDynamicMatrix<double>(module);
......
from __future__ import print_function, unicode_literals
import logging
import os
import re
......@@ -7,7 +5,7 @@ import subprocess
import dune.common.module
from dune.common.compatibility import buffer_to_str
from dune.common.utility import buffer_to_str
from dune.generator import builder, ConfigurationError
logger = logging.getLogger(__name__)
......@@ -25,10 +23,8 @@ def assertHave(identifier):
matches = [match for match in [re.match('^[ ]*#define[ ]+' + identifier.strip() + '[ ]+ENABLE', line) for line in open(config)] if match is not None]
if not matches:
# logger.info("checkconfiguration.have(" + identifier + ") failed - identifier not defined in " + config)
raise ConfigurationError(identifier + " is not set in dune-py's config.h")
elif matches.__len__() > 1:
# logger.info("checkconfiguration.have(" + identifier + ") failed - multiple definitions in " + config)
raise ConfigurationError(identifier + " found multiple times in dune-py's config.h")
def preprocessorAssert(tests):
......
import importlib
import sys
if sys.version_info.major == 2:
def buffer_to_str(b):
return b
else:
def buffer_to_str(b):
return b.decode('utf-8')
if sys.version_info.major == 2:
def isString(s):
return isinstance(s, (str, unicode))
def isInteger(i):
return isinstance(i, (int, long))
else:
def isString(s):
return isinstance(s, str)
def isInteger(i):
return isinstance(i, int)
if sys.version_info.major == 2:
def reload_module(module):
reload(module)
return module
else:
reload_module = importlib.reload
if sys.version_info.major == 2:
from inspect import getargspec
def getNumberOfParameters(func):
return len( getargspec(func).args )
else:
from inspect import signature
def getNumberOfParameters(func):
return len( signature(func).parameters )
print("""WARNING:
Importing deprecated `dune.common.compatibility'. The Python 2.7 versions
of the functions defined here were removed and the Python 3+ versions moved
so use
import dune.common.utility
instead
""")
from .utility import *
......@@ -13,10 +13,10 @@ import sys
from os.path import expanduser
if __name__ == "dune.common.module":
from dune.common.compatibility import buffer_to_str
from dune.common.utility import buffer_to_str
from dune.common import project
else:
from compatibility import buffer_to_str
from utility import buffer_to_str
import project
logger = logging.getLogger(__name__)
......
import sys
print("""WARNING:
Importing deprecated `dune.common.pickle' use
import pickle
instead
""")
if sys.version_info.major == 2:
from cPickle import *
else:
from pickle import *
from pickle import *
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment