Repository: Pyomo/pyomo

Issue:
Move pyomo.core.kernel.util
This is the only part of pyomo.core.kernel that imports from pyomo.core.base.  This module defines the pprint() function, which probably should be generalized to include other parts of pyomo.  Hence, I'd recommend moving this to pyomo.common.


Discussion:
I am ok moving it, but not to common - common should not import any other part of Pyomo. 
It would take a lot to generalize that function until we get some common base class structure between the two interfaces. I would recommend we move it to the pyomo.kernel module. This is where all delayed ctype assignments take place that "break" the linkage between core.kernel and core.base.

Resolving patch:
diff --git a/pyomo/core/kernel/__init__.py b/pyomo/core/kernel/__init__.py
--- a/pyomo/core/kernel/__init__.py
+++ b/pyomo/core/kernel/__init__.py
@@ -2,8 +2,8 @@
 #
 #  Pyomo: Python Optimization Modeling Objects
 #  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC
-#  Under the terms of Contract DE-NA0003525 with National Technology and 
-#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain 
+#  Under the terms of Contract DE-NA0003525 with National Technology and
+#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
 #  rights in this software.
 #  This software is distributed under the 3-clause BSD License.
 #  ___________________________________________________________________________
@@ -95,7 +95,6 @@
                                          Binary,
                                          RealInterval,
                                          IntegerInterval)
-from pyomo.core.kernel.util import pprint
 
 #
 # Collecting all of the hacks that needed to be added into
diff --git a/pyomo/kernel/__init__.py b/pyomo/kernel/__init__.py
--- a/pyomo/kernel/__init__.py
+++ b/pyomo/kernel/__init__.py
@@ -14,7 +14,7 @@
 from pyomo.opt import (SolverFactory,
                        SolverStatus,
                        TerminationCondition)
-
+from pyomo.kernel.util import pprint
 from pyomo.core.kernel import *
 
 # set up the Block ctype
diff --git a/pyomo/core/kernel/util.py b/pyomo/kernel/util.py
similarity index 100%
rename from pyomo/core/kernel/util.py
rename to pyomo/kernel/util.py


Test patch:
diff --git a/pyomo/core/tests/unit/test_component_block.py b/pyomo/core/tests/unit/test_component_block.py
--- a/pyomo/core/tests/unit/test_component_block.py
+++ b/pyomo/core/tests/unit/test_component_block.py
@@ -85,6 +85,7 @@ def _collect_expr_components(exp):
 class TestMisc(unittest.TestCase):
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
@@ -97,16 +98,16 @@ def test_pprint(self):
         B.o = objective()
         B.p = parameter()
         B.s = sos([])
-        pyomo.core.kernel.pprint(B)
+        pyomo.kernel.pprint(B)
         b = block()
         b.B = B
-        pyomo.core.kernel.pprint(B)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(B)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(B)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(B)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_ctype(self):
         b = block()
diff --git a/pyomo/core/tests/unit/test_component_constraint.py b/pyomo/core/tests/unit/test_component_constraint.py
--- a/pyomo/core/tests/unit/test_component_constraint.py
+++ b/pyomo/core/tests/unit/test_component_constraint.py
@@ -34,21 +34,22 @@
 class Test_constraint(unittest.TestCase):
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
         v = variable()
         c = constraint((1, v**2, 2))
-        pyomo.core.kernel.pprint(c)
+        pyomo.kernel.pprint(c)
         b = block()
         b.c = c
-        pyomo.core.kernel.pprint(c)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(c)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(c)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(c)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_ctype(self):
         c = constraint()
@@ -1564,16 +1565,16 @@ def test_pprint(self):
         # is still in the early stages.
         v = variable()
         c = linear_constraint(lb=1, terms=[(v,1)], ub=1)
-        pyomo.core.kernel.pprint(c)
+        pyomo.kernel.pprint(c)
         b = block()
         b.c = c
-        pyomo.core.kernel.pprint(c)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(c)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(c)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(c)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_ctype(self):
         c = linear_constraint([],[])
diff --git a/pyomo/core/tests/unit/test_component_dict.py b/pyomo/core/tests/unit/test_component_dict.py
--- a/pyomo/core/tests/unit/test_component_dict.py
+++ b/pyomo/core/tests/unit/test_component_dict.py
@@ -56,20 +56,21 @@ class _TestComponentDictBase(object):
     _ctype_factory = None
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
         cdict = self._container_type({None: self._ctype_factory()})
-        pyomo.core.kernel.pprint(cdict)
+        pyomo.kernel.pprint(cdict)
         b = block()
         b.cdict = cdict
-        pyomo.core.kernel.pprint(cdict)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(cdict)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(cdict)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(cdict)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_ctype(self):
         c = self._container_type()
diff --git a/pyomo/core/tests/unit/test_component_expression.py b/pyomo/core/tests/unit/test_component_expression.py
--- a/pyomo/core/tests/unit/test_component_expression.py
+++ b/pyomo/core/tests/unit/test_component_expression.py
@@ -83,22 +83,23 @@ def test_init_NumericValue(self):
             self.assertIs(noclone(obj).expr, obj)
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
         v = variable()
         e = noclone(v**2)
-        pyomo.core.kernel.pprint(e)
-        pyomo.core.kernel.pprint(e, indent=1)
+        pyomo.kernel.pprint(e)
+        pyomo.kernel.pprint(e, indent=1)
         b = block()
         b.e = expression(expr=e)
-        pyomo.core.kernel.pprint(e)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(e)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(e)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(e)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_pickle(self):
         v = variable()
