get-module-underlying 0.0.1__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.
- get_module_underlying-0.0.1/PKG-INFO +127 -0
- get_module_underlying-0.0.1/README.md +115 -0
- get_module_underlying-0.0.1/_exceptions.py +5 -0
- get_module_underlying-0.0.1/get_module_underlying.egg-info/PKG-INFO +127 -0
- get_module_underlying-0.0.1/get_module_underlying.egg-info/SOURCES.txt +9 -0
- get_module_underlying-0.0.1/get_module_underlying.egg-info/dependency_links.txt +1 -0
- get_module_underlying-0.0.1/get_module_underlying.egg-info/requires.txt +1 -0
- get_module_underlying-0.0.1/get_module_underlying.egg-info/top_level.txt +2 -0
- get_module_underlying-0.0.1/get_module_underlying.py +296 -0
- get_module_underlying-0.0.1/setup.cfg +4 -0
- get_module_underlying-0.0.1/setup.py +16 -0
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
Description: # get_module_underlying
|
|
10
|
+
|
|
11
|
+
Explore Python modules deeper than `dir()`.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install get_module_underlying
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from get_module_underlying import ModuleExplorer
|
|
23
|
+
|
|
24
|
+
# Explore a module
|
|
25
|
+
explorer = ModuleExplorer('sys')
|
|
26
|
+
|
|
27
|
+
# Get all attributes (excluding __xxx__)
|
|
28
|
+
print(explorer.get_all_attrs())
|
|
29
|
+
|
|
30
|
+
# Get only public attributes
|
|
31
|
+
print(explorer.get_public_attrs())
|
|
32
|
+
|
|
33
|
+
# Get private attributes (single underscore)
|
|
34
|
+
print(explorer.get_private_attrs())
|
|
35
|
+
|
|
36
|
+
# Get dunder attributes (__xxx__)
|
|
37
|
+
print(explorer.get_dunder_attrs())
|
|
38
|
+
|
|
39
|
+
# Get callable methods/functions
|
|
40
|
+
print(explorer.get_callable_attrs())
|
|
41
|
+
|
|
42
|
+
# Get non-callable attributes (variables, constants)
|
|
43
|
+
print(explorer.get_non_callable_attrs())
|
|
44
|
+
|
|
45
|
+
# Get attributes with their values
|
|
46
|
+
print(explorer.get_attrs_with_values())
|
|
47
|
+
|
|
48
|
+
# Get attributes with their types
|
|
49
|
+
print(explorer.get_attrs_with_types())
|
|
50
|
+
|
|
51
|
+
# Get all classes
|
|
52
|
+
print(explorer.get_classes())
|
|
53
|
+
|
|
54
|
+
# Get all functions
|
|
55
|
+
print(explorer.get_functions())
|
|
56
|
+
|
|
57
|
+
# Get all builtins
|
|
58
|
+
print(explorer.get_builtins())
|
|
59
|
+
|
|
60
|
+
# Get all submodules
|
|
61
|
+
print(explorer.get_modules())
|
|
62
|
+
|
|
63
|
+
# Get detailed module info
|
|
64
|
+
print(explorer.get_module_info())
|
|
65
|
+
|
|
66
|
+
# Get statistics summary
|
|
67
|
+
print(explorer.get_stats())
|
|
68
|
+
|
|
69
|
+
# Get Python system info
|
|
70
|
+
print(explorer.get_sys_info())
|
|
71
|
+
|
|
72
|
+
# Get module file info
|
|
73
|
+
print(explorer.get_file_info())
|
|
74
|
+
|
|
75
|
+
# Get everything at once
|
|
76
|
+
print(explorer.get_everything())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Methods Reference
|
|
80
|
+
|
|
81
|
+
| Method | Return Type | Description |
|
|
82
|
+
|--------|-------------|-------------|
|
|
83
|
+
| `get_all_attrs()` | `{'valid': bool, 'data': list}` | All attributes except dunder (`__xxx__`) |
|
|
84
|
+
| `get_public_attrs()` | `{'valid': bool, 'data': list}` | Attributes not starting with `_` |
|
|
85
|
+
| `get_private_attrs()` | `{'valid': bool, 'data': list}` | Attributes with single `_` prefix |
|
|
86
|
+
| `get_dunder_attrs()` | `{'valid': bool, 'data': list}` | Dunder attributes (`__xxx__`) |
|
|
87
|
+
| `get_callable_attrs()` | `{'valid': bool, 'data': list}` | Callable functions/methods |
|
|
88
|
+
| `get_non_callable_attrs()` | `{'valid': bool, 'data': list}` | Non-callable variables/constants |
|
|
89
|
+
| `get_attrs_with_values()` | `{'valid': bool, 'data': dict}` | Attribute names with their values |
|
|
90
|
+
| `get_attrs_with_types()` | `{'valid': bool, 'data': dict}` | Attribute names with their types |
|
|
91
|
+
| `get_classes()` | `{'valid': bool, 'data': list}` | All classes in the module |
|
|
92
|
+
| `get_functions()` | `{'valid': bool, 'data': list}` | All functions in the module |
|
|
93
|
+
| `get_builtins()` | `{'valid': bool, 'data': list}` | All built-in functions |
|
|
94
|
+
| `get_modules()` | `{'valid': bool, 'data': list}` | All submodules imported |
|
|
95
|
+
| `get_module_info()` | `{'valid': bool, 'data': dict}` | Module metadata (name, file, doc, etc.) |
|
|
96
|
+
| `get_stats()` | `{'valid': bool, 'data': dict}` | Statistical summary of all attributes |
|
|
97
|
+
| `get_sys_info()` | `{'valid': bool, 'data': dict}` | Python system information |
|
|
98
|
+
| `get_file_info()` | `{'valid': bool, 'data': dict}` | Module source file information |
|
|
99
|
+
| `get_everything()` | `{'valid': bool, 'data': dict}` | All information combined |
|
|
100
|
+
|
|
101
|
+
## Return Format
|
|
102
|
+
|
|
103
|
+
All methods return a dictionary with the following structure:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
{
|
|
107
|
+
'valid': True, # bool: True if module is valid, False otherwise
|
|
108
|
+
'data': ... # The actual data (list or dict)
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
If the module is not valid, the method will:
|
|
113
|
+
- Emit a `ValidNotTrueWarning` warning
|
|
114
|
+
- Return `{'valid': False}`
|
|
115
|
+
|
|
116
|
+
## Dependencies
|
|
117
|
+
|
|
118
|
+
- Python 3.6+
|
|
119
|
+
- `absence` library (automatically installed)
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT
|
|
124
|
+
Platform: UNKNOWN
|
|
125
|
+
Classifier: Programming Language :: Python :: 3
|
|
126
|
+
Requires-Python: >=3.6
|
|
127
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# get_module_underlying
|
|
2
|
+
|
|
3
|
+
Explore Python modules deeper than `dir()`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install get_module_underlying
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from get_module_underlying import ModuleExplorer
|
|
15
|
+
|
|
16
|
+
# Explore a module
|
|
17
|
+
explorer = ModuleExplorer('sys')
|
|
18
|
+
|
|
19
|
+
# Get all attributes (excluding __xxx__)
|
|
20
|
+
print(explorer.get_all_attrs())
|
|
21
|
+
|
|
22
|
+
# Get only public attributes
|
|
23
|
+
print(explorer.get_public_attrs())
|
|
24
|
+
|
|
25
|
+
# Get private attributes (single underscore)
|
|
26
|
+
print(explorer.get_private_attrs())
|
|
27
|
+
|
|
28
|
+
# Get dunder attributes (__xxx__)
|
|
29
|
+
print(explorer.get_dunder_attrs())
|
|
30
|
+
|
|
31
|
+
# Get callable methods/functions
|
|
32
|
+
print(explorer.get_callable_attrs())
|
|
33
|
+
|
|
34
|
+
# Get non-callable attributes (variables, constants)
|
|
35
|
+
print(explorer.get_non_callable_attrs())
|
|
36
|
+
|
|
37
|
+
# Get attributes with their values
|
|
38
|
+
print(explorer.get_attrs_with_values())
|
|
39
|
+
|
|
40
|
+
# Get attributes with their types
|
|
41
|
+
print(explorer.get_attrs_with_types())
|
|
42
|
+
|
|
43
|
+
# Get all classes
|
|
44
|
+
print(explorer.get_classes())
|
|
45
|
+
|
|
46
|
+
# Get all functions
|
|
47
|
+
print(explorer.get_functions())
|
|
48
|
+
|
|
49
|
+
# Get all builtins
|
|
50
|
+
print(explorer.get_builtins())
|
|
51
|
+
|
|
52
|
+
# Get all submodules
|
|
53
|
+
print(explorer.get_modules())
|
|
54
|
+
|
|
55
|
+
# Get detailed module info
|
|
56
|
+
print(explorer.get_module_info())
|
|
57
|
+
|
|
58
|
+
# Get statistics summary
|
|
59
|
+
print(explorer.get_stats())
|
|
60
|
+
|
|
61
|
+
# Get Python system info
|
|
62
|
+
print(explorer.get_sys_info())
|
|
63
|
+
|
|
64
|
+
# Get module file info
|
|
65
|
+
print(explorer.get_file_info())
|
|
66
|
+
|
|
67
|
+
# Get everything at once
|
|
68
|
+
print(explorer.get_everything())
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Methods Reference
|
|
72
|
+
|
|
73
|
+
| Method | Return Type | Description |
|
|
74
|
+
|--------|-------------|-------------|
|
|
75
|
+
| `get_all_attrs()` | `{'valid': bool, 'data': list}` | All attributes except dunder (`__xxx__`) |
|
|
76
|
+
| `get_public_attrs()` | `{'valid': bool, 'data': list}` | Attributes not starting with `_` |
|
|
77
|
+
| `get_private_attrs()` | `{'valid': bool, 'data': list}` | Attributes with single `_` prefix |
|
|
78
|
+
| `get_dunder_attrs()` | `{'valid': bool, 'data': list}` | Dunder attributes (`__xxx__`) |
|
|
79
|
+
| `get_callable_attrs()` | `{'valid': bool, 'data': list}` | Callable functions/methods |
|
|
80
|
+
| `get_non_callable_attrs()` | `{'valid': bool, 'data': list}` | Non-callable variables/constants |
|
|
81
|
+
| `get_attrs_with_values()` | `{'valid': bool, 'data': dict}` | Attribute names with their values |
|
|
82
|
+
| `get_attrs_with_types()` | `{'valid': bool, 'data': dict}` | Attribute names with their types |
|
|
83
|
+
| `get_classes()` | `{'valid': bool, 'data': list}` | All classes in the module |
|
|
84
|
+
| `get_functions()` | `{'valid': bool, 'data': list}` | All functions in the module |
|
|
85
|
+
| `get_builtins()` | `{'valid': bool, 'data': list}` | All built-in functions |
|
|
86
|
+
| `get_modules()` | `{'valid': bool, 'data': list}` | All submodules imported |
|
|
87
|
+
| `get_module_info()` | `{'valid': bool, 'data': dict}` | Module metadata (name, file, doc, etc.) |
|
|
88
|
+
| `get_stats()` | `{'valid': bool, 'data': dict}` | Statistical summary of all attributes |
|
|
89
|
+
| `get_sys_info()` | `{'valid': bool, 'data': dict}` | Python system information |
|
|
90
|
+
| `get_file_info()` | `{'valid': bool, 'data': dict}` | Module source file information |
|
|
91
|
+
| `get_everything()` | `{'valid': bool, 'data': dict}` | All information combined |
|
|
92
|
+
|
|
93
|
+
## Return Format
|
|
94
|
+
|
|
95
|
+
All methods return a dictionary with the following structure:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
{
|
|
99
|
+
'valid': True, # bool: True if module is valid, False otherwise
|
|
100
|
+
'data': ... # The actual data (list or dict)
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
If the module is not valid, the method will:
|
|
105
|
+
- Emit a `ValidNotTrueWarning` warning
|
|
106
|
+
- Return `{'valid': False}`
|
|
107
|
+
|
|
108
|
+
## Dependencies
|
|
109
|
+
|
|
110
|
+
- Python 3.6+
|
|
111
|
+
- `absence` library (automatically installed)
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
MIT
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
Description: # get_module_underlying
|
|
10
|
+
|
|
11
|
+
Explore Python modules deeper than `dir()`.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install get_module_underlying
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from get_module_underlying import ModuleExplorer
|
|
23
|
+
|
|
24
|
+
# Explore a module
|
|
25
|
+
explorer = ModuleExplorer('sys')
|
|
26
|
+
|
|
27
|
+
# Get all attributes (excluding __xxx__)
|
|
28
|
+
print(explorer.get_all_attrs())
|
|
29
|
+
|
|
30
|
+
# Get only public attributes
|
|
31
|
+
print(explorer.get_public_attrs())
|
|
32
|
+
|
|
33
|
+
# Get private attributes (single underscore)
|
|
34
|
+
print(explorer.get_private_attrs())
|
|
35
|
+
|
|
36
|
+
# Get dunder attributes (__xxx__)
|
|
37
|
+
print(explorer.get_dunder_attrs())
|
|
38
|
+
|
|
39
|
+
# Get callable methods/functions
|
|
40
|
+
print(explorer.get_callable_attrs())
|
|
41
|
+
|
|
42
|
+
# Get non-callable attributes (variables, constants)
|
|
43
|
+
print(explorer.get_non_callable_attrs())
|
|
44
|
+
|
|
45
|
+
# Get attributes with their values
|
|
46
|
+
print(explorer.get_attrs_with_values())
|
|
47
|
+
|
|
48
|
+
# Get attributes with their types
|
|
49
|
+
print(explorer.get_attrs_with_types())
|
|
50
|
+
|
|
51
|
+
# Get all classes
|
|
52
|
+
print(explorer.get_classes())
|
|
53
|
+
|
|
54
|
+
# Get all functions
|
|
55
|
+
print(explorer.get_functions())
|
|
56
|
+
|
|
57
|
+
# Get all builtins
|
|
58
|
+
print(explorer.get_builtins())
|
|
59
|
+
|
|
60
|
+
# Get all submodules
|
|
61
|
+
print(explorer.get_modules())
|
|
62
|
+
|
|
63
|
+
# Get detailed module info
|
|
64
|
+
print(explorer.get_module_info())
|
|
65
|
+
|
|
66
|
+
# Get statistics summary
|
|
67
|
+
print(explorer.get_stats())
|
|
68
|
+
|
|
69
|
+
# Get Python system info
|
|
70
|
+
print(explorer.get_sys_info())
|
|
71
|
+
|
|
72
|
+
# Get module file info
|
|
73
|
+
print(explorer.get_file_info())
|
|
74
|
+
|
|
75
|
+
# Get everything at once
|
|
76
|
+
print(explorer.get_everything())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Methods Reference
|
|
80
|
+
|
|
81
|
+
| Method | Return Type | Description |
|
|
82
|
+
|--------|-------------|-------------|
|
|
83
|
+
| `get_all_attrs()` | `{'valid': bool, 'data': list}` | All attributes except dunder (`__xxx__`) |
|
|
84
|
+
| `get_public_attrs()` | `{'valid': bool, 'data': list}` | Attributes not starting with `_` |
|
|
85
|
+
| `get_private_attrs()` | `{'valid': bool, 'data': list}` | Attributes with single `_` prefix |
|
|
86
|
+
| `get_dunder_attrs()` | `{'valid': bool, 'data': list}` | Dunder attributes (`__xxx__`) |
|
|
87
|
+
| `get_callable_attrs()` | `{'valid': bool, 'data': list}` | Callable functions/methods |
|
|
88
|
+
| `get_non_callable_attrs()` | `{'valid': bool, 'data': list}` | Non-callable variables/constants |
|
|
89
|
+
| `get_attrs_with_values()` | `{'valid': bool, 'data': dict}` | Attribute names with their values |
|
|
90
|
+
| `get_attrs_with_types()` | `{'valid': bool, 'data': dict}` | Attribute names with their types |
|
|
91
|
+
| `get_classes()` | `{'valid': bool, 'data': list}` | All classes in the module |
|
|
92
|
+
| `get_functions()` | `{'valid': bool, 'data': list}` | All functions in the module |
|
|
93
|
+
| `get_builtins()` | `{'valid': bool, 'data': list}` | All built-in functions |
|
|
94
|
+
| `get_modules()` | `{'valid': bool, 'data': list}` | All submodules imported |
|
|
95
|
+
| `get_module_info()` | `{'valid': bool, 'data': dict}` | Module metadata (name, file, doc, etc.) |
|
|
96
|
+
| `get_stats()` | `{'valid': bool, 'data': dict}` | Statistical summary of all attributes |
|
|
97
|
+
| `get_sys_info()` | `{'valid': bool, 'data': dict}` | Python system information |
|
|
98
|
+
| `get_file_info()` | `{'valid': bool, 'data': dict}` | Module source file information |
|
|
99
|
+
| `get_everything()` | `{'valid': bool, 'data': dict}` | All information combined |
|
|
100
|
+
|
|
101
|
+
## Return Format
|
|
102
|
+
|
|
103
|
+
All methods return a dictionary with the following structure:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
{
|
|
107
|
+
'valid': True, # bool: True if module is valid, False otherwise
|
|
108
|
+
'data': ... # The actual data (list or dict)
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
If the module is not valid, the method will:
|
|
113
|
+
- Emit a `ValidNotTrueWarning` warning
|
|
114
|
+
- Return `{'valid': False}`
|
|
115
|
+
|
|
116
|
+
## Dependencies
|
|
117
|
+
|
|
118
|
+
- Python 3.6+
|
|
119
|
+
- `absence` library (automatically installed)
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT
|
|
124
|
+
Platform: UNKNOWN
|
|
125
|
+
Classifier: Programming Language :: Python :: 3
|
|
126
|
+
Requires-Python: >=3.6
|
|
127
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
_exceptions.py
|
|
3
|
+
get_module_underlying.py
|
|
4
|
+
setup.py
|
|
5
|
+
get_module_underlying.egg-info/PKG-INFO
|
|
6
|
+
get_module_underlying.egg-info/SOURCES.txt
|
|
7
|
+
get_module_underlying.egg-info/dependency_links.txt
|
|
8
|
+
get_module_underlying.egg-info/requires.txt
|
|
9
|
+
get_module_underlying.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
absence
|
|
@@ -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]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='get_module_underlying',
|
|
5
|
+
version='0.0.1',
|
|
6
|
+
description='Explore Python modules deeper than dir()',
|
|
7
|
+
long_description=open('README.md').read(),
|
|
8
|
+
long_description_content_type='text/markdown',
|
|
9
|
+
author='San Zhang',
|
|
10
|
+
author_email='san.zhang@example.com',
|
|
11
|
+
py_modules=['_exceptions', 'get_module_underlying'],
|
|
12
|
+
license='MIT',
|
|
13
|
+
classifiers=['Programming Language :: Python :: 3'],
|
|
14
|
+
python_requires='>=3.6',
|
|
15
|
+
install_requires=['absence'],
|
|
16
|
+
)
|