<commit_before># -*- coding: UTF-8 -*-
#
# Copyright (C) 2008-2010 <NAME> <<EMAIL>>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

"""
Information about the configuration of solvcon.

SOLVCON will find each of the solvcon.ini files from current working directory
toward the root, and use their settings.  Three settings are recognized in
[SOLVCON] section:

* APPS: SOLVCON_APPS
* LOGFILE: SOLVCON_LOGFILE
* PROJECT_DIR: SOLVCON_PROJECT_DIR.  Can be set at empty, which indicates the
    path where the configuration file locates.

Configurable environmental variables:

* ``SOLVCON_PROJECT_DIR``: the directory holds the applications.
* ``SOLVCON_LOGFILE``: filename for solvcon logfile.
* ``SOLVCON_APPS``: names of the available applications, seperated with
  semi-colon.  There should be no spaces.
* ``SOLVCON_FPDTYPE``: a string for the numpy dtype object for floating-point.
  The default fpdtype to be used is float64 (double).
* ``SOLVCON_INTDTYPE``: a string for the numpy dtype object for integer.
  The default intdtype to be used is int32.
* ``SOLVCON_FORTRAN``: flag to use FORTRAN binaries.
* ``SOLVCON_MPI``: flag to use MPI.
"""

__docformat__ = 'restructuredtext en'

class Solvcon(object):
    """
    The configuration singleton.
    """
    def __init__(self):
        import os, sys
        from ConfigParser import ConfigParser
        from .mpy import MPI
        # directories.
        self.pydir = os.path.abspath(os.path.dirname(__file__))
        self.pkgdir = os.path.abspath(os.path.join(self.pydir, '..'))
        libdir = os.path.join(self.pydir, '..', 'lib')
        if not os.path.exists(libdir):
            libdir = os.path.join(sys.prefix, 'lib', 'solvcon')
        self.libdir = os.path.abspath(libdir)
        datadir = os.path.join(self.pydir, '..', 'test', 'data')
        if not os.path.exists(datadir):
            datadir = os.path.join(sys.prefix, 'share', 'solvcon', 'test')
        self.datadir = os.path.abspath(datadir)
        # configuration files.
        cfgdirs = list()
        cwd = os.getcwd()
        parent = os.path.dirname(cwd)
        while parent != cwd:
            if os.path.exists(os.path.join(cwd, 'solvcon.ini')):
                cfgdirs.append(cwd)
            cwd = parent
            parent = os.path.dirname(cwd)
        cfg = ConfigParser()
        cfg.read([
            os.path.join(dname, 'solvcon.ini') for dname in cfgdirs])
        ## project directory.
        project_dir = None
        if cfg.has_option('SOLVCON', 'PROJECT_DIR'):
            project_dir = cfg.get('SOLVCON', 'PROJECT_DIR')
        if project_dir == '' and len(cfgdirs):
            project_dir = cfgdirs[0]
        projdir = os.environ.get('SOLVCON_PROJECT_DIR', project_dir)
        if projdir == None:
            projdir = os.getcwd()
        self.projdir = os.path.abspath(projdir)
        sys.path.insert(0, self.projdir)<commit_msg>Add support to user home installation.<commit_after># -*- coding: UTF-8 -*-
#
# Copyright (C) 2008-2010 <NAME> <<EMAIL>>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

"""
Information about the configuration of solvcon.

SOLVCON will find each of the solvcon.ini files from current working directory
toward the root, and use their settings.  Three settings are recognized in
[SOLVCON] section:

* APPS: SOLVCON_APPS
* LOGFILE: SOLVCON_LOGFILE
* PROJECT_DIR: SOLVCON_PROJECT_DIR.  Can be set at empty, which indicates the
    path where the configuration file locates.

Configurable environmental variables:

* ``SOLVCON_PROJECT_DIR``: the directory holds the applications.
* ``SOLVCON_LOGFILE``: filename for solvcon logfile.
* ``SOLVCON_APPS``: names of the available applications, seperated with
  semi-colon.  There should be no spaces.
* ``SOLVCON_FPDTYPE``: a string for the numpy dtype object for floating-point.
  The default fpdtype to be used is float64 (double).
* ``SOLVCON_INTDTYPE``: a string for the numpy dtype object for integer.
  The default intdtype to be used is int32.
* ``SOLVCON_FORTRAN``: flag to use FORTRAN binaries.
* ``SOLVCON_MPI``: flag to use MPI.
"""

__docformat__ = 'restructuredtext en'

class Solvcon(object):
    """
    The configuration singleton.
    """
    def __init__(self):
        import os, sys
        from ConfigParser import ConfigParser
        from .mpy import MPI
        # directories.
        self.pydir = os.path.abspath(os.path.dirname(__file__))
        self.pkgdir = os.path.abspath(os.path.join(self.pydir, '..'))
        libdir = os.path.join(self.pydir, '..', 'lib')
        for root in [sys.prefix, os.path.join(os.environ['HOME'], '.local')]:
            if not os.path.exists(libdir):
                libdir = os.path.join(root, 'lib', 'solvcon')
        self.libdir = os.path.abspath(libdir)
        datadir = os.path.join(self.pydir, '..', 'test', 'data')
        for root in [sys.prefix, os.path.join(os.environ['HOME'], '.local')]:
            if not os.path.exists(datadir):
                datadir = os.path.join(root, 'share', 'solvcon', 'test')
        self.datadir = os.path.abspath(datadir)
        # configuration files.
        cfgdirs = list()
        cwd = os.getcwd()
        parent = os.path.dirname(cwd)
        while parent != cwd:
            if os.path.exists(os.path.join(cwd, 'solvcon.ini')):
                cfgdirs.append(cwd)
            cwd = parent
            parent = os.path.dirname(cwd)
        cfg = ConfigParser()
        cfg.read([
            os.path.join(dname, 'solvcon.ini') for dname in cfgdirs])
        ## project directory.
        project_dir = None
        if cfg.has_option('SOLVCON', 'PROJECT_DIR'):
            project_dir = cfg.get('SOLVCON', 'PROJECT_DIR')
        if project_dir == '' and len(cfgdirs):
            project_dir = cfgdirs[0]
        projdir = os.environ.get('SOLVCON_PROJECT_DIR', project_dir)
        if projdir == None:
            projdir = os.getcwd()
        self.projdir = os.path.abspath(projdir)
        sys.path.insert(0, self.projdir)
{'fraction_non_alphanumeric': 0.1088538091969801, 'fraction_numerical': 0.0074124914207275225, 'mean_word_length': 2.93200215866163, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6489863', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2248, 'n_words': 730}