@@ -270,21 +271,22 @@ class _Test_expression_base(object):
     _ctype_factory = None
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
         p = parameter()
         e = self._ctype_factory(p**2)
-        pyomo.core.kernel.pprint(e)
+        pyomo.kernel.pprint(e)
         b = block()
         b.e = e
-        pyomo.core.kernel.pprint(e)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(e)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(e)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(e)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_pickle(self):
         e = self._ctype_factory(expr=1.0)
diff --git a/pyomo/core/tests/unit/test_component_matrix_constraint.py b/pyomo/core/tests/unit/test_component_matrix_constraint.py
--- a/pyomo/core/tests/unit/test_component_matrix_constraint.py
+++ b/pyomo/core/tests/unit/test_component_matrix_constraint.py
@@ -54,6 +54,7 @@
 class Test_matrix_constraint(unittest.TestCase):
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
@@ -64,16 +65,16 @@ def test_pprint(self):
                                    lb=1,
                                    ub=2,
                                    x=vlist)
-        pyomo.core.kernel.pprint(ctuple)
+        pyomo.kernel.pprint(ctuple)
         b = block()
         b.c = ctuple
-        pyomo.core.kernel.pprint(ctuple)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(ctuple)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(ctuple)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(ctuple)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_ctype(self):
         ctuple = matrix_constraint(numpy.random.rand(3,3))
diff --git a/pyomo/core/tests/unit/test_component_objective.py b/pyomo/core/tests/unit/test_component_objective.py
--- a/pyomo/core/tests/unit/test_component_objective.py
+++ b/pyomo/core/tests/unit/test_component_objective.py
@@ -30,21 +30,22 @@
 class Test_objective(unittest.TestCase):
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
         v = variable()
         o = objective(expr=v**2)
-        pyomo.core.kernel.pprint(o)
+        pyomo.kernel.pprint(o)
         b = block()
         b.o = o
-        pyomo.core.kernel.pprint(o)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(o)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(o)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(o)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_ctype(self):
         o = objective()
diff --git a/pyomo/core/tests/unit/test_component_parameter.py b/pyomo/core/tests/unit/test_component_parameter.py
--- a/pyomo/core/tests/unit/test_component_parameter.py
+++ b/pyomo/core/tests/unit/test_component_parameter.py
@@ -28,20 +28,21 @@
 class Test_parameter(unittest.TestCase):
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
         p = parameter()
-        pyomo.core.kernel.pprint(p)
+        pyomo.kernel.pprint(p)
         b = block()
         b.p = p
-        pyomo.core.kernel.pprint(p)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(p)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(p)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(p)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_ctype(self):
         p = parameter()
diff --git a/pyomo/core/tests/unit/test_component_sos.py b/pyomo/core/tests/unit/test_component_sos.py
--- a/pyomo/core/tests/unit/test_component_sos.py
+++ b/pyomo/core/tests/unit/test_component_sos.py
@@ -29,21 +29,22 @@
 class Test_sos(unittest.TestCase):
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
         vlist = variable_list([variable(), variable()])
         s = sos(vlist)
-        pyomo.core.kernel.pprint(s)
+        pyomo.kernel.pprint(s)
         b = block()
         b.s = s
-        pyomo.core.kernel.pprint(s)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(s)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(s)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(s)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_ctype(self):
         s = sos([])
diff --git a/pyomo/core/tests/unit/test_component_suffix.py b/pyomo/core/tests/unit/test_component_suffix.py
--- a/pyomo/core/tests/unit/test_component_suffix.py
+++ b/pyomo/core/tests/unit/test_component_suffix.py
@@ -34,6 +34,7 @@
 class Test_suffix(unittest.TestCase):
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
@@ -42,18 +43,18 @@ def test_pprint(self):
         s = suffix()
         s[v] = 1
         s[clist] = None
-        pyomo.core.kernel.pprint(s)
+        pyomo.kernel.pprint(s)
         b = block()
         b.s = s
-        pyomo.core.kernel.pprint(s)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(s)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(s)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(s)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
-        pyomo.core.kernel.pprint({'a': 1, 'b': 2})
+        pyomo.kernel.pprint({'a': 1, 'b': 2})
 
     def test_str(self):
         s = suffix()
diff --git a/pyomo/core/tests/unit/test_component_variable.py b/pyomo/core/tests/unit/test_component_variable.py
--- a/pyomo/core/tests/unit/test_component_variable.py
+++ b/pyomo/core/tests/unit/test_component_variable.py
@@ -48,20 +48,21 @@
 class Test_variable(unittest.TestCase):
 
     def test_pprint(self):
+        import pyomo.kernel
         # Not really testing what the output is, just that
         # an error does not occur. The pprint functionality
         # is still in the early stages.
         v = variable()
-        pyomo.core.kernel.pprint(v)
+        pyomo.kernel.pprint(v)
         b = block()
         b.v = v
-        pyomo.core.kernel.pprint(v)
-        pyomo.core.kernel.pprint(b)
+        pyomo.kernel.pprint(v)
+        pyomo.kernel.pprint(b)
         m = block()
         m.b = b
-        pyomo.core.kernel.pprint(v)
-        pyomo.core.kernel.pprint(b)
-        pyomo.core.kernel.pprint(m)
+        pyomo.kernel.pprint(v)
+        pyomo.kernel.pprint(b)
+        pyomo.kernel.pprint(m)
 
     def test_extract_domain_type_and_bounds(self):
         # test an edge case