pyhabitat 1.1.23__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.
- pyhabitat/__init__.py +29 -0
- pyhabitat/__main__.py +6 -0
- pyhabitat/cli.py +140 -0
- pyhabitat/environment.py +1080 -0
- pyhabitat/reporting.py +120 -0
- pyhabitat/system_info.py +131 -0
- pyhabitat/version_info.py +209 -0
- pyhabitat-1.1.23.dist-info/METADATA +226 -0
- pyhabitat-1.1.23.dist-info/RECORD +13 -0
- pyhabitat-1.1.23.dist-info/WHEEL +5 -0
- pyhabitat-1.1.23.dist-info/entry_points.txt +2 -0
- pyhabitat-1.1.23.dist-info/licenses/LICENSE +7 -0
- pyhabitat-1.1.23.dist-info/top_level.txt +1 -0
pyhabitat/__init__.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# src/pyhabitat/__init__.py
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
from .version_info import get_package_version as version
|
|
4
|
+
from .system_info import SystemInfo
|
|
5
|
+
from .reporting import report
|
|
6
|
+
from .environment import *
|
|
7
|
+
"""
|
|
8
|
+
Detect whether Python is running inside WSL, Docker, CI, or mobile environments.
|
|
9
|
+
"""
|
|
10
|
+
"""
|
|
11
|
+
from .platform import *
|
|
12
|
+
from .runtime import *
|
|
13
|
+
from .packaging import *
|
|
14
|
+
|
|
15
|
+
__all__ = []
|
|
16
|
+
for module in (
|
|
17
|
+
globals()['platform'],
|
|
18
|
+
globals()['runtime'],
|
|
19
|
+
globals()['packaging']):
|
|
20
|
+
__all__.extend(module.__all__)
|
|
21
|
+
"""
|
|
22
|
+
# Dynamically re-export everything environment declares in its __all__
|
|
23
|
+
__all__ = [
|
|
24
|
+
'version',
|
|
25
|
+
'SystemInfo',
|
|
26
|
+
'report',
|
|
27
|
+
] + environment.__all__
|
|
28
|
+
|
|
29
|
+
__version__ = version()
|
pyhabitat/__main__.py
ADDED
pyhabitat/cli.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# src/pyhabitat/cli.py
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import argparse
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import pyhabitat
|
|
7
|
+
from pyhabitat.version_info import get_package_version
|
|
8
|
+
from pyhabitat.reporting import report
|
|
9
|
+
|
|
10
|
+
"""
|
|
11
|
+
from . import environment
|
|
12
|
+
from .environment import * # to enable CLI --list
|
|
13
|
+
import pyhabitat # refers to the folder
|
|
14
|
+
"""
|
|
15
|
+
# Instead of wildcarding .environment, we pull the clean API from the package root
|
|
16
|
+
from pyhabitat import (
|
|
17
|
+
environment,
|
|
18
|
+
__all__ as public_api
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def run_cli():
|
|
23
|
+
"""Parse CLI arguments and run the pyhabitat environment report."""
|
|
24
|
+
current_version = get_package_version()
|
|
25
|
+
parser = argparse.ArgumentParser(
|
|
26
|
+
description="PyHabitat: Python environment and build introspection"
|
|
27
|
+
)
|
|
28
|
+
# Add the version argument
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
'-v', '--version',
|
|
31
|
+
action='version',
|
|
32
|
+
version=f'PyHabitat {current_version}'
|
|
33
|
+
)
|
|
34
|
+
# Add the path argument
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"--path",
|
|
37
|
+
type=str,
|
|
38
|
+
default=None,
|
|
39
|
+
help="Path to a script or binary to inspect (defaults to sys.argv[0])",
|
|
40
|
+
)
|
|
41
|
+
# Add the debug argument
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--debug",
|
|
44
|
+
action="store_true",
|
|
45
|
+
help="Enable verbose debug output",
|
|
46
|
+
)
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"--list",
|
|
49
|
+
action="store_true",
|
|
50
|
+
help="List available callable functions in pyhabitat"
|
|
51
|
+
)
|
|
52
|
+
# Add the path argument
|
|
53
|
+
parser.add_argument(
|
|
54
|
+
"--clear-cache",
|
|
55
|
+
action = 'store_true',
|
|
56
|
+
help="Force fresh environment checks with cached results.",
|
|
57
|
+
)
|
|
58
|
+
#parser.add_argument(
|
|
59
|
+
# "--verbose",
|
|
60
|
+
# action="store_true",
|
|
61
|
+
# help="List available callable functions in pyhabitat"
|
|
62
|
+
#)
|
|
63
|
+
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"command",
|
|
66
|
+
nargs="?",
|
|
67
|
+
help="Function name to run (or use --list)",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
args = parser.parse_args()
|
|
72
|
+
|
|
73
|
+
if args.clear_cache:
|
|
74
|
+
environment.clear_all_caches() #
|
|
75
|
+
print("All cached results cleared to allow for fresh checks.")
|
|
76
|
+
return # avoid running the report
|
|
77
|
+
|
|
78
|
+
if args.list:
|
|
79
|
+
# Use the __all__ we imported from .
|
|
80
|
+
for name in public_api:
|
|
81
|
+
func = getattr(pyhabitat, name, None)
|
|
82
|
+
if callable(func):
|
|
83
|
+
print(name)
|
|
84
|
+
if args.debug:
|
|
85
|
+
doc = func.__doc__ or "(no description)"
|
|
86
|
+
print(f" {doc}")
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
"""if args.list:
|
|
90
|
+
for name in pyhabitat.__all__:
|
|
91
|
+
func = getattr(pyhabitat, name, None)
|
|
92
|
+
if callable(func):
|
|
93
|
+
print(name)
|
|
94
|
+
if args.debug:
|
|
95
|
+
doc = func.__doc__ or "(no description)"
|
|
96
|
+
print(f"{name}: {doc}")
|
|
97
|
+
return"""
|
|
98
|
+
'''
|
|
99
|
+
if args.command:
|
|
100
|
+
func = getattr(pyhabitat, args.command, None)
|
|
101
|
+
if callable(func):
|
|
102
|
+
print(func())
|
|
103
|
+
return # Exit after running the subcommand
|
|
104
|
+
else:
|
|
105
|
+
print(f"Unknown function: {args.command}")
|
|
106
|
+
return # Exit after reporting the unknown command
|
|
107
|
+
'''
|
|
108
|
+
"""if args.command:
|
|
109
|
+
func = getattr(pyhabitat, args.command, None)
|
|
110
|
+
if callable(func):
|
|
111
|
+
kwargs = {}
|
|
112
|
+
if args.path:
|
|
113
|
+
kwargs['path'] = Path(args.path)
|
|
114
|
+
if args.debug:
|
|
115
|
+
kwargs['debug'] = args.debug
|
|
116
|
+
print(func(**kwargs))
|
|
117
|
+
return
|
|
118
|
+
else:
|
|
119
|
+
# necessary to avoid printing report if specific function matching the command is not found
|
|
120
|
+
print(f"Function not callable. Check spelling: {args.command}")
|
|
121
|
+
return"""
|
|
122
|
+
|
|
123
|
+
if args.command:
|
|
124
|
+
func = getattr(pyhabitat, args.command, None)
|
|
125
|
+
if callable(func):
|
|
126
|
+
kwargs = {}
|
|
127
|
+
if args.path:
|
|
128
|
+
kwargs['path'] = Path(args.path)
|
|
129
|
+
if args.debug:
|
|
130
|
+
kwargs['debug'] = args.debug
|
|
131
|
+
|
|
132
|
+
# Run the specific requested function
|
|
133
|
+
print(func(**kwargs))
|
|
134
|
+
return
|
|
135
|
+
else:
|
|
136
|
+
print(f"Function not found or not callable: {args.command}")
|
|
137
|
+
return
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
report(path=Path(args.path) if args.path else None, debug=args.debug)
|