PyObjectInterface 0.1.1rc1__tar.gz → 0.1.1rc2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (18) hide show
  1. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PKG-INFO +27 -1
  2. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface/__init__.py +21 -3
  3. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface.egg-info/PKG-INFO +27 -1
  4. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/README.md +27 -1
  5. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/setup.cfg +1 -1
  6. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/tests/test_poi.py +28 -2
  7. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/LICENSE +0 -0
  8. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/MANIFEST.in +0 -0
  9. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface/WebController.py +0 -0
  10. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface/examples/example.py +0 -0
  11. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface/examples/robot.py +0 -0
  12. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface/web_controller.tpl.html +0 -0
  13. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface.egg-info/SOURCES.txt +0 -0
  14. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface.egg-info/dependency_links.txt +0 -0
  15. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface.egg-info/requires.txt +0 -0
  16. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/PyObjectInterface.egg-info/top_level.txt +0 -0
  17. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/pyproject.toml +0 -0
  18. {PyObjectInterface-0.1.1rc1 → PyObjectInterface-0.1.1rc2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyObjectInterface
3
- Version: 0.1.1rc1
3
+ Version: 0.1.1rc2
4
4
  Summary: Create a web interface to interact with a class
5
5
  Home-page: https://github.com/RobertJN64/PyObjectInterface
6
6
  Author: Robert Nies
@@ -77,3 +77,29 @@ You can use PyObjectInterface without the WebController.
77
77
  - `flask_app`: return value of flask.Flask()
78
78
  - `recursion_depth = 5`: maximum layers of subobjects to include
79
79
  - `create_private_interface = True`: if `True` creates a `/webcontroller/private` page that includes private methods and attributes
80
+
81
+ ### Modifying Attributes
82
+
83
+ By default, POI treats `NoneType, bool, int, float, str, list, dict, tuple, and set` as primitive types.
84
+ These show up in the attribute table instead of as recursive objects.
85
+
86
+ `numpy.ndarray`, `pandas.DataFrame`, and `pandas.Series` are also treated as primitives.
87
+
88
+ If you would like to customize this behavior, you can modify
89
+ `PyObjectInterface.basic_attribute_types`
90
+
91
+ For example:
92
+ ```python
93
+ from PyObjectInterface import basic_attribute_types
94
+
95
+ class My_Class_A: ...
96
+ class My_Class_B: ...
97
+ class My_Class_C: ...
98
+
99
+ basic_attribute_types[str(type(My_Class_A()))] = False
100
+ basic_attribute_types[str(type(My_Class_B()))] = True
101
+ ```
102
+
103
+ `My_Class_A` will be treated as a primitive and only show up in the attributes table.
104
+ `My_Class_B` will also show up in attributes table, but it still appears in the subobjects section.
105
+ `My_Class_C` will only appear in the subobjects section.
@@ -1,6 +1,22 @@
1
1
  from typing_extensions import Self
2
2
  import inspect
3
3
 
4
+ # {type: examine_recursively}
5
+ basic_attribute_types = {
6
+ str(type(None)): False, #NoneType
7
+ str(type(True)): False, #bool
8
+ str(type(1)): False, #int
9
+ str(type(1.0)): False, #float
10
+ str(type('1')): False, #str
11
+ str(type([1])): False, #list
12
+ str(type({1:1})): False, #dict
13
+ str(type((1,1))): False, #tuple
14
+ str(type({1})): False, #set
15
+ "<class 'numpy.ndarray'>": False,
16
+ "<class 'pandas.core.frame.DataFrame'>": False,
17
+ "<class 'pandas.core.series.Series'>": False
18
+ }
19
+
4
20
  class FunctionDesc:
5
21
  def __init__(self, func):
6
22
  self.func = func
@@ -48,12 +64,14 @@ class PyObjectInterface:
48
64
  all_attrs = [x for x in inspect.getmembers(obj) if x[0][0:1] != '_'] #ignore private
49
65
 
50
66
  for (attr_name, instance) in all_attrs:
67
+ if str(type(instance)) in basic_attribute_types:
68
+ self.attribute_list.append(attr_name)
69
+ if not basic_attribute_types[str(type(instance))]:
70
+ continue #skip the rest of the checks, we don't want to examine this item recursively
71
+
51
72
  if hasattr(instance, '__call__'):
52
73
  self.method_dict[attr_name] = FunctionDesc(instance)
53
74
 
54
- elif isinstance(instance, (int, float, str, bool, list, dict)) or instance is None:
55
- self.attribute_list.append(attr_name)
56
-
57
75
  elif recursion_depth > 0: #stop adding subobjects at recursion depth 0
58
76
  # using .__class__ allows superclassing
59
77
  # noinspection PyTypeChecker
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyObjectInterface
3
- Version: 0.1.1rc1
3
+ Version: 0.1.1rc2
4
4
  Summary: Create a web interface to interact with a class
5
5
  Home-page: https://github.com/RobertJN64/PyObjectInterface
6
6
  Author: Robert Nies
@@ -77,3 +77,29 @@ You can use PyObjectInterface without the WebController.
77
77
  - `flask_app`: return value of flask.Flask()
78
78
  - `recursion_depth = 5`: maximum layers of subobjects to include
79
79
  - `create_private_interface = True`: if `True` creates a `/webcontroller/private` page that includes private methods and attributes
80
+
81
+ ### Modifying Attributes
82
+
83
+ By default, POI treats `NoneType, bool, int, float, str, list, dict, tuple, and set` as primitive types.
84
+ These show up in the attribute table instead of as recursive objects.
85
+
86
+ `numpy.ndarray`, `pandas.DataFrame`, and `pandas.Series` are also treated as primitives.
87
+
88
+ If you would like to customize this behavior, you can modify
89
+ `PyObjectInterface.basic_attribute_types`
90
+
91
+ For example:
92
+ ```python
93
+ from PyObjectInterface import basic_attribute_types
94
+
95
+ class My_Class_A: ...
96
+ class My_Class_B: ...
97
+ class My_Class_C: ...
98
+
99
+ basic_attribute_types[str(type(My_Class_A()))] = False
100
+ basic_attribute_types[str(type(My_Class_B()))] = True
101
+ ```
102
+
103
+ `My_Class_A` will be treated as a primitive and only show up in the attributes table.
104
+ `My_Class_B` will also show up in attributes table, but it still appears in the subobjects section.
105
+ `My_Class_C` will only appear in the subobjects section.
@@ -54,4 +54,30 @@ You can use PyObjectInterface without the WebController.
54
54
  - `name: str`: Friendly name for object, generally the name of the variable that refers to the object
55
55
  - `flask_app`: return value of flask.Flask()
56
56
  - `recursion_depth = 5`: maximum layers of subobjects to include
57
- - `create_private_interface = True`: if `True` creates a `/webcontroller/private` page that includes private methods and attributes
57
+ - `create_private_interface = True`: if `True` creates a `/webcontroller/private` page that includes private methods and attributes
58
+
59
+ ### Modifying Attributes
60
+
61
+ By default, POI treats `NoneType, bool, int, float, str, list, dict, tuple, and set` as primitive types.
62
+ These show up in the attribute table instead of as recursive objects.
63
+
64
+ `numpy.ndarray`, `pandas.DataFrame`, and `pandas.Series` are also treated as primitives.
65
+
66
+ If you would like to customize this behavior, you can modify
67
+ `PyObjectInterface.basic_attribute_types`
68
+
69
+ For example:
70
+ ```python
71
+ from PyObjectInterface import basic_attribute_types
72
+
73
+ class My_Class_A: ...
74
+ class My_Class_B: ...
75
+ class My_Class_C: ...
76
+
77
+ basic_attribute_types[str(type(My_Class_A()))] = False
78
+ basic_attribute_types[str(type(My_Class_B()))] = True
79
+ ```
80
+
81
+ `My_Class_A` will be treated as a primitive and only show up in the attributes table.
82
+ `My_Class_B` will also show up in attributes table, but it still appears in the subobjects section.
83
+ `My_Class_C` will only appear in the subobjects section.
@@ -6,7 +6,7 @@ license = MIT
6
6
  license_file = LICENSE
7
7
  url = https://github.com/RobertJN64/PyObjectInterface
8
8
  author_email = robertjnies@gmail.com
9
- version = 0.1.1rc1
9
+ version = 0.1.1rc2
10
10
  long_description = file: README.md
11
11
  long_description_content_type = text/markdown
12
12
  classifiers =
@@ -1,5 +1,6 @@
1
+ from PyObjectInterface import PyObjectInterface, basic_attribute_types
1
2
  from PyObjectInterface.WebController import generate_html
2
- from PyObjectInterface import PyObjectInterface
3
+ import numpy as np
3
4
  import pytest
4
5
 
5
6
  class Nested:
@@ -141,4 +142,29 @@ def test_html():
141
142
 
142
143
  class Blank: pass
143
144
  poi = PyObjectInterface(Blank(), 'Blank')
144
- assert 'table' not in generate_html(poi)
145
+ assert 'table' not in generate_html(poi)
146
+
147
+ class np_special_case:
148
+ def __init__(self):
149
+ self.np_arr = np.array([1,2,3])
150
+
151
+ def test_np_special_case():
152
+ n = np_special_case()
153
+
154
+ poi = PyObjectInterface(n, 'b')
155
+ assert 'np_arr' in poi.attribute_list
156
+ assert 'np_arr' not in poi.subobj_dict
157
+
158
+ basic_attribute_types[str(type(n.np_arr))] = True
159
+
160
+ poi = PyObjectInterface(n, 'b')
161
+ assert 'np_arr' in poi.attribute_list
162
+ assert 'np_arr' in poi.subobj_dict
163
+
164
+ assert "is a builtin method and can't be accessed from WebController" in generate_html(poi)
165
+
166
+ basic_attribute_types.pop(str(type(n.np_arr)))
167
+
168
+ poi = PyObjectInterface(n, 'b')
169
+ assert 'np_arr' not in poi.attribute_list
170
+ assert 'np_arr' in poi.subobj_dict