python-undef 0.1.3__tar.gz → 0.1.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python_undef
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: Python undefined header in pyconfig.h
5
5
  Project-URL: homepage, https://github.com/Locked-chess-official/python_undef
6
6
  Author-email: Locked-chess-official <13140752715@163.com>
@@ -24,16 +24,24 @@ pip install python_undef
24
24
 
25
25
  ## Usage
26
26
 
27
- This command will create the file "Python_undef.h"
27
+ This command under will create the file "Python_undef.h"
28
28
 
29
29
  ```bash
30
30
  python -m python_undef --generate
31
31
  ```
32
32
 
33
- This command will output the include path of "Python_undef.h".
33
+ It defaults output the file "Python_undef.h" in the package directory. You can use the `--output` option to specify the output file:
34
+
35
+ ```bash
36
+ python -m python_undef --generate --output <path>
37
+ ```
38
+
39
+ The command under will output the include path of "Python_undef.h".
34
40
 
35
41
  You can use this command in your C/C++ project such as "cmake", "gyp" and so on.
36
42
 
43
+ If hadn't run `python -m python_undef --generate` it will exit with code 1.
44
+
37
45
  ```bash
38
46
  python -m python_undef --include
39
47
  ```
@@ -14,16 +14,24 @@ pip install python_undef
14
14
 
15
15
  ## Usage
16
16
 
17
- This command will create the file "Python_undef.h"
17
+ This command under will create the file "Python_undef.h"
18
18
 
19
19
  ```bash
20
20
  python -m python_undef --generate
21
21
  ```
22
22
 
23
- This command will output the include path of "Python_undef.h".
23
+ It defaults output the file "Python_undef.h" in the package directory. You can use the `--output` option to specify the output file:
24
+
25
+ ```bash
26
+ python -m python_undef --generate --output <path>
27
+ ```
28
+
29
+ The command under will output the include path of "Python_undef.h".
24
30
 
25
31
  You can use this command in your C/C++ project such as "cmake", "gyp" and so on.
26
32
 
33
+ If hadn't run `python -m python_undef --generate` it will exit with code 1.
34
+
27
35
  ```bash
28
36
  python -m python_undef --include
29
37
  ```
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "python_undef"
7
- version = "0.1.3"
7
+ version = "0.1.5"
8
8
  description = "Python undefined header in pyconfig.h"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -1,3 +1,17 @@
1
+ """
2
+ python_undef - A utility to generate a header file that undefines non-standard Python macros in pyconfig.h.
3
+
4
+ Usage:
5
+ python -m python_undef --generate
6
+ This is the main command to generate Python_undef.h based on the system's pyconfig.h to the include directly under the package directly.
7
+ python -m python_undef --generate --output <path>
8
+ This command generates Python_undef.h and saves it to the specified output path.
9
+ python -m python_undef --include
10
+ This command prints the include path where Python_undef.h is located.
11
+ python -m python_undef --help
12
+ Display this help message.
13
+ """
14
+
1
15
  import os
2
16
  import re
3
17
  import datetime
@@ -71,7 +85,7 @@ def generate_python_undef_header(pyconfig_path: str, output_path: str|None=None)
71
85
  try:
72
86
  os.makedirs(f'{file_dir}/include')
73
87
  except Exception as e:
74
- print(f"Error creating include directory: {e}")
88
+ print(f"Error creating include directory: {e}", file=sys.stderr)
75
89
  return False
76
90
 
77
91
  # Read pyconfig.h
@@ -79,10 +93,10 @@ def generate_python_undef_header(pyconfig_path: str, output_path: str|None=None)
79
93
  with open(pyconfig_path, 'r', encoding='utf-8') as f:
80
94
  lines = f.readlines()
81
95
  except FileNotFoundError:
82
- print(f"Error: File not found {pyconfig_path}")
96
+ print(f"Error: File not found {pyconfig_path}", file=sys.stderr)
83
97
  return False
84
98
  except Exception as e:
85
- print(f"Error reading file: {e}")
99
+ print(f"Error reading file: {e}", file=sys.stderr)
86
100
  return False
87
101
 
88
102
  # Collect macros
@@ -132,7 +146,7 @@ def generate_python_undef_header(pyconfig_path: str, output_path: str|None=None)
132
146
  * #define DONOTUNDEF_MACRO_NAME
133
147
  *
134
148
  * Generation rules:
