diff --git a/examples/opf/experiments/multistep/base/permutations_simple_3.py b/examples/opf/experiments/multistep/base/permutations_simple_3.py index 2ce99589a6..6dae642b29 100644 --- a/examples/opf/experiments/multistep/base/permutations_simple_3.py +++ b/examples/opf/experiments/multistep/base/permutations_simple_3.py @@ -27,6 +27,7 @@ '~/nupic/eng/lib/python2.6/site-packages/nupic/frameworks/opf/expGenerator/ExpGenerator.pyc' """ +from nupic import NUPIC_ROOT from nupic.swarming.permutationhelpers import * # The name of the field being predicted. Any allowed permutation MUST contain @@ -58,7 +59,7 @@ 'predictedField': 'field2', 'predictionSteps': [1,3], - 'dataSource': 'file://%s' % (os.path.join(os.environ['NUPIC'], 'examples', 'opf', + 'dataSource': 'file://%s' % (os.path.join(NUPIC_ROOT, 'examples', 'opf', 'experiments', 'multistep', 'datasets', 'simple_3.csv')), '__field2_encoder' : PermuteEncoder(fieldName='field2', diff --git a/nupic/__init__.py b/nupic/__init__.py index 44cddc96fb..c383810ec5 100644 --- a/nupic/__init__.py +++ b/nupic/__init__.py @@ -19,3 +19,7 @@ # http://numenta.org/licenses/ # ---------------------------------------------------------------------- __version__ = "0.3.0.dev0" + +import os +NUPIC_ROOT = os.environ.get('NUPIC', os.path.dirname(os.path.realpath(__file__))) + diff --git a/nupic/support/__init__.py b/nupic/support/__init__.py index ce8e94f4ba..24e668a48f 100644 --- a/nupic/support/__init__.py +++ b/nupic/support/__init__.py @@ -82,6 +82,7 @@ from pkg_resources import resource_string, resource_filename from configuration import Configuration +from nupic import NUPIC_ROOT from nupic.support.fshelpers import makeDirectoryFromAbsolutePath @@ -409,7 +410,7 @@ def initLogging(verbose=False, console='stdout', consoleLevel='DEBUG'): # If NTA_LOG_DIR is not defined, set it now. This is used by the logging # config file to set the path for the log files if 'NTA_LOG_DIR' not in os.environ: - os.environ['NTA_LOG_DIR'] = os.path.join(os.environ['NUPIC'], 'logs') + os.environ['NTA_LOG_DIR'] = os.path.join(NUPIC_ROOT, '../logs') if not os.path.exists(os.environ['NTA_LOG_DIR']): makeDirectoryFromAbsolutePath(os.path.abspath(os.environ['NTA_LOG_DIR'])) diff --git a/tests/integration/nupic/opf/expgenerator_test.py b/tests/integration/nupic/opf/expgenerator_test.py index 531cee139a..4b39ce1d50 100755 --- a/tests/integration/nupic/opf/expgenerator_test.py +++ b/tests/integration/nupic/opf/expgenerator_test.py @@ -35,6 +35,7 @@ from pkg_resources import resource_filename import unittest2 as unittest +from nupic import NUPIC_ROOT from nupic.data import dictutils from nupic.database.ClientJobsDAO import ClientJobsDAO from nupic.support import aggregationDivide @@ -118,7 +119,7 @@ def setUp(self): global g_myEnv if not g_myEnv: # Setup environment - params = type('obj', (object,), {'installDir' : os.environ['NUPIC']}) + params = type('obj', (object,), {'installDir' : NUPIC_ROOT}) g_myEnv = MyTestEnvironment(params) @@ -1947,7 +1948,7 @@ def _getTestList(): # Our custom options (that don't get passed to unittest): customOptions = ['--installDir', '--verbosity', '--logLevel'] parser.add_option( - "--installDir", dest="installDir", default=os.environ['NUPIC'], + "--installDir", dest="installDir", default=NUPIC_ROOT, help="Path to the NTA install directory [default: %default].") parser.add_option("--verbosity", default=0, type="int", @@ -1961,7 +1962,7 @@ def _getTestList(): # The following are put here to document what is accepted by the unittest # module - we don't actually use them in this code bas. - parser.add_option("--verbose", dest="verbose", default=os.environ['NUPIC'], + parser.add_option("--verbose", dest="verbose", default=NUPIC_ROOT, help="Verbose output") parser.add_option("--quiet", dest="quiet", default=None, help="Minimal output") diff --git a/tests/integration/nupic/opf/opf_description_template_test/opf_description_template_test.py b/tests/integration/nupic/opf/opf_description_template_test/opf_description_template_test.py index 56b46a1bb2..35130e8d42 100755 --- a/tests/integration/nupic/opf/opf_description_template_test/opf_description_template_test.py +++ b/tests/integration/nupic/opf/opf_description_template_test/opf_description_template_test.py @@ -27,6 +27,7 @@ import sys import unittest2 as unittest +from nupic import NUPIC_ROOT from nupic.frameworks.opf.opfhelpers import ( loadExperimentDescriptionScriptFromDir, getExperimentDescriptionInterfaceFromModule @@ -47,9 +48,7 @@ class MyTestEnvironment(object): def __init__(self): - nupicDir = os.environ['NUPIC'] - - examplesDir = os.path.join(nupicDir, "examples") + examplesDir = os.path.join(NUPIC_ROOT, "examples") _debugOut("examplesDir=<%s>" % (examplesDir,)) @@ -58,7 +57,7 @@ def __init__(self): # This is where we find OPF binaries (e.g., run_opf_experiment.py, etc.) # In the autobuild, it is a read-only directory - self.__opfBinDir = os.path.join(nupicDir, "scripts") + self.__opfBinDir = os.path.join(NUPIC_ROOT, "scripts") assert os.path.exists(self.__opfBinDir), \ "%s is not present in filesystem" % self.__opfBinDir _debugOut("self.__opfBinDir=<%s>" % self.__opfBinDir) diff --git a/tests/integration/nupic/opf/opf_experiment_results_test.py b/tests/integration/nupic/opf/opf_experiment_results_test.py index 54ca9c398d..bb605bae8d 100755 --- a/tests/integration/nupic/opf/opf_experiment_results_test.py +++ b/tests/integration/nupic/opf/opf_experiment_results_test.py @@ -32,6 +32,7 @@ import time import unittest2 as unittest +from nupic import NUPIC_ROOT from nupic.data.file_record_stream import FileRecordStream @@ -55,9 +56,7 @@ def testExperimentResults(self): examples/prediction directory in the install tree (same as predictionDir) """ - nupicDir = os.environ['NUPIC'] - - opfDir = os.path.join(nupicDir, "examples", "opf") + opfDir = os.path.join(NUPIC_ROOT, "examples", "opf") testDir = opfDir @@ -95,7 +94,7 @@ def testExperimentResults(self): # Run from the test directory so that we can find our experiments os.chdir(testDir) - runExperiment = os.path.join(nupicDir, 'scripts', 'run_opf_experiment.py') + runExperiment = os.path.join(NUPIC_ROOT, 'scripts', 'run_opf_experiment.py') # A list of experiments to run. Valid attributes: # experimentDir - Required, path to the experiment directory containing diff --git a/tests/integration/nupic/opf/opf_experiments_test.py b/tests/integration/nupic/opf/opf_experiments_test.py index b0f8525ff9..89ba735a84 100755 --- a/tests/integration/nupic/opf/opf_experiments_test.py +++ b/tests/integration/nupic/opf/opf_experiments_test.py @@ -26,6 +26,7 @@ import traceback import unittest2 as unittest +from nupic import NUPIC_ROOT from nupic.frameworks.opf.experiment_runner import ( runExperiment, initExperimentPrng) @@ -33,7 +34,7 @@ # Globals EXCLUDED_EXPERIMENTS = [] # none for now -PREDICTION_DIR = os.path.join(os.environ['NUPIC'], 'examples', 'opf') +PREDICTION_DIR = os.path.join(NUPIC_ROOT, 'examples', 'opf') RUN_ALL_ITERATIONS = False diff --git a/tests/swarming/nupic/swarming/swarming_test.py b/tests/swarming/nupic/swarming/swarming_test.py index 759f361fd7..749f3e632d 100755 --- a/tests/swarming/nupic/swarming/swarming_test.py +++ b/tests/swarming/nupic/swarming/swarming_test.py @@ -40,6 +40,7 @@ from optparse import OptionParser +from nupic import NUPIC_ROOT from nupic.database.ClientJobsDAO import ClientJobsDAO from nupic.support import configuration, initLogging from nupic.support.unittesthelpers.testcasebase import (unittest, @@ -255,7 +256,7 @@ def _generateHSJobParams(self, # Form the stream definition if dataPath is None: - dataPath = os.path.join(os.environ['NUPIC'], 'examples', 'prediction', + dataPath = os.path.join(NUPIC_ROOT, 'examples', 'prediction', 'data', 'extra', 'qa', "hotgym", "qa_hotgym.csv") streamDef = dict( version = 1, diff --git a/tests/unit/nupic/support/configuration_test.py b/tests/unit/nupic/support/configuration_test.py index 074fad6966..0bb392a21a 100755 --- a/tests/unit/nupic/support/configuration_test.py +++ b/tests/unit/nupic/support/configuration_test.py @@ -36,11 +36,10 @@ from xml.etree.ElementTree import ParseError except ImportError: from xml.parsers.expat import ExpatError as ParseError -import nupic - -import nupic.support.configuration_base as configuration +from nupic import NUPIC_ROOT +import nupic.support.configuration_base as configuration class ConfigurationTest(unittest.TestCase): @@ -519,7 +518,7 @@ def testGetConfigPathsForNone( configuration.Configuration._configPaths = None # pylint: disable=W0212 result = configuration.Configuration.getConfigPaths() self.assertTrue(isinstance(result, list)) - self.assertEqual(result, [os.path.join(os.environ['NUPIC'], + self.assertEqual(result, [os.path.join(NUPIC_ROOT, 'config', 'default')]) @patch.object(configuration.Configuration, '_configPaths', diff --git a/tests/unit/nupic/support/custom_configuration_test.py b/tests/unit/nupic/support/custom_configuration_test.py index a8fd111fc1..406cdf5020 100755 --- a/tests/unit/nupic/support/custom_configuration_test.py +++ b/tests/unit/nupic/support/custom_configuration_test.py @@ -38,7 +38,7 @@ except ImportError: from xml.parsers.expat import ExpatError as ParseError -import nupic +from nupic import NUPIC_ROOT import nupic.support.configuration_custom as configuration @@ -803,7 +803,7 @@ def testGetConfigPathsForNone( configuration.Configuration._configPaths = None # pylint: disable=W0212 result = configuration.Configuration.getConfigPaths() self.assertTrue(isinstance(result, list)) - self.assertEqual(result, [os.path.join(os.environ['NUPIC'], + self.assertEqual(result, [os.path.join(NUPIC_ROOT, 'config', 'default')]) @patch.object(configuration.Configuration, '_configPaths',