Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Mar 12, 2019
2 parents 4dc47f7 + 4b95836 commit 289d320
Show file tree
Hide file tree
Showing 13 changed files with 426 additions and 382 deletions.
2 changes: 0 additions & 2 deletions cmake/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ if(PYTHONLIBS_FOUND)
include_directories(SYSTEM ${PYTHON_INCLUDE_DIR})
add_definitions(-DHAVE_PYTHON=1)
set(PDAL_HAVE_PYTHON 1)
add_definitions(-DPDAL_PYTHON_LIBRARY="${PYTHON_LIBRARY}")
set(PDAL_HAVE_PYTHON 1)
set(PDAL_PYTHON_VERSION_STRING "${PYTHONLIBS_VERSION_STRING}" CACHE STRING "PDAL Python version" FORCE)

find_package(NumPy QUIET 1.5 REQUIRED)
Expand Down
9 changes: 2 additions & 7 deletions kernels/SplitKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <io/BufferReader.hpp>
#include <pdal/StageFactory.hpp>
#include <pdal/util/Utils.hpp>

namespace pdal
{
Expand Down Expand Up @@ -70,17 +71,11 @@ void SplitKernel::addSwitches(ProgramArgs& args)

void SplitKernel::validateSwitches(ProgramArgs& args)
{
#ifdef WIN32
char pathSeparator = '\\';
#else
char pathSeparator = '/';
#endif

if (m_length && m_capacity)
throw pdal_error("Can't specify both length and capacity.");
if (!m_length && !m_capacity)
m_capacity = 100000;
if (m_outputFile.back() == pathSeparator)
if (m_outputFile.back() == Utils::dirSeparator)
m_outputFile += m_inputFile;
}

Expand Down
16 changes: 3 additions & 13 deletions pdal/PluginDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ namespace pdal
namespace
{

#if defined(__APPLE__) && defined(__MACH__)
static const std::string dynamicLibraryExtension(".dylib");
static const char pathSeparator(':');
#elif defined _WIN32
static const std::string dynamicLibraryExtension(".dll");
static const char pathSeparator(';');
#else
static const std::string dynamicLibraryExtension(".so");
static const char pathSeparator(':');
#endif

StringList pluginSearchPaths()
{
StringList searchPaths;
Expand All @@ -61,7 +50,7 @@ StringList pluginSearchPaths()
Utils::getenv("PDAL_DRIVER_PATH", envOverride);

if (!envOverride.empty())
searchPaths = Utils::split2(envOverride, pathSeparator);
searchPaths = Utils::split2(envOverride, Utils::pathListSeparator);
else
{
StringList standardPaths { ".", "./lib", "../lib", "./bin", "../bin" };
Expand Down Expand Up @@ -108,7 +97,8 @@ std::string validPlugin(const std::string& path, const StringList& types)

// Strip the extension off of the end.
pos = file.rfind('.');
if (pos == std::string::npos || file.substr(pos) != dynamicLibraryExtension)
if (pos == std::string::npos ||
(file.substr(pos) != Utils::dynamicLibExtension))
return std::string();
file = file.substr(0, pos);

Expand Down
6 changes: 4 additions & 2 deletions pdal/util/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,17 @@ std::string toAbsolutePath(const std::string& filename)
std::string toAbsolutePath(const std::string& filename, const std::string base)
{
const std::string newbase = toAbsolutePath(base);
return pdalboost::filesystem::absolute(toNative(filename), toNative(newbase)).string();
return pdalboost::filesystem::absolute(toNative(filename),
toNative(newbase)).string();
}


std::string getFilename(const std::string& path)
{
#ifdef _WIN32
std::string pathsep("\\/");
#else
char pathsep = '/';
char pathsep = Utils::dirSeparator;
#endif

std::string::size_type pos = path.find_last_of(pathsep);
Expand Down
16 changes: 15 additions & 1 deletion pdal/util/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ namespace pdal

namespace Utils
{

#if defined(__APPLE__) && defined(__MACH__)
const std::string dynamicLibExtension = ".dylib";
const char dirSeparator = '/';
const char pathListSeparator = ':';
#elif defined _WIN32
const std::string dynamicLibExtension = ".dll";
const char dirSeparator = '\\';
const char pathListSeparator = ';';
#else
const std::string dynamicLibExtension = ".so";
const char dirSeparator = '/';
const char pathListSeparator = ':';
#endif

/**
* \brief Clamp value to given bounds.
*
Expand Down Expand Up @@ -925,7 +940,6 @@ namespace Utils
return true;
}


/**
Convert a string to a value by reading from a string stream.
Expand Down
7 changes: 3 additions & 4 deletions plugins/python/filters/PythonFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ void PythonFilter::addArgs(ProgramArgs& args)
m_module);
args.add("function", "Function to call", m_function);
args.add("add_dimension", "Dimensions to add", m_addDimensions);
args.add("pdalargs", "Dictionary to add to module globals when calling function", m_pdalargs);
args.add("pdalargs", "Dictionary to add to module globals when "
"calling function", m_pdalargs);
}


Expand All @@ -76,7 +77,7 @@ void PythonFilter::ready(PointTableRef table)
{
if (m_source.empty())
m_source = FileUtils::readFileIntoString(m_scriptFile);
static_cast<plang::Environment*>(plang::Environment::get())->set_stdout(log()->getLogStream());
plang::Environment::get()->set_stdout(log()->getLogStream());
m_script = new plang::Script(m_source, m_module, m_function);

m_pythonMethod = new plang::Invocation(*m_script);
Expand Down Expand Up @@ -121,9 +122,7 @@ PointViewSet PythonFilter::run(PointViewPtr view)
m_pythonMethod->end(*view, getMetadata());
viewSet.insert(view);
}

return viewSet;

}


Expand Down
8 changes: 7 additions & 1 deletion plugins/python/plang/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#define PY_ARRAY_UNIQUE_SYMBOL PDAL_ARRAY_API
#include <numpy/arrayobject.h>
#include <pdal/util/Utils.hpp>

#include <sstream>
#include <mutex>
Expand All @@ -62,7 +63,12 @@
__attribute__((constructor))
static void loadPython()
{
::dlopen(PDAL_PYTHON_LIBRARY, RTLD_LAZY | RTLD_GLOBAL);
std::string libname;

pdal::Utils::getenv("PDAL_PYTHON_LIBRARY", libname);
if (libname.empty())
libname = "libPython" + pdal::Utils::dynamicLibExtension;
::dlopen(libname.data(), RTLD_LAZY | RTLD_GLOBAL);
}
#endif

Expand Down
10 changes: 5 additions & 5 deletions plugins/python/plang/Invocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ bool Invocation::execute()
m_scriptArgs = PyTuple_New(numArgs);

if (numArgs > 2)
throw pdal::pdal_error("Only two arguments -- ins and outs numpy arrays -- can be passed!");
throw pdal::pdal_error("Only two arguments -- ins and outs "
"numpy arrays -- can be passed!");

PyTuple_SetItem(m_scriptArgs, 0, m_varsIn);
if (numArgs > 1)
Expand Down Expand Up @@ -348,7 +349,7 @@ bool Invocation::execute()
if (!m_scriptResult)
throw pdal::pdal_error(getTraceback());
if (!PyBool_Check(m_scriptResult))
throw pdal::pdal_error("User function return value not a boolean type.");
throw pdal::pdal_error("User function return value not boolean.");

PyObject* b = PyUnicode_FromString("metadata");
if (PyDict_Contains(m_dictionary, PyUnicode_FromString("metadata")) == 1)
Expand Down Expand Up @@ -430,18 +431,17 @@ void Invocation::begin(PointView& view, MetadataNode m)
m_metadata_PyObject = plang::fromMetadata(m);

// Put 'schema' dict into module scope
Py_XDECREF(m_schema_PyObject);
MetadataNode s = view.layout()->toMetadata();
std::ostringstream ostrm;
Utils::toJSON(s, ostrm);
Py_XDECREF(m_schema_PyObject);
m_schema_PyObject = getPyJSON(ostrm.str());
ostrm.str("");

Py_XDECREF(m_srs_PyObject);
MetadataNode srs = view.spatialReference().toMetadata();
Utils::toJSON(srs, ostrm);
Py_XDECREF(m_srs_PyObject);
m_srs_PyObject = getPyJSON(ostrm.str());
ostrm.str("");
}

void Invocation::end(PointView& view, MetadataNode m)
Expand Down

0 comments on commit 289d320

Please sign in to comment.