crossportability 0.1.0__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.
- crossportability-0.1.0/LICENSE +21 -0
- crossportability-0.1.0/PKG-INFO +48 -0
- crossportability-0.1.0/README.md +29 -0
- crossportability-0.1.0/crossportability/__init__.py +4 -0
- crossportability-0.1.0/crossportability/detect.py +233 -0
- crossportability-0.1.0/crossportability/report.py +190 -0
- crossportability-0.1.0/crossportability.egg-info/PKG-INFO +48 -0
- crossportability-0.1.0/crossportability.egg-info/SOURCES.txt +10 -0
- crossportability-0.1.0/crossportability.egg-info/dependency_links.txt +1 -0
- crossportability-0.1.0/crossportability.egg-info/top_level.txt +1 -0
- crossportability-0.1.0/pyproject.toml +26 -0
- crossportability-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Neel Patel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: crossportability
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Detect potential portability issues in Python projects.
|
|
5
|
+
Author: Neel Patel
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/neelpatel-png/crossportability
|
|
8
|
+
Project-URL: Repository, https://github.com/neelpatel-png/crossportability
|
|
9
|
+
Project-URL: Issues, https://github.com/neelpatel-png/crossportability/issues
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: Topic :: Software Development :: Testing
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# CrossPortability
|
|
21
|
+
A Python library for detecting potential operating-system and environment portability issues in Python projects.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
- Detect Platform-Specific Imports
|
|
25
|
+
- Detect OS-Specific Paths
|
|
26
|
+
- Detect Platform Usage
|
|
27
|
+
- Detect System Commands
|
|
28
|
+
- Detect Platform-Specific Environment Variables
|
|
29
|
+
- Analyze Individual Python Files
|
|
30
|
+
- Recursively Analyze Python Projects
|
|
31
|
+
- Generate Structured Detection Results
|
|
32
|
+
- Generate Human-Readable Reports
|
|
33
|
+
|
|
34
|
+
## Concepts Used
|
|
35
|
+
- Abstract Syntax Tree (AST)
|
|
36
|
+
- Static Code Analysis
|
|
37
|
+
- pathlib
|
|
38
|
+
- File Handling
|
|
39
|
+
- Dictionaries
|
|
40
|
+
- Lists
|
|
41
|
+
- Functions
|
|
42
|
+
- Exception Handling
|
|
43
|
+
- Type Hints
|
|
44
|
+
- Docstrings
|
|
45
|
+
- Python Packages
|
|
46
|
+
|
|
47
|
+
## Author
|
|
48
|
+
- Patel Neel
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# CrossPortability
|
|
2
|
+
A Python library for detecting potential operating-system and environment portability issues in Python projects.
|
|
3
|
+
|
|
4
|
+
## Features
|
|
5
|
+
- Detect Platform-Specific Imports
|
|
6
|
+
- Detect OS-Specific Paths
|
|
7
|
+
- Detect Platform Usage
|
|
8
|
+
- Detect System Commands
|
|
9
|
+
- Detect Platform-Specific Environment Variables
|
|
10
|
+
- Analyze Individual Python Files
|
|
11
|
+
- Recursively Analyze Python Projects
|
|
12
|
+
- Generate Structured Detection Results
|
|
13
|
+
- Generate Human-Readable Reports
|
|
14
|
+
|
|
15
|
+
## Concepts Used
|
|
16
|
+
- Abstract Syntax Tree (AST)
|
|
17
|
+
- Static Code Analysis
|
|
18
|
+
- pathlib
|
|
19
|
+
- File Handling
|
|
20
|
+
- Dictionaries
|
|
21
|
+
- Lists
|
|
22
|
+
- Functions
|
|
23
|
+
- Exception Handling
|
|
24
|
+
- Type Hints
|
|
25
|
+
- Docstrings
|
|
26
|
+
- Python Packages
|
|
27
|
+
|
|
28
|
+
## Author
|
|
29
|
+
- Patel Neel
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import ast
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def _validate_path(path: str | Path) -> Path:
|
|
6
|
+
"""
|
|
7
|
+
Validate that the supplied path exists.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
path: A file or directory path.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
A Path object representing the supplied path.
|
|
14
|
+
|
|
15
|
+
Raises:
|
|
16
|
+
ValueError: If the path does not exist.
|
|
17
|
+
"""
|
|
18
|
+
path = Path(path)
|
|
19
|
+
if not path.exists():
|
|
20
|
+
raise ValueError("Path does not exist")
|
|
21
|
+
return path
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _get_python_files(path: str | Path) -> list[Path]:
|
|
25
|
+
"""
|
|
26
|
+
Find Python files from a file or directory path.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
path: A Python file or directory to scan.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
A list of Python file paths.
|
|
33
|
+
|
|
34
|
+
Raises:
|
|
35
|
+
ValueError: If the path is invalid or is not a Python file.
|
|
36
|
+
"""
|
|
37
|
+
path = _validate_path(path)
|
|
38
|
+
if path.is_file():
|
|
39
|
+
if path.suffix == ".py":
|
|
40
|
+
return [path]
|
|
41
|
+
raise ValueError("File is not a Python file")
|
|
42
|
+
if path.is_dir():
|
|
43
|
+
return list(path.rglob("*.py"))
|
|
44
|
+
raise ValueError("Invalid path")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def imports(path: str | Path) -> dict[str, list[tuple[str, str]]]:
|
|
48
|
+
"""
|
|
49
|
+
Detect OS-specific Python imports.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
path: A Python file or directory to scan.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
A dictionary mapping file paths to detected imports.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If the supplied path does not exist or is invalid.
|
|
59
|
+
"""
|
|
60
|
+
files = _get_python_files(path)
|
|
61
|
+
results = {}
|
|
62
|
+
for file in files:
|
|
63
|
+
code = file.read_text()
|
|
64
|
+
tree = ast.parse(code)
|
|
65
|
+
findings = []
|
|
66
|
+
for node in ast.walk(tree):
|
|
67
|
+
if isinstance(node, ast.Import):
|
|
68
|
+
for alias in node.names:
|
|
69
|
+
module = alias.name
|
|
70
|
+
if module in ["winsound", "winreg", "msvcrt"]:
|
|
71
|
+
findings.append(("Windows", module))
|
|
72
|
+
elif module in ["pwd", "grp", "termios", "fcntl"]:
|
|
73
|
+
findings.append(("Unix", module))
|
|
74
|
+
elif isinstance(node, ast.ImportFrom):
|
|
75
|
+
module = node.module
|
|
76
|
+
if module in ["winsound", "winreg", "msvcrt"]:
|
|
77
|
+
findings.append(("Windows", module))
|
|
78
|
+
elif module in ["pwd", "grp", "termios", "fcntl"]:
|
|
79
|
+
findings.append(("Unix", module))
|
|
80
|
+
results[str(file)] = findings
|
|
81
|
+
return results
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def ospath(path: str | Path) -> dict[str, list[tuple[str, str]]]:
|
|
85
|
+
"""
|
|
86
|
+
Detect hard-coded operating-system-specific paths.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
path: A Python file or directory to scan.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
A dictionary mapping file paths to detected
|
|
93
|
+
Windows- or Unix-style paths.
|
|
94
|
+
|
|
95
|
+
Raises:
|
|
96
|
+
ValueError: If the supplied path does not exist or is invalid.
|
|
97
|
+
"""
|
|
98
|
+
files = _get_python_files(path)
|
|
99
|
+
results = {}
|
|
100
|
+
for file in files:
|
|
101
|
+
code = file.read_text()
|
|
102
|
+
tree = ast.parse(code)
|
|
103
|
+
findings = []
|
|
104
|
+
for node in ast.walk(tree):
|
|
105
|
+
if isinstance(node, ast.Constant):
|
|
106
|
+
if isinstance(node.value, str):
|
|
107
|
+
if ":" in node.value and "\\" in node.value:
|
|
108
|
+
findings.append(("Windows", node.value))
|
|
109
|
+
elif node.value.startswith("/"):
|
|
110
|
+
findings.append(("Unix", node.value))
|
|
111
|
+
results[str(file)] = findings
|
|
112
|
+
return results
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def platform_usage(path: str | Path) -> dict[str, list[str]]:
|
|
116
|
+
"""
|
|
117
|
+
Detect platform-specific checks using os.name or sys.platform.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
path: A Python file or directory to scan.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
A dictionary mapping file paths to detected platform checks.
|
|
124
|
+
|
|
125
|
+
Raises:
|
|
126
|
+
ValueError: If the supplied path does not exist or is invalid.
|
|
127
|
+
"""
|
|
128
|
+
files = _get_python_files(path)
|
|
129
|
+
results = {}
|
|
130
|
+
for file in files:
|
|
131
|
+
code = file.read_text()
|
|
132
|
+
tree = ast.parse(code)
|
|
133
|
+
findings = []
|
|
134
|
+
for node in ast.walk(tree):
|
|
135
|
+
if isinstance(node, ast.Attribute):
|
|
136
|
+
if isinstance(node.value, ast.Name):
|
|
137
|
+
if node.value.id == "os" and node.attr == "name":
|
|
138
|
+
findings.append("os.name")
|
|
139
|
+
elif node.value.id == "sys" and node.attr == "platform":
|
|
140
|
+
findings.append("sys.platform")
|
|
141
|
+
results[str(file)] = findings
|
|
142
|
+
return results
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def commands(path: str | Path) -> dict[str, list[str]]:
|
|
146
|
+
"""
|
|
147
|
+
Detect potentially platform-dependent system commands.
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
path: A Python file or directory to scan.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
A dictionary mapping file paths to detected system commands.
|
|
154
|
+
|
|
155
|
+
Raises:
|
|
156
|
+
ValueError: If the supplied path does not exist or is invalid.
|
|
157
|
+
"""
|
|
158
|
+
files = _get_python_files(path)
|
|
159
|
+
results = {}
|
|
160
|
+
for file in files:
|
|
161
|
+
code = file.read_text()
|
|
162
|
+
tree = ast.parse(code)
|
|
163
|
+
findings = []
|
|
164
|
+
for node in ast.walk(tree):
|
|
165
|
+
if isinstance(node, ast.Call):
|
|
166
|
+
if isinstance(node.func, ast.Attribute):
|
|
167
|
+
if isinstance(node.func.value, ast.Name):
|
|
168
|
+
if node.func.value.id == "os" and node.func.attr == "system":
|
|
169
|
+
findings.append("os.system")
|
|
170
|
+
elif node.func.value.id == "subprocess" and node.func.attr == "run":
|
|
171
|
+
findings.append("subprocess.run")
|
|
172
|
+
results[str(file)] = findings
|
|
173
|
+
return results
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def environment(path: str | Path) -> dict[str, list[tuple[str, str]]]:
|
|
177
|
+
"""
|
|
178
|
+
Detect platform-specific environment variables.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
path: A Python file or directory to scan.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
A dictionary mapping file paths to detected
|
|
185
|
+
Unix- or Windows-specific environment variables.
|
|
186
|
+
|
|
187
|
+
Raises:
|
|
188
|
+
ValueError: If the supplied path does not exist or is invalid.
|
|
189
|
+
"""
|
|
190
|
+
files = _get_python_files(path)
|
|
191
|
+
results = {}
|
|
192
|
+
windows_variables = ["USERPROFILE", "APPDATA", "PROGRAMFILES"]
|
|
193
|
+
unix_variables = ["HOME", "PATH", "SHELL"]
|
|
194
|
+
for file in files:
|
|
195
|
+
code = file.read_text()
|
|
196
|
+
tree = ast.parse(code)
|
|
197
|
+
findings = []
|
|
198
|
+
for node in ast.walk(tree):
|
|
199
|
+
if isinstance(node, ast.Subscript):
|
|
200
|
+
if isinstance(node.value, ast.Attribute):
|
|
201
|
+
if isinstance(node.value.value, ast.Name):
|
|
202
|
+
if node.value.value.id == "os" and node.value.attr == "environ":
|
|
203
|
+
if isinstance(node.slice, ast.Constant):
|
|
204
|
+
if isinstance(node.slice.value, str):
|
|
205
|
+
if node.slice.value in unix_variables:
|
|
206
|
+
findings.append(("Unix", node.slice.value))
|
|
207
|
+
elif node.slice.value in windows_variables:
|
|
208
|
+
findings.append(("Windows", node.slice.value))
|
|
209
|
+
results[str(file)] = findings
|
|
210
|
+
return results
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def scan(path: str | Path) -> dict:
|
|
214
|
+
"""
|
|
215
|
+
Run all portability detection checks on a Python file or directory.
|
|
216
|
+
|
|
217
|
+
Args:
|
|
218
|
+
path: A Python file or directory to scan.
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
A dictionary containing the results from all detection categories.
|
|
222
|
+
|
|
223
|
+
Raises:
|
|
224
|
+
ValueError: If the supplied path does not exist or is invalid.
|
|
225
|
+
"""
|
|
226
|
+
return {
|
|
227
|
+
"os_paths": ospath(path),
|
|
228
|
+
"platform_usage": platform_usage(path),
|
|
229
|
+
"system_commands": commands(path),
|
|
230
|
+
"imports": imports(path),
|
|
231
|
+
"environment_variables": environment(path)
|
|
232
|
+
}
|
|
233
|
+
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
from . import detect
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def imports(path: str) -> str:
|
|
5
|
+
"""
|
|
6
|
+
Generate a text report of platform-specific imports.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
path: A Python file or directory to scan.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
A formatted string containing the detected imports.
|
|
13
|
+
|
|
14
|
+
Raises:
|
|
15
|
+
ValueError: If the path does not exist or is invalid.
|
|
16
|
+
"""
|
|
17
|
+
results = detect.imports(path)
|
|
18
|
+
report = []
|
|
19
|
+
for file, findings in results.items():
|
|
20
|
+
report.append(f"FILE: {file}")
|
|
21
|
+
if findings:
|
|
22
|
+
for finding in findings:
|
|
23
|
+
report.append(f" {finding[0]} → {finding[1]}")
|
|
24
|
+
else:
|
|
25
|
+
report.append(" No findings")
|
|
26
|
+
report.append("")
|
|
27
|
+
return "\n".join(report)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def ospath(path: str) -> str:
|
|
31
|
+
"""
|
|
32
|
+
Generate a report of operating-system-specific paths.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
path: A Python file or directory to scan.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
A formatted string containing the detected OS-specific paths.
|
|
39
|
+
|
|
40
|
+
Raises:
|
|
41
|
+
ValueError: If the path does not exist or is invalid.
|
|
42
|
+
"""
|
|
43
|
+
results = detect.ospath(path)
|
|
44
|
+
report = []
|
|
45
|
+
for file, findings in results.items():
|
|
46
|
+
report.append(f"FILE: {file}")
|
|
47
|
+
if findings:
|
|
48
|
+
for finding in findings:
|
|
49
|
+
report.append(f" {finding[0]} → {finding[1]}")
|
|
50
|
+
else:
|
|
51
|
+
report.append(" No findings")
|
|
52
|
+
report.append("")
|
|
53
|
+
return "\n".join(report)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def platform_usage(path: str) -> str:
|
|
57
|
+
"""
|
|
58
|
+
Generate a report of platform-specific checks in Python code.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
path: A Python file or directory to scan.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
A formatted string containing detected uses of os.name
|
|
65
|
+
and sys.platform.
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
ValueError: If the path does not exist or is invalid.
|
|
69
|
+
"""
|
|
70
|
+
results = detect.platform_usage(path)
|
|
71
|
+
report = []
|
|
72
|
+
for file, findings in results.items():
|
|
73
|
+
report.append(f"FILE: {file}")
|
|
74
|
+
if findings:
|
|
75
|
+
for finding in findings:
|
|
76
|
+
report.append(f" {finding}")
|
|
77
|
+
else:
|
|
78
|
+
report.append(" No findings")
|
|
79
|
+
report.append("")
|
|
80
|
+
return "\n".join(report)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def commands(path: str) -> str:
|
|
84
|
+
"""
|
|
85
|
+
Generate a report of potentially platform-dependent system commands.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
path: A Python file or directory to scan.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
A formatted string containing detected uses of os.system
|
|
92
|
+
and subprocess.run.
|
|
93
|
+
|
|
94
|
+
Raises:
|
|
95
|
+
ValueError: If the path does not exist or is invalid.
|
|
96
|
+
"""
|
|
97
|
+
results = detect.commands(path)
|
|
98
|
+
report = []
|
|
99
|
+
for file, findings in results.items():
|
|
100
|
+
report.append(f"FILE: {file}")
|
|
101
|
+
if findings:
|
|
102
|
+
for finding in findings:
|
|
103
|
+
report.append(f" {finding}")
|
|
104
|
+
else:
|
|
105
|
+
report.append(" No findings")
|
|
106
|
+
report.append("")
|
|
107
|
+
return "\n".join(report)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def environment(path: str) -> str:
|
|
111
|
+
"""
|
|
112
|
+
Generate a report of platform-specific environment variables.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
path: A Python file or directory to scan.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
A formatted string containing the detected environment variables.
|
|
119
|
+
|
|
120
|
+
Raises:
|
|
121
|
+
ValueError: If the path does not exist or is invalid.
|
|
122
|
+
"""
|
|
123
|
+
results = detect.environment(path)
|
|
124
|
+
report = []
|
|
125
|
+
for file, findings in results.items():
|
|
126
|
+
report.append(f"FILE: {file}")
|
|
127
|
+
if findings:
|
|
128
|
+
for finding in findings:
|
|
129
|
+
report.append(f" {finding[0]} → {finding[1]}")
|
|
130
|
+
else:
|
|
131
|
+
report.append(" No findings")
|
|
132
|
+
report.append("")
|
|
133
|
+
return "\n".join(report)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def scan(path: str) -> str:
|
|
137
|
+
"""
|
|
138
|
+
Generate a complete portability report.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
path: A Python file or directory to scan.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
A formatted string containing all portability detection results.
|
|
145
|
+
|
|
146
|
+
Raises:
|
|
147
|
+
ValueError: If the path does not exist or is invalid.
|
|
148
|
+
"""
|
|
149
|
+
sections = []
|
|
150
|
+
sections.append("OS-SPECIFIC PATHS")
|
|
151
|
+
sections.append(ospath(path))
|
|
152
|
+
sections.append("PLATFORM DETECTION")
|
|
153
|
+
sections.append(platform_usage(path))
|
|
154
|
+
sections.append("SYSTEM COMMANDS")
|
|
155
|
+
sections.append(commands(path))
|
|
156
|
+
sections.append("PLATFORM-SPECIFIC IMPORTS")
|
|
157
|
+
sections.append(imports(path))
|
|
158
|
+
sections.append("ENVIRONMENT VARIABLES")
|
|
159
|
+
sections.append(environment(path))
|
|
160
|
+
return "\n\n".join(sections)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def files(path: str) -> str:
|
|
164
|
+
"""
|
|
165
|
+
Generate a formatted table of Python files found at the given path.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
path: A Python file or directory to scan.
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
A formatted string containing the discovered Python files.
|
|
172
|
+
|
|
173
|
+
Raises:
|
|
174
|
+
ValueError: If the path does not exist or is invalid.
|
|
175
|
+
"""
|
|
176
|
+
results = detect._get_python_files(path)
|
|
177
|
+
if not results:
|
|
178
|
+
return "PYTHON FILES\n\nNo Python files found."
|
|
179
|
+
rows = []
|
|
180
|
+
rows.append("PYTHON FILES")
|
|
181
|
+
rows.append("-" * 60)
|
|
182
|
+
rows.append(f"{'#':<5} {'FILE'}")
|
|
183
|
+
rows.append("-" * 60)
|
|
184
|
+
for number, file in enumerate(results, start=1):
|
|
185
|
+
rows.append(f"{number:<5} {file}")
|
|
186
|
+
rows.append("-" * 60)
|
|
187
|
+
return "\n".join(rows)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: crossportability
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Detect potential portability issues in Python projects.
|
|
5
|
+
Author: Neel Patel
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/neelpatel-png/crossportability
|
|
8
|
+
Project-URL: Repository, https://github.com/neelpatel-png/crossportability
|
|
9
|
+
Project-URL: Issues, https://github.com/neelpatel-png/crossportability/issues
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: Topic :: Software Development :: Testing
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# CrossPortability
|
|
21
|
+
A Python library for detecting potential operating-system and environment portability issues in Python projects.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
- Detect Platform-Specific Imports
|
|
25
|
+
- Detect OS-Specific Paths
|
|
26
|
+
- Detect Platform Usage
|
|
27
|
+
- Detect System Commands
|
|
28
|
+
- Detect Platform-Specific Environment Variables
|
|
29
|
+
- Analyze Individual Python Files
|
|
30
|
+
- Recursively Analyze Python Projects
|
|
31
|
+
- Generate Structured Detection Results
|
|
32
|
+
- Generate Human-Readable Reports
|
|
33
|
+
|
|
34
|
+
## Concepts Used
|
|
35
|
+
- Abstract Syntax Tree (AST)
|
|
36
|
+
- Static Code Analysis
|
|
37
|
+
- pathlib
|
|
38
|
+
- File Handling
|
|
39
|
+
- Dictionaries
|
|
40
|
+
- Lists
|
|
41
|
+
- Functions
|
|
42
|
+
- Exception Handling
|
|
43
|
+
- Type Hints
|
|
44
|
+
- Docstrings
|
|
45
|
+
- Python Packages
|
|
46
|
+
|
|
47
|
+
## Author
|
|
48
|
+
- Patel Neel
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
crossportability/__init__.py
|
|
5
|
+
crossportability/detect.py
|
|
6
|
+
crossportability/report.py
|
|
7
|
+
crossportability.egg-info/PKG-INFO
|
|
8
|
+
crossportability.egg-info/SOURCES.txt
|
|
9
|
+
crossportability.egg-info/dependency_links.txt
|
|
10
|
+
crossportability.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
crossportability
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools >= 77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "crossportability"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Detect potential portability issues in Python projects."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Neel Patel" }
|
|
13
|
+
]
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
20
|
+
"Topic :: Software Development :: Testing",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://github.com/neelpatel-png/crossportability"
|
|
25
|
+
Repository = "https://github.com/neelpatel-png/crossportability"
|
|
26
|
+
Issues = "https://github.com/neelpatel-png/crossportability/issues"
|