135
- * - Macros starting with Py_, PY_, _Py, _PY are preserved (Python standard)
149
+ * - Macros starting with Py, PY, _Py, _PY are preserved (Python standard)
136
150
  * - Macros ending with _H are preserved (header guards)
137
151
  * - All other macros are undefined
138
152
  * - Macro name validation uses Python's standard identifier checking
@@ -207,7 +221,7 @@ def generate_python_undef_header(pyconfig_path: str, output_path: str|None=None)
207
221
  return True
208
222
 
209
223
  except Exception as e:
210
- print(f"Error writing file: {e}")
224
+ print(f"Error writing file: {e}", file=sys.stderr)
211
225
  return False
212
226
 
213
227
  def main():
@@ -216,7 +230,9 @@ def main():
216
230
  if sys.argv[1] in ('-h', '--help'):
217
231
  print("""Usage:
218
232
  python -m python_undef --generate
219
- Generate Python_undef.h based on the system's pyconfig.h.
233
+ Generate Python_undef.h based on the system's pyconfig.h to the include directly under the package directly.
234
+ python -m python_undef --generate --output <path>
235
+ Generate Python_undef.h and specify output path.
220
236
  python -m python_undef --include
221
237
  Print the include path where Python_undef.h is located.""")
222
238
  sys.exit(0)
@@ -229,36 +245,44 @@ python -m python_undef --include
229
245
  pyconfig_path = include_dir / "pyconfig.h"
230
246
 
231
247
  if os.path.exists(pyconfig_path):
232
- success = generate_python_undef_header(pyconfig_path)
233
-
248
+ if sys.argv[2:]:
249
+ if sys.argv[2] == "--output" and len(sys.argv) == 4:
250
+ if not os.path.isdir(sys.argv[3]):
251
+ print("Error: Specified output path does not exist.", file=sys.stderr)
252
+ sys.exit(1)
253
+ output_path = str(Path(sys.argv[3]) / "Python_undef.h")
254
+ print(f"Output path specified: {output_path}")
255
+ else:
256
+ print("Invalid output argument. Use --output <path> to specify output file.", file=sys.stderr)
257
+ sys.exit(1)
258
+ else:
259
+ output_path = None
260
+ success = generate_python_undef_header(pyconfig_path, output_path)
261
+
234
262
  if success:
235
263
  print(f"\n✅ Generation complete!")
236
- print(f"💡 Tip: Use '{sys.executable} -m python_undef --include' to add this header file path to search path.")
264
+ if not output_path:
265
+ print(f"💡 Tip: Use '{sys.executable} -m python_undef --include' to add this header file path to search path.")
237
266
  sys.exit(0)
238
267
  else:
239
- print(f"\n❌ Generation failed!")
268
+ print(f"\n❌ Generation failed!", file=sys.stderr)
240
269
  sys.exit(1)
241
-
270
+
242
271
  else:
243
- print(f"File {pyconfig_path} not found.")
244
- print("Please update the pyconfig_path variable to the actual pyconfig.h path.")
245
- print("\nTypical paths on Windows:")
246
- print(" C:\\\\Python3x\\\\include\\\\pyconfig.h")
247
- print("\nTypical paths on Unix/Linux:")
248
- print(" /usr/include/python3.x/pyconfig.h")
249
- print(" /usr/local/include/python3.x/pyconfig.h")
272
+ print(f"File {pyconfig_path} not found.", file=sys.stderr)
273
+ print("Please ensure the python is standard installation with headers.", file=sys.stderr)
250
274
  sys.exit(1)
251
275
  elif sys.argv[1] == "--include":
252
276
  file_dir = os.path.dirname(os.path.abspath(__file__))
253
277
  if not (Path(file_dir) / "include" / "Python_undef.h").exists():
254
- print("File not found. Use 'python -m python_undef --generate' to generate the header first.")
278
+ print(f"File not found. Use '{sys.executable} -m python_undef --generate' to generate the header first.", file=sys.stderr)
255
279
  sys.exit(1)
256
280
  include_path = os.path.abspath(os.path.join(file_dir, 'include'))
257
281
  print(include_path)
258
282
  sys.exit(0)
259
283
  else:
260
- print("Unknown argument. Use --help for usage information.")
284
+ print("Unknown argument. Use --help for usage information.", file=sys.stderr)
261
285
  sys.exit(1)
262
286
  else:
263
- print("No arguments provided. Use --help for usage information.")
287
+ print("No arguments provided. Use --help for usage information.", file=sys.stderr)
264
288
  sys.exit(1)
File without changes
File without changes