<commit_before>/*ckwg +5
 * Copyright 2011-2012 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#include "registration.h"

#include <vistk/pipeline/utils.h>

#include <vistk/python/util/python_gil.h>

#include <boost/python/import.hpp>

#include <Python.h>

using namespace boost::python;
using namespace vistk;

static envvar_name_t const python_suppress_envvar = envvar_name_t("VISTK_NO_PYTHON_MODULES");

static bool is_suppressed();

void
register_processes()
{
  if (is_suppressed())
  {
    return;
  }

  Py_Initialize();

  try
  {
    vistk::python::python_gil const gil;

    (void)gil;

    object const modules = import("vistk.modules.modules");
    object const loader = modules.attr("load_python_modules");

    loader();
  }
  catch (error_already_set& /*e*/)
  {
    /// \todo Implement.
  }
}

bool
is_suppressed()
{
  envvar_value_t const python_suppress = get_envvar(python_suppress_envvar);

  bool suppress_python_modules = false;

  if (python_suppress)
  {
    suppress_python_modules = true;
  }

  free_envvar(python_suppress);

  return suppress_python_modules;
}<commit_msg>Handle exceptions when loading Python modules<commit_after>/*ckwg +5
 * Copyright 2011-2012 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#include "registration.h"

#include <python/helpers/exceptions.h>

#include <vistk/pipeline/utils.h>

#include <vistk/python/util/python_gil.h>

#include <boost/python/import.hpp>

#include <Python.h>

using namespace boost::python;
using namespace vistk;

static envvar_name_t const python_suppress_envvar = envvar_name_t("VISTK_NO_PYTHON_MODULES");

static void load();
static bool is_suppressed();

void
register_processes()
{
  if (is_suppressed())
  {
    return;
  }

  Py_Initialize();

  HANDLE_PYTHON_EXCEPTION(load())
}

void
load()
{
  vistk::python::python_gil const gil;

  (void)gil;

  object const modules = import("vistk.modules.modules");
  object const loader = modules.attr("load_python_modules");

  loader();
}

bool
is_suppressed()
{
  envvar_value_t const python_suppress = get_envvar(python_suppress_envvar);

  bool suppress_python_modules = false;

  if (python_suppress)
  {
    suppress_python_modules = true;
  }

  free_envvar(python_suppress);

  return suppress_python_modules;
}
{'fraction_non_alphanumeric': 0.10998043052837574, 'fraction_numerical': 0.012524461839530333, 'mean_word_length': 4.66740576496674, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1877654', 'n_tokens_mistral': 937, 'n_tokens_neox': 871, 'n_words': 197}