Skip to content

Commit

Permalink
Proper snake_case for nupic.support (part 5) (#3618)
Browse files Browse the repository at this point in the history
* Proper snake_case for nupic.support

* Updated doc guide with new module names
  • Loading branch information
rhyolight authored May 11, 2017
1 parent 755b548 commit 8b48371
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 49 deletions.
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,17 @@ nupic
│   ├── configuration.py [TODO]
│   ├── configuration_base.py [TODO]
│   ├── configuration_custom.py [TODO]
│   ├── consoleprinter.py [TODO]
│   ├── console_printer.py [TODO]
│   ├── decorators.py [TODO]
│   ├── enum.py [TODO]
│   ├── exceptions.py [TODO]
│   ├── feature_groups.py [TODO]
│   ├── features.py [TODO]
│   ├── features_list.py [TODO]
│   ├── fshelpers.py [TODO]
│   ├── fs_helpers.py [TODO]
│   ├── group_by.py [TODO]
│   ├── lockattributes.py [TODO]
│   └── mysqlhelpers.py [TODO]
│   ├── lock_attributes.py [TODO]
│   └── mysql_helpers.py [TODO]
├── swarming
│   ├── DummyModelRunner.py [TODO]
│   ├── HypersearchV2.py [TODO]
Expand Down
2 changes: 1 addition & 1 deletion src/nupic/algorithms/backtracking_tm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from nupic.bindings.math import Random
from nupic.bindings.algorithms import getSegmentActivityLevel, isSegmentActive
from nupic.math import GetNTAReal
from nupic.support.consoleprinter import ConsolePrinterMixin
from nupic.support.console_printer import ConsolePrinterMixin


# Default verbosity while running unit tests
Expand Down
4 changes: 2 additions & 2 deletions src/nupic/database/client_jobs_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from nupic.support.decorators import logExceptions #, logEntryExit
from nupic.database.connection import ConnectionFactory
from nupic.support.configuration import Configuration
from nupic.support import pymysqlhelpers
from nupic.support import pymysql_helpers


_MODULE_NAME = "nupic.database.ClientJobsDAO"
Expand All @@ -55,7 +55,7 @@ class InvalidConnectionException(Exception):
# insertions, etc.
# NOTE: having this as a global permits us to switch parameters wholesale (e.g.,
# timeout)
g_retrySQL = pymysqlhelpers.retrySQL(logger=_LOGGER)
g_retrySQL = pymysql_helpers.retrySQL(logger=_LOGGER)



Expand Down
60 changes: 30 additions & 30 deletions src/nupic/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import os
import nupic.bindings.engine_internal as engine_internal
from nupic.support.lockattributes import LockAttributesMixin
from nupic.support.lock_attributes import LockAttributesMixin
import functools

basicTypes = ['Byte',
Expand Down Expand Up @@ -85,7 +85,7 @@ def registerBuiltInRegions():

def customExceptionHandler(type, value, tb):
"""Catch unhandled Python exception
The handler prints the original exception info including into a buffer.
It then extracts the original error message (when the exception is raised
inside a Py node additional stacktrace info will be appended in the end)
Expand All @@ -108,7 +108,7 @@ def customExceptionHandler(type, value, tb):
for i, line in enumerate(lines):
if line.startswith('RuntimeError:'):
begin = i
#
#
# elif line.startswith('Traceback (most recent call last):'):
# end = i
# break
Expand Down Expand Up @@ -154,19 +154,19 @@ def customExceptionHandler(type, value, tb):

class Dimensions(engine_internal.Dimensions):
"""Represent the topology of an N-dimensional region
Basically, it is a list of integers such as: [4, 8, 6]
In this example the topology is a 3 dimensional region with
4 x 8 x 6 nodes.
You can initialize it with a list of dimensions or with no arguments
and then append dimensions.
"""

def __init__(self, *args):
"""Construct a Dimensions object
The constructor can be called with no arguments or with a list
of integers
"""
Expand All @@ -179,22 +179,22 @@ def __str__(self):

def Array(dtype, size=None, ref=False):
"""Factory function that creates typed Array or ArrayRef objects
dtype - the data type of the array (as string).
Supported types are: Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Real32, Real64
size - the size of the array. Must be positive integer.
"""

def getArrayType(self):
"""A little function to replace the getType() method of arrays
It returns a string representation of the array element type instead of the
integer value (NTA_BasicType enum) returned by the origianl array
"""
return self._dtype


# ArrayRef can't be allocated
if ref:
assert size is None
Expand Down Expand Up @@ -223,10 +223,10 @@ def ArrayRef(dtype):

class CollectionWrapper(object):
"""Wrap an nupic::Collection with a dict-like interface
The optional valueWrapper is used to wrap values for adaptation purposes.
Maintains the original documentation
collection - the original collection
valueWrapper - an optional callable object used to wrap values.
"""
Expand Down Expand Up @@ -295,11 +295,11 @@ def __hash__(self):

class SpecItem(object):
"""Wrapper that translates the data type and access code to a string
The original values are an enumerated type in C++ that become
just integers in Python. This class wraps the original ParameterSpec
and translates the integer values to meaningful strings: that correspond to the C++ enum labels.
It is used to wrap ParameterSpec, InputSpec and OutputSpec
"""
accessModes = ['Create', 'ReadOnly', 'ReadWrite']
Expand Down Expand Up @@ -361,7 +361,7 @@ def __init__(self, region, datatype):
self.datatype = basicTypes[datatype]

def getParameterArray(self, paramName):
# return a PyArray instead of a plain array.
# return a PyArray instead of a plain array.
# PyArray constructor/class for type X is called XArray()
#factoryName = self.datatype + 'Array'
#if factoryName not in globals():
Expand All @@ -382,18 +382,18 @@ class Region(LockAttributesMixin):

#Wrapper for a network region
#- Maintains original documentation
#- Implement syntactic sugar properties:
#- Implement syntactic sugar properties:
#name = property(getName)
#type = property(getType)
#spec = property(getSpec)
#dimensions = property(getDimensions, setDimensions)
#network = property(getNetwork)
#- Makes sure that returned objects are high-level wrapper objects
#- Forwards everything else to internal region

def __init__(self, region, network):
"""Store the wraped region and hosting network
The network is the high-level Network and not the internal
Network. This is important in case the user requests the network
from the region (never leak a engine object, remember)
Expand Down Expand Up @@ -428,9 +428,9 @@ def getSpecFromType(nodeType):
def compute(self):
"""
@doc:place_holder(Region.compute)
** This line comes from the original docstring (not generated by Documentor)
** This line comes from the original docstring (not generated by Documentor)
"""
return self._region.compute()

Expand Down Expand Up @@ -487,7 +487,7 @@ def __cmp__(self, other):
return self._region == other._region

def _getParameterMethods(self, paramName):
"""Returns functions to set/get the parameter. These are
"""Returns functions to set/get the parameter. These are
the strongly typed functions get/setParameterUInt32, etc.
The return value is a pair:
setfunc, getfunc
Expand All @@ -496,7 +496,7 @@ def _getParameterMethods(self, paramName):
if paramName in self._paramTypeCache:
return self._paramTypeCache[paramName]
try:
# Catch the error here. We will re-throw in getParameter or
# Catch the error here. We will re-throw in getParameter or
# setParameter with a better error message than we could generate here
paramSpec = self.getSpec().parameters.getByName(paramName)
except:
Expand Down Expand Up @@ -581,7 +581,7 @@ class Network(engine_internal.Network):

def __init__(self, *args):
"""Constructor
- Initialize the internal engine_internal.Network class generated by Swig
- Attach docstrings to selected methods
"""
Expand All @@ -597,7 +597,7 @@ def __init__(self, *args):
docTable = (
(engine_internal.Network.getRegions, 'Get the collection of regions in a network'),
)

# Attach documentation to methods and properties
for obj, docString in docTable:
if isinstance(obj, str):
Expand All @@ -610,7 +610,7 @@ def __init__(self, *args):

def _getRegions(self):
"""Get the collection of regions in a network
This is a tricky one. The collection of regions returned from
from the internal network is a collection of internal regions.
The desired collection is a collelcion of net.Region objects
Expand All @@ -623,9 +623,9 @@ class is used with a custom makeRegion() function (see bellow)

def makeRegion(name, r):
"""Wrap a engine region with a nupic.engine_internal.Region
Also passes the containing nupic.engine_internal.Network network in _network. This
function is passed a value wrapper to the CollectionWrapper
function is passed a value wrapper to the CollectionWrapper
"""
r = Region(r, self)
#r._network = self
Expand Down
2 changes: 1 addition & 1 deletion src/nupic/frameworks/opf/htm_prediction_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from nupic.data.field_meta import FieldMetaSpecial, FieldMetaInfo
from nupic.encoders import MultiEncoder, DeltaEncoder
from nupic.engine import Network
from nupic.support.fshelpers import makeDirectoryFromAbsolutePath
from nupic.support.fs_helpers import makeDirectoryFromAbsolutePath
from nupic.frameworks.opf.opf_utils import (InferenceType,
InferenceElement,
SensorInput,
Expand Down
2 changes: 1 addition & 1 deletion src/nupic/frameworks/opf/htm_prediction_model_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import os

from nupic.support.fshelpers import makeDirectoryFromAbsolutePath
from nupic.support.fs_helpers import makeDirectoryFromAbsolutePath
from htm_prediction_model import HTMPredictionModel


Expand Down
2 changes: 1 addition & 1 deletion src/nupic/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
from pkg_resources import resource_string, resource_filename

from configuration import Configuration
from nupic.support.fshelpers import makeDirectoryFromAbsolutePath
from nupic.support.fs_helpers import makeDirectoryFromAbsolutePath


# Local imports
Expand Down
16 changes: 8 additions & 8 deletions src/nupic/support/configuration_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import traceback
from xml.etree import ElementTree

from nupic.support.fshelpers import makeDirectoryFromAbsolutePath
from nupic.support.fs_helpers import makeDirectoryFromAbsolutePath
from nupic.support.configuration_base import Configuration as ConfigurationBase


Expand Down Expand Up @@ -86,13 +86,13 @@ def setCustomProperties(cls, properties):
"""
_getLogger().info("Setting custom configuration properties=%r; caller=%r",
properties, traceback.format_stack())

_CustomConfigurationFileWrapper.edit(properties)

for propertyName, value in properties.iteritems():
cls.set(propertyName, value)


@classmethod
def clear(cls):
""" Clear all configuration properties from in-memory cache, but do NOT
Expand All @@ -104,8 +104,8 @@ def clear(cls):

# Reset in-memory custom configuration info.
_CustomConfigurationFileWrapper.clear(persistent=False)


@classmethod
def resetCustomConfig(cls):
""" Clear all custom configuration settings and delete the persistent
Expand All @@ -128,7 +128,7 @@ def loadCustomConfig(cls):
""" Loads custom configuration settings from their persistent storage.
DO NOT CALL THIS: It's typically not necessary to call this method
directly - see NOTE below.
NOTE: this method exists *solely* for the benefit of prepare_conf.py, which
needs to load configuration files selectively.
"""
Expand Down Expand Up @@ -273,7 +273,7 @@ def edit(cls, properties):
newProp.append(valueTag)

elements.append(newProp)

try:
makeDirectoryFromAbsolutePath(os.path.dirname(configFilePath))
with open(configFilePath,'w') as fp:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import os
import unittest2 as unittest

from nupic.support.consoleprinter import ConsolePrinterMixin, Tee
from nupic.support.console_printer import ConsolePrinterMixin, Tee



Expand Down

0 comments on commit 8b48371

Please sign in to comment.