get-module-underlying 0.0.1__py3-none-any.whl

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.
_exceptions.py ADDED
@@ -0,0 +1,5 @@
1
+ # _exceptions.py
2
+
3
+ class ValidNotTrueWarning(Warning):
4
+ """Raised when the module is not valid."""
5
+ pass
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.1
2
+ Name: get-module-underlying
3
+ Version: 0.0.1
4
+ Summary: Explore Python modules deeper than dir()
5
+ Home-page: UNKNOWN
6
+ Author: San Zhang
7
+ Author-email: san.zhang@example.com
8
+ License: MIT
9
+ Platform: UNKNOWN
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: absence
14
+
15
+ # get_module_underlying
16
+
17
+ Explore Python modules deeper than `dir()`.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install get_module_underlying
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```python
28
+ from get_module_underlying import ModuleExplorer
29
+
30
+ # Explore a module
31
+ explorer = ModuleExplorer('sys')
32
+
33
+ # Get all attributes (excluding __xxx__)
34
+ print(explorer.get_all_attrs())
35
+
36
+ # Get only public attributes
37
+ print(explorer.get_public_attrs())
38
+
39
+ # Get private attributes (single underscore)
40
+ print(explorer.get_private_attrs())
41
+
42
+ # Get dunder attributes (__xxx__)
43
+ print(explorer.get_dunder_attrs())
44
+
45
+ # Get callable methods/functions
46
+ print(explorer.get_callable_attrs())
47
+
48
+ # Get non-callable attributes (variables, constants)
49
+ print(explorer.get_non_callable_attrs())
50
+
51
+ # Get attributes with their values
52
+ print(explorer.get_attrs_with_values())
53
+
54
+ # Get attributes with their types
55
+ print(explorer.get_attrs_with_types())
56
+
57
+ # Get all classes
58
+ print(explorer.get_classes())
59
+
60
+ # Get all functions
61
+ print(explorer.get_functions())
62
+
63
+ # Get all builtins
64
+ print(explorer.get_builtins())
65
+
66
+ # Get all submodules
67
+ print(explorer.get_modules())
68
+
69
+ # Get detailed module info
70
+ print(explorer.get_module_info())
71
+
72
+ # Get statistics summary
73
+ print(explorer.get_stats())
74
+
75
+ # Get Python system info
76
+ print(explorer.get_sys_info())
77
+
78
+ # Get module file info
79
+ print(explorer.get_file_info())
80
+
81
+ # Get everything at once
82
+ print(explorer.get_everything())
83
+ ```
84
+
85
+ ## Methods Reference
86
+
87
+ | Method | Return Type | Description |
88
+ |--------|-------------|-------------|
89
+ | `get_all_attrs()` | `{'valid': bool, 'data': list}` | All attributes except dunder (`__xxx__`) |
90
+ | `get_public_attrs()` | `{'valid': bool, 'data': list}` | Attributes not starting with `_` |
91
+ | `get_private_attrs()` | `{'valid': bool, 'data': list}` | Attributes with single `_` prefix |
92
+ | `get_dunder_attrs()` | `{'valid': bool, 'data': list}` | Dunder attributes (`__xxx__`) |
93
+ | `get_callable_attrs()` | `{'valid': bool, 'data': list}` | Callable functions/methods |
94
+ | `get_non_callable_attrs()` | `{'valid': bool, 'data': list}` | Non-callable variables/constants |
95
+ | `get_attrs_with_values()` | `{'valid': bool, 'data': dict}` | Attribute names with their values |
96
+ | `get_attrs_with_types()` | `{'valid': bool, 'data': dict}` | Attribute names with their types |
97
+ | `get_classes()` | `{'valid': bool, 'data': list}` | All classes in the module |
98
+ | `get_functions()` | `{'valid': bool, 'data': list}` | All functions in the module |
99
+ | `get_builtins()` | `{'valid': bool, 'data': list}` | All built-in functions |
100
+ | `get_modules()` | `{'valid': bool, 'data': list}` | All submodules imported |
101
+ | `get_module_info()` | `{'valid': bool, 'data': dict}` | Module metadata (name, file, doc, etc.) |
102
+ | `get_stats()` | `{'valid': bool, 'data': dict}` | Statistical summary of all attributes |
103
+ | `get_sys_info()` | `{'valid': bool, 'data': dict}` | Python system information |
104
+ | `get_file_info()` | `{'valid': bool, 'data': dict}` | Module source file information |
105
+ | `get_everything()` | `{'valid': bool, 'data': dict}` | All information combined |
106
+
107
+ ## Return Format
108
+
109
+ All methods return a dictionary with the following structure:
110
+
111
+ ```python
112
+ {
113
+ 'valid': True, # bool: True if module is valid, False otherwise
114
+ 'data': ... # The actual data (list or dict)
115
+ }
116
+ ```
117
+
118
+ If the module is not valid, the method will:
119
+ - Emit a `ValidNotTrueWarning` warning
120
+ - Return `{'valid': False}`
121
+
122
+ ## Dependencies
123
+
124
+ - Python 3.6+
125
+ - `absence` library (automatically installed)
126
+
127
+ ## License
128
+
129
+ MIT
130
+
@@ -0,0 +1,6 @@
1
+ _exceptions.py,sha256=oupQ3hSTPp1tniS5HHbI0jT1RUE2pkMfqVwBYesVIHQ,115
2
+ get_module_underlying.py,sha256=UXdpTPbcqybrR2U3HjU7GSbr_n3HwDVTUbXOg0QyvQ4,10627
3
+ get_module_underlying-0.0.1.dist-info/METADATA,sha256=wIpyTqb0Ysizf1Q1p0XQFM9z4_1wowwE3NlzdqHa-kU,3936
4
+ get_module_underlying-0.0.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
5
+ get_module_underlying-0.0.1.dist-info/top_level.txt,sha256=oCnPXZ81vDPSEsmaVDpQfZ18n1NmUQMDrzLASAz6Pys,34
6
+ get_module_underlying-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.45.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ _exceptions
2
+ get_module_underlying
@@ -0,0 +1,296 @@
1
+ # get_module_underlying.py
2
+
3
+ import sys
4
+ import __main__
5
+ import os
6
+ import types
7
+ import warnings
8
+ from _exceptions import ValidNotTrueWarning
9
+
10
+
11
+ class ModuleExplorer:
12
+ """
13
+ Module explorer - goes deeper than dir()
14
+ """
15
+
16
+ def __init__(self, module_name=None):
17
+ self.name = module_name
18
+ self.module = None
19
+ self._valid = False
20
+ self._error = None
21
+
22
+ try:
23
+ import absence
24
+ from absence import absent
25
+ except ImportError as e:
26
+ self._error = str(e)
27
+ warnings.warn(f"Failed to import 'absence': {e}", ValidNotTrueWarning)
28
+ return
29
+
30
+ if module_name is None or module_name is absent:
31
+ self._error = "Module name cannot be None or absent."
32
+ warnings.warn(self._error, ValidNotTrueWarning)
33
+ return
34
+
35
+ self.name = module_name
36
+
37
+ if module_name in sys.modules:
38
+ self.module = sys.modules[module_name]
39
+ self._valid = True
40
+ else:
41
+ try:
42
+ self.module = __import__(module_name)
43
+ self._valid = True
44
+ except (ImportError, ModuleNotFoundError) as e:
45
+ self._error = str(e)
46
+ warnings.warn(f"Module '{module_name}' not found: {e}", ValidNotTrueWarning)
47
+ self.module = None
48
+ self._valid = False
49
+
50
+ def is_valid(self):
51
+ return self._valid
52
+
53
+ def _check_and_warn(self):
54
+ if not self._valid:
55
+ if self._error:
56
+ warnings.warn(self._error, ValidNotTrueWarning)
57
+ else:
58
+ warnings.warn(f"Module '{self.name}' is not valid.", ValidNotTrueWarning)
59
+ return False
60
+ return True
61
+
62
+ def get_all_attrs(self):
63
+ if not self._check_and_warn():
64
+ return {'valid': False}
65
+ return {
66
+ 'valid': True,
67
+ 'data': sorted([
68
+ k for k in dir(self.module)
69
+ if not (k.startswith('__') and k.endswith('__'))
70
+ ])
71
+ }
72
+
73
+ def get_public_attrs(self):
74
+ if not self._check_and_warn():
75
+ return {'valid': False}
76
+ return {
77
+ 'valid': True,
78
+ 'data': sorted([k for k in dir(self.module) if not k.startswith('_')])
79
+ }
80
+
81
+ def get_private_attrs(self):
82
+ if not self._check_and_warn():
83
+ return {'valid': False}
84
+ return {
85
+ 'valid': True,
86
+ 'data': sorted([
87
+ k for k in dir(self.module)
88
+ if k.startswith('_') and not (k.startswith('__') and k.endswith('__'))
89
+ ])
90
+ }
91
+
92
+ def get_dunder_attrs(self):
93
+ if not self._check_and_warn():
94
+ return {'valid': False}
95
+ return {
96
+ 'valid': True,
97
+ 'data': sorted([
98
+ k for k in dir(self.module)
99
+ if k.startswith('__') and k.endswith('__')
100
+ ])
101
+ }
102
+
103
+ def get_callable_attrs(self):
104
+ if not self._check_and_warn():
105
+ return {'valid': False}
106
+ result = []
107
+ for k in self.get_all_attrs()['data']:
108
+ try:
109
+ if callable(getattr(self.module, k)):
110
+ result.append(k)
111
+ except Exception:
112
+ pass
113
+ return {'valid': True, 'data': sorted(result)}
114
+
115
+ def get_non_callable_attrs(self):
116
+ if not self._check_and_warn():
117
+ return {'valid': False}
118
+ result = []
119
+ for k in self.get_all_attrs()['data']:
120
+ try:
121
+ if not callable(getattr(self.module, k)):
122
+ result.append(k)
123
+ except Exception:
124
+ pass
125
+ return {'valid': True, 'data': sorted(result)}
126
+
127
+ def get_attrs_with_values(self):
128
+ if not self._check_and_warn():
129
+ return {'valid': False}
130
+ result = {}
131
+ for k in self.get_all_attrs()['data']:
132
+ try:
133
+ result[k] = getattr(self.module, k)
134
+ except Exception:
135
+ result[k] = 'N/A'
136
+ return {'valid': True, 'data': result}
137
+
138
+ def get_attrs_with_types(self):
139
+ if not self._check_and_warn():
140
+ return {'valid': False}
141
+ result = {}
142
+ for k in self.get_all_attrs()['data']:
143
+ try:
144
+ v = getattr(self.module, k)
145
+ result[k] = type(v).__name__
146
+ except Exception:
147
+ result[k] = 'Unknown'
148
+ return {'valid': True, 'data': result}
149
+
150
+ def get_classes(self):
151
+ if not self._check_and_warn():
152
+ return {'valid': False}
153
+ result = []
154
+ for k in self.get_all_attrs()['data']:
155
+ try:
156
+ v = getattr(self.module, k)
157
+ if isinstance(v, type):
158
+ result.append(k)
159
+ except Exception:
160
+ pass
161
+ return {'valid': True, 'data': sorted(result)}
162
+
163
+ def get_functions(self):
164
+ if not self._check_and_warn():
165
+ return {'valid': False}
166
+ result = []
167
+ for k in self.get_all_attrs()['data']:
168
+ try:
169
+ v = getattr(self.module, k)
170
+ if isinstance(v, types.FunctionType):
171
+ result.append(k)
172
+ except Exception:
173
+ pass
174
+ return {'valid': True, 'data': sorted(result)}
175
+
176
+ def get_builtins(self):
177
+ if not self._check_and_warn():
178
+ return {'valid': False}
179
+ result = []
180
+ for k in self.get_all_attrs()['data']:
181
+ try:
182
+ v = getattr(self.module, k)
183
+ if isinstance(v, types.BuiltinFunctionType):
184
+ result.append(k)
185
+ except Exception:
186
+ pass
187
+ return {'valid': True, 'data': sorted(result)}
188
+
189
+ def get_modules(self):
190
+ if not self._check_and_warn():
191
+ return {'valid': False}
192
+ result = []
193
+ for k in self.get_all_attrs()['data']:
194
+ try:
195
+ v = getattr(self.module, k)
196
+ if isinstance(v, types.ModuleType):
197
+ result.append(k)
198
+ except Exception:
199
+ pass
200
+ return {'valid': True, 'data': sorted(result)}
201
+
202
+ def get_module_info(self):
203
+ if not self._check_and_warn():
204
+ return {'valid': False}
205
+ return {
206
+ 'valid': True,
207
+ 'data': {
208
+ 'name': self.name,
209
+ 'module_name': getattr(self.module, '__name__', None),
210
+ 'file': getattr(self.module, '__file__', None),
211
+ 'doc': getattr(self.module, '__doc__', None),
212
+ 'package': getattr(self.module, '__package__', None),
213
+ 'path': getattr(self.module, '__path__', None),
214
+ 'loader': str(getattr(self.module, '__loader__', None)),
215
+ 'spec': str(getattr(self.module, '__spec__', None)),
216
+ 'cached': getattr(self.module, '__cached__', None),
217
+ }
218
+ }
219
+
220
+ def get_stats(self):
221
+ if not self._check_and_warn():
222
+ return {'valid': False}
223
+ all_data = self.get_all_attrs()['data']
224
+ return {
225
+ 'valid': True,
226
+ 'data': {
227
+ 'total_attrs': len(all_data),
228
+ 'public_count': len(self.get_public_attrs()['data']),
229
+ 'private_count': len(self.get_private_attrs()['data']),
230
+ 'dunder_count': len(self.get_dunder_attrs()['data']),
231
+ 'callable_count': len(self.get_callable_attrs()['data']),
232
+ 'non_callable_count': len(self.get_non_callable_attrs()['data']),
233
+ 'class_count': len(self.get_classes()['data']),
234
+ 'function_count': len(self.get_functions()['data']),
235
+ 'builtin_count': len(self.get_builtins()['data']),
236
+ 'submodule_count': len(self.get_modules()['data']),
237
+ }
238
+ }
239
+
240
+ def get_sys_info(self):
241
+ return {
242
+ 'valid': True,
243
+ 'data': {
244
+ 'python_version': sys.version,
245
+ 'platform': sys.platform,
246
+ 'executable': sys.executable,
247
+ 'argv': sys.argv,
248
+ 'path': sys.path[:10],
249
+ 'modules_loaded': len(sys.modules),
250
+ }
251
+ }
252
+
253
+ def get_file_info(self):
254
+ if not self._check_and_warn():
255
+ return {'valid': False}
256
+ filepath = getattr(self.module, '__file__', None)
257
+ if not filepath:
258
+ return {'valid': True, 'data': {'filepath': None, 'exists': False}}
259
+ return {
260
+ 'valid': True,
261
+ 'data': {
262
+ 'filepath': filepath,
263
+ 'exists': os.path.exists(filepath),
264
+ 'is_file': os.path.isfile(filepath) if os.path.exists(filepath) else False,
265
+ 'size': os.path.getsize(filepath) if os.path.exists(filepath) else None,
266
+ 'dirname': os.path.dirname(filepath) if os.path.exists(filepath) else None,
267
+ 'basename': os.path.basename(filepath) if os.path.exists(filepath) else None,
268
+ }
269
+ }
270
+
271
+ def get_everything(self):
272
+ if not self._check_and_warn():
273
+ return {'valid': False}
274
+ return {
275
+ 'valid': True,
276
+ 'data': {
277
+ 'module_info': self.get_module_info()['data'],
278
+ 'stats': self.get_stats()['data'],
279
+ 'sys_info': self.get_sys_info()['data'],
280
+ 'file_info': self.get_file_info()['data'],
281
+ 'all_attrs': self.get_all_attrs()['data'],
282
+ 'public_attrs': self.get_public_attrs()['data'],
283
+ 'private_attrs': self.get_private_attrs()['data'],
284
+ 'dunder_attrs': self.get_dunder_attrs()['data'],
285
+ 'callable_attrs': self.get_callable_attrs()['data'],
286
+ 'non_callable_attrs': self.get_non_callable_attrs()['data'],
287
+ 'classes': self.get_classes()['data'],
288
+ 'functions': self.get_functions()['data'],
289
+ 'builtins': self.get_builtins()['data'],
290
+ 'submodules': self.get_modules()['data'],
291
+ 'attrs_with_values': self.get_attrs_with_values()['data'],
292
+ 'attrs_with_types': self.get_attrs_with_types()['data'],
293
+ }
294
+ }
295
+ __dir__ = [ModuleExplorer]
296
+ __all__ = [ModuleExplorer]