python-undef 0.1.0__tar.gz → 0.1.3__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.
- python_undef-0.1.3/PKG-INFO +55 -0
- python_undef-0.1.3/README.md +45 -0
- {python_undef-0.1.0 → python_undef-0.1.3}/pyproject.toml +2 -1
- {python_undef-0.1.0 → python_undef-0.1.3}/src/python_undef/__init__.py +25 -13
- python_undef-0.1.0/PKG-INFO +0 -8
- python_undef-0.1.0/README.md +0 -37
- {python_undef-0.1.0 → python_undef-0.1.3}/.gitignore +0 -0
- {python_undef-0.1.0 → python_undef-0.1.3}/LICENSE +0 -0
- {python_undef-0.1.0 → python_undef-0.1.3}/src/python_undef/__main__.py +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python_undef
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Python undefined header in pyconfig.h
|
|
5
|
+
Project-URL: homepage, https://github.com/Locked-chess-official/python_undef
|
|
6
|
+
Author-email: Locked-chess-official <13140752715@163.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# Python_undef
|
|
12
|
+
|
|
13
|
+
This is a Python script that generates a header file "Python_undef.h" which undefine many macros in "pyconfig.h" that doesn't match the rule that "should start with PY_".
|
|
14
|
+
|
|
15
|
+
## Why
|
|
16
|
+
|
|
17
|
+
The "pyconfig.h" continue many macros that doesn't math the rule that "should start with PY_" which may cause the comflict with the other projects. This project undefines them.
|
|
18
|
+
|
|
19
|
+
## Download
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install python_undef
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
This command will create the file "Python_undef.h"
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
python -m python_undef --generate
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This command will output the include path of "Python_undef.h".
|
|
34
|
+
|
|
35
|
+
You can use this command in your C/C++ project such as "cmake", "gyp" and so on.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
python -m python_undef --include
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
You can include the "Python_undef.h" file in your project:
|
|
42
|
+
|
|
43
|
+
```c
|
|
44
|
+
#include <Python.h>
|
|
45
|
+
#include <Python_undef.h>
|
|
46
|
+
#include <other_header.h>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The "pyconfig.h" continue many macros that doesn't math the rule that "should start with PY_". This file undefine them.
|
|
50
|
+
|
|
51
|
+
If you want to save the macro, use `#define DONOTUNDEF_macro_name` before include "Python_undef.h" to keep it.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT License
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Python_undef
|
|
2
|
+
|
|
3
|
+
This is a Python script that generates a header file "Python_undef.h" which undefine many macros in "pyconfig.h" that doesn't match the rule that "should start with PY_".
|
|
4
|
+
|
|
5
|
+
## Why
|
|
6
|
+
|
|
7
|
+
The "pyconfig.h" continue many macros that doesn't math the rule that "should start with PY_" which may cause the comflict with the other projects. This project undefines them.
|
|
8
|
+
|
|
9
|
+
## Download
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install python_undef
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
This command will create the file "Python_undef.h"
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
python -m python_undef --generate
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This command will output the include path of "Python_undef.h".
|
|
24
|
+
|
|
25
|
+
You can use this command in your C/C++ project such as "cmake", "gyp" and so on.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
python -m python_undef --include
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
You can include the "Python_undef.h" file in your project:
|
|
32
|
+
|
|
33
|
+
```c
|
|
34
|
+
#include <Python.h>
|
|
35
|
+
#include <Python_undef.h>
|
|
36
|
+
#include <other_header.h>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The "pyconfig.h" continue many macros that doesn't math the rule that "should start with PY_". This file undefine them.
|
|
40
|
+
|
|
41
|
+
If you want to save the macro, use `#define DONOTUNDEF_macro_name` before include "Python_undef.h" to keep it.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT License
|
|
@@ -4,8 +4,9 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python_undef"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.3"
|
|
8
8
|
description = "Python undefined header in pyconfig.h"
|
|
9
|
+
readme = "README.md"
|
|
9
10
|
license = {text = "MIT"}
|
|
10
11
|
authors = [
|
|
11
12
|
{ name = "Locked-chess-official", email = "13140752715@163.com" }
|
|
@@ -2,8 +2,9 @@ import os
|
|
|
2
2
|
import re
|
|
3
3
|
import datetime
|
|
4
4
|
import sys
|
|
5
|
+
from pathlib import Path
|
|
5
6
|
|
|
6
|
-
def is_valid_macro_name(macro_name):
|
|
7
|
+
def is_valid_macro_name(macro_name: str):
|
|
7
8
|
"""
|
|
8
9
|
Determine whether a macro name is valid using Python's standard library methods.
|
|
9
10
|
|
|
@@ -20,7 +21,7 @@ def is_valid_macro_name(macro_name):
|
|
|
20
21
|
# Use str.isidentifier() to check for valid identifier syntax
|
|
21
22
|
return macro_name.isidentifier()
|
|
22
23
|
|
|
23
|
-
def extract_macro_name(line):
|
|
24
|
+
def extract_macro_name(line: str):
|
|
24
25
|
"""Extract the macro name from a #define line (handles spaces between # and define)."""
|
|
25
26
|
line = line.strip()
|
|
26
27
|
|
|
@@ -36,7 +37,7 @@ def extract_macro_name(line):
|
|
|
36
37
|
return candidate
|
|
37
38
|
return None
|
|
38
39
|
|
|
39
|
-
def is_standard_python_macro(macro_name):
|
|
40
|
+
def is_standard_python_macro(macro_name: str):
|
|
40
41
|
"""
|
|
41
42
|
Check whether a macro follows Python's standard naming conventions.
|
|
42
43
|
Rules: Starts with Py, PY, _Py, _PY, or ends with _H.
|
|
@@ -44,7 +45,7 @@ def is_standard_python_macro(macro_name):
|
|
|
44
45
|
standard_prefixes = ('Py', 'PY', '_Py', '_PY')
|
|
45
46
|
return macro_name.startswith(standard_prefixes) or macro_name.endswith('_H')
|
|
46
47
|
|
|
47
|
-
def generate_undef_code(macro_name):
|
|
48
|
+
def generate_undef_code(macro_name: str):
|
|
48
49
|
"""Generate the code to undefine a macro."""
|
|
49
50
|
return f"""#ifndef DONOTUNDEF_{macro_name}
|
|
50
51
|
#ifdef {macro_name}
|
|
@@ -54,7 +55,7 @@ def generate_undef_code(macro_name):
|
|
|
54
55
|
|
|
55
56
|
"""
|
|
56
57
|
|
|
57
|
-
def generate_python_undef_header(pyconfig_path, output_path=None):
|
|
58
|
+
def generate_python_undef_header(pyconfig_path: str, output_path: str|None=None):
|
|
58
59
|
"""
|
|
59
60
|
Generate the Python_undef.h header file.
|
|
60
61
|
|
|
@@ -64,9 +65,14 @@ def generate_python_undef_header(pyconfig_path, output_path=None):
|
|
|
64
65
|
"""
|
|
65
66
|
if output_path is None:
|
|
66
67
|
file_dir = os.path.dirname(os.path.abspath(__file__))
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
include_dir = Path(file_dir) / 'include'
|
|
69
|
+
output_path = str(include_dir / 'Python_undef.h')
|
|
70
|
+
if not include_dir.exists():
|
|
71
|
+
try:
|
|
72
|
+
os.makedirs(f'{file_dir}/include')
|
|
73
|
+
except Exception as e:
|
|
74
|
+
print(f"Error creating include directory: {e}")
|
|
75
|
+
return False
|
|
70
76
|
|
|
71
77
|
# Read pyconfig.h
|
|
72
78
|
try:
|
|
@@ -194,7 +200,7 @@ def generate_python_undef_header(pyconfig_path, output_path=None):
|
|
|
194
200
|
print(f" ... and {len(macros_to_undef) - 50} more")
|
|
195
201
|
|
|
196
202
|
print(f"\nUsage Notes:")
|
|
197
|
-
print(f" 1. Include this file before including other library headers.")
|
|
203
|
+
print(f" 1. Include this file before including other library headers but must be after '<Python.h>'.")
|
|
198
204
|
print(f" 2. Use DONOTUNDEF_XXX to protect macros that must be kept.")
|
|
199
205
|
print(f" 3. Regenerate this file whenever rebuilding Python.")
|
|
200
206
|
|
|
@@ -206,7 +212,6 @@ def generate_python_undef_header(pyconfig_path, output_path=None):
|
|
|
206
212
|
|
|
207
213
|
def main():
|
|
208
214
|
import sysconfig
|
|
209
|
-
from pathlib import Path
|
|
210
215
|
if sys.argv[1:]:
|
|
211
216
|
if sys.argv[1] in ('-h', '--help'):
|
|
212
217
|
print("""Usage:
|
|
@@ -214,6 +219,7 @@ python -m python_undef --generate
|
|
|
214
219
|
Generate Python_undef.h based on the system's pyconfig.h.
|
|
215
220
|
python -m python_undef --include
|
|
216
221
|
Print the include path where Python_undef.h is located.""")
|
|
222
|
+
sys.exit(0)
|
|
217
223
|
elif sys.argv[1] == '--generate':
|
|
218
224
|
include_dir = Path(sysconfig.get_path('include'))
|
|
219
225
|
print(f"\n{'='*60}")
|
|
@@ -227,9 +233,11 @@ python -m python_undef --include
|
|
|
227
233
|
|
|
228
234
|
if success:
|
|
229
235
|
print(f"\n✅ Generation complete!")
|
|
230
|
-
print(f"💡 Tip:
|
|
236
|
+
print(f"💡 Tip: Use '{sys.executable} -m python_undef --include' to add this header file path to search path.")
|
|
237
|
+
sys.exit(0)
|
|
231
238
|
else:
|
|
232
239
|
print(f"\n❌ Generation failed!")
|
|
240
|
+
sys.exit(1)
|
|
233
241
|
|
|
234
242
|
else:
|
|
235
243
|
print(f"File {pyconfig_path} not found.")
|
|
@@ -239,14 +247,18 @@ python -m python_undef --include
|
|
|
239
247
|
print("\nTypical paths on Unix/Linux:")
|
|
240
248
|
print(" /usr/include/python3.x/pyconfig.h")
|
|
241
249
|
print(" /usr/local/include/python3.x/pyconfig.h")
|
|
250
|
+
sys.exit(1)
|
|
242
251
|
elif sys.argv[1] == "--include":
|
|
243
252
|
file_dir = os.path.dirname(os.path.abspath(__file__))
|
|
244
|
-
if not Path(file_dir).exists():
|
|
253
|
+
if not (Path(file_dir) / "include" / "Python_undef.h").exists():
|
|
245
254
|
print("File not found. Use 'python -m python_undef --generate' to generate the header first.")
|
|
246
|
-
|
|
255
|
+
sys.exit(1)
|
|
247
256
|
include_path = os.path.abspath(os.path.join(file_dir, 'include'))
|
|
248
257
|
print(include_path)
|
|
258
|
+
sys.exit(0)
|
|
249
259
|
else:
|
|
250
260
|
print("Unknown argument. Use --help for usage information.")
|
|
261
|
+
sys.exit(1)
|
|
251
262
|
else:
|
|
252
263
|
print("No arguments provided. Use --help for usage information.")
|
|
264
|
+
sys.exit(1)
|
python_undef-0.1.0/PKG-INFO
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: python_undef
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Python undefined header in pyconfig.h
|
|
5
|
-
Project-URL: homepage, https://github.com/Locked-chess-official/python_undef
|
|
6
|
-
Author-email: Locked-chess-official <13140752715@163.com>
|
|
7
|
-
License: MIT
|
|
8
|
-
License-File: LICENSE
|
python_undef-0.1.0/README.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Python_undef
|
|
2
|
-
|
|
3
|
-
## Download
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
pip install python_undef
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
|
|
11
|
-
This will create the file "Python_undef.h"
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
python -m python_undef --generate
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
This will output the include path of "Python_undef.h"
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
python -m python_undef --include
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
You can include the "Python_undef.h" file in your project:
|
|
24
|
-
|
|
25
|
-
```c
|
|
26
|
-
#include <Python.h>
|
|
27
|
-
#include <Python_undef.h>
|
|
28
|
-
#include <other_header.h>
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
The "pyconfig.h" continue many macros that doesn't math the rule that "should start with PY_". This file undefine them.
|
|
32
|
-
|
|
33
|
-
If you wan't to save the macro, use `#define DONOTUNDEF_macro_name` before include "Python_undef.h" to keep it.
|
|
34
|
-
|
|
35
|
-
## License
|
|
36
|
-
|
|
37
|
-
MIT License
|
|
File without changes
|
|
File without changes
|
|
File without changes
|