0
# Version Information
1
2
Nuitka's version system provides comprehensive version detection, compatibility checking, and Python environment validation. The Version module enables programmatic access to version information for both Nuitka itself and the Python environments it supports.
3
4
## Capabilities
5
6
### Nuitka Version Information
7
8
Functions to retrieve current Nuitka version information in various formats.
9
10
```python { .api }
11
def getNuitkaVersion() -> str:
12
"""
13
Get current Nuitka version string.
14
15
Returns the complete version string including major, minor, and
16
patch numbers in semantic versioning format.
17
18
Returns:
19
str: Version string (e.g., "2.7.13")
20
"""
21
22
def parseNuitkaVersionToTuple(version: str) -> tuple[int, int, int, bool, int]:
23
"""
24
Convert version string to tuple format.
25
26
Parses a version string into its component parts for
27
programmatic comparison and manipulation.
28
29
Args:
30
version (str): Version string to parse
31
32
Returns:
33
tuple[int, int, int, bool, int]: (major, minor, patch, is_release, micro)
34
35
Raises:
36
ValueError: On invalid version string format
37
"""
38
39
def getNuitkaVersionTuple() -> tuple[int, int, int, bool, int]:
40
"""
41
Get version as tuple (major, minor, patch, is_release, micro).
42
43
Returns the current Nuitka version as a tuple with detailed
44
version information for precise programmatic comparison.
45
46
Returns:
47
tuple[int, int, int, bool, int]: (major, minor, patch, is_release, micro)
48
"""
49
50
def getNuitkaVersionYear() -> int:
51
"""
52
Get copyright year for current version.
53
54
Returns the copyright year associated with the current
55
Nuitka release for licensing and attribution purposes.
56
57
Returns:
58
int: Copyright year
59
"""
60
```
61
62
**Usage Example:**
63
64
```python
65
from nuitka.Version import (
66
getNuitkaVersion,
67
getNuitkaVersionTuple,
68
getNuitkaVersionYear,
69
parseNuitkaVersionToTuple
70
)
71
72
# Get version information
73
version_str = getNuitkaVersion()
74
version_tuple = getNuitkaVersionTuple()
75
copyright_year = getNuitkaVersionYear()
76
77
print(f"Nuitka version: {version_str}")
78
print(f"Version tuple: {version_tuple}")
79
print(f"Copyright year: {copyright_year}")
80
81
# Parse arbitrary version string
82
parsed = parseNuitkaVersionToTuple("2.5.8")
83
print(f"Parsed version: {parsed}") # (2, 5, 8)
84
```
85
86
### Commercial Version Support
87
88
Access commercial version information when available.
89
90
```python { .api }
91
def getCommercialVersion() -> str | None:
92
"""
93
Get commercial version if available.
94
95
Returns commercial plugin version information if a commercial
96
license is active and commercial features are available.
97
98
Returns:
99
str | None: Commercial version string or None if not available
100
"""
101
```
102
103
**Usage Example:**
104
105
```python
106
from nuitka.Version import getCommercialVersion
107
108
# Check for commercial features
109
commercial = getCommercialVersion()
110
111
if commercial:
112
print(f"Commercial version: {commercial}")
113
print("Commercial features available")
114
else:
115
print("Open source version")
116
```
117
118
### Python Version Compatibility
119
120
Functions to check Python version support and compatibility.
121
122
```python { .api }
123
def getSupportedPythonVersions() -> list:
124
"""
125
Get list of supported Python versions.
126
127
Returns all Python versions that are officially supported
128
by the current Nuitka release.
129
130
Returns:
131
list: Supported Python version strings
132
"""
133
134
def getNotYetSupportedPythonVersions() -> list:
135
"""
136
Get list of unsupported Python versions.
137
138
Returns Python versions that are not yet supported but
139
may be supported in future releases.
140
141
Returns:
142
list: Unsupported Python version strings
143
"""
144
145
def getSupportedPythonVersionStr() -> str:
146
"""
147
Get supported versions as formatted string.
148
149
Returns a human-readable string listing all supported
150
Python versions for display purposes.
151
152
Returns:
153
str: Formatted version support string
154
"""
155
156
def isPythonVersionSupported(version: str) -> bool:
157
"""
158
Check if specific Python version is supported.
159
160
Args:
161
version (str): Python version to check (e.g., "3.11")
162
163
Returns:
164
bool: True if version is supported
165
"""
166
167
def getCurrentPythonVersion() -> str:
168
"""
169
Get current Python version string.
170
171
Returns:
172
str: Current Python version (e.g., "3.11.5")
173
"""
174
```
175
176
**Usage Example:**
177
178
```python
179
from nuitka.PythonVersions import (
180
getSupportedPythonVersions,
181
getNotYetSupportedPythonVersions,
182
getSupportedPythonVersionStr
183
)
184
import sys
185
186
# Check version support
187
supported = getSupportedPythonVersions()
188
unsupported = getNotYetSupportedPythonVersions()
189
support_str = getSupportedPythonVersionStr()
190
191
print(f"Supported versions: {supported}")
192
print(f"Not yet supported: {unsupported}")
193
print(f"Support summary: {support_str}")
194
195
# Check current Python version
196
current_version = f"{sys.version_info.major}.{sys.version_info.minor}"
197
if current_version in [v.replace("Python ", "") for v in supported]:
198
print(f"Current Python {current_version} is supported")
199
else:
200
print(f"Warning: Python {current_version} may not be fully supported")
201
```
202
203
## Version Comparison
204
205
### Programmatic Version Comparison
206
207
Compare Nuitka versions programmatically for compatibility checking.
208
209
```python
210
from nuitka.Version import getNuitkaVersionTuple, parseNuitkaVersionToTuple
211
212
def is_version_compatible(required_version: str) -> bool:
213
"""
214
Check if current Nuitka version meets requirements.
215
216
Args:
217
required_version (str): Minimum required version
218
219
Returns:
220
bool: True if current version is compatible
221
"""
222
current = getNuitkaVersionTuple()
223
required = parseNuitkaVersionToTuple(required_version)
224
225
return current >= required
226
227
def compare_versions(version1: str, version2: str) -> int:
228
"""
229
Compare two version strings.
230
231
Args:
232
version1 (str): First version to compare
233
version2 (str): Second version to compare
234
235
Returns:
236
int: -1 if version1 < version2, 0 if equal, 1 if version1 > version2
237
"""
238
v1 = parseNuitkaVersionToTuple(version1)
239
v2 = parseNuitkaVersionToTuple(version2)
240
241
if v1 < v2:
242
return -1
243
elif v1 > v2:
244
return 1
245
else:
246
return 0
247
248
# Usage examples
249
if is_version_compatible("2.5.0"):
250
print("Version requirement met")
251
252
result = compare_versions("2.7.13", "2.6.0")
253
if result > 0:
254
print("First version is newer")
255
```
256
257
### Feature Availability Checking
258
259
Check if specific features are available in the current version.
260
261
```python
262
from nuitka.Version import getNuitkaVersionTuple
263
264
def has_feature(feature_name: str) -> bool:
265
"""
266
Check if a feature is available in current version.
267
268
Args:
269
feature_name (str): Name of feature to check
270
271
Returns:
272
bool: True if feature is available
273
"""
274
version = getNuitkaVersionTuple()
275
276
# Feature availability mapping (example)
277
features = {
278
"pgo": (2, 6, 0), # Profile-guided optimization
279
"lto": (2, 5, 0), # Link-time optimization
280
"commercial": (2, 0, 0), # Commercial features
281
"macos_bundle": (2, 4, 0), # macOS app bundles
282
"python3_12": (2, 7, 0), # Python 3.12 support
283
}
284
285
if feature_name in features:
286
required = features[feature_name]
287
return version >= required
288
289
return False
290
291
# Check feature availability
292
if has_feature("pgo"):
293
print("Profile-guided optimization available")
294
295
if has_feature("python3_12"):
296
print("Python 3.12 support available")
297
```
298
299
## Runtime Version Detection
300
301
### Python Environment Detection
302
303
Detect and validate the Python environment for compilation.
304
305
```python
306
import sys
307
from nuitka.PythonVersions import getSupportedPythonVersions
308
309
def validate_python_environment():
310
"""
311
Validate current Python environment for Nuitka compilation.
312
313
Returns:
314
dict: Environment validation results
315
"""
316
current_version = f"{sys.version_info.major}.{sys.version_info.minor}"
317
supported_versions = getSupportedPythonVersions()
318
319
# Convert supported versions to comparable format
320
supported_numbers = []
321
for version in supported_versions:
322
if "Python" in version:
323
ver_num = version.replace("Python ", "")
324
supported_numbers.append(ver_num)
325
326
is_supported = current_version in supported_numbers
327
328
return {
329
"current_version": current_version,
330
"supported_versions": supported_numbers,
331
"is_supported": is_supported,
332
"python_executable": sys.executable,
333
"platform": sys.platform,
334
"architecture": sys.maxsize > 2**32 and "64-bit" or "32-bit"
335
}
336
337
# Usage
338
env_info = validate_python_environment()
339
print(f"Python {env_info['current_version']} ({'supported' if env_info['is_supported'] else 'not supported'})")
340
print(f"Architecture: {env_info['architecture']}")
341
print(f"Platform: {env_info['platform']}")
342
```
343
344
### Development vs Production Detection
345
346
Detect if running in development or production environment.
347
348
```python
349
from nuitka.Version import getCommercialVersion
350
import os
351
352
def get_environment_info():
353
"""
354
Get comprehensive environment information.
355
356
Returns:
357
dict: Environment details
358
"""
359
return {
360
"nuitka_version": getNuitkaVersion(),
361
"nuitka_version_tuple": getNuitkaVersionTuple(),
362
"commercial_available": getCommercialVersion() is not None,
363
"development_mode": os.getenv("NUITKA_DEBUG") is not None,
364
"cache_enabled": os.getenv("NUITKA_CACHE_DIR") is not None,
365
"copyright_year": getNuitkaVersionYear()
366
}
367
368
# Usage
369
env = get_environment_info()
370
print(f"Environment: {'Development' if env['development_mode'] else 'Production'}")
371
print(f"Commercial: {'Available' if env['commercial_available'] else 'Not available'}")
372
print(f"Cache: {'Enabled' if env['cache_enabled'] else 'Disabled'}")
373
```
374
375
## Version Reporting
376
377
### Diagnostic Information
378
379
Generate comprehensive version and environment reports.
380
381
```python
382
from nuitka.Version import *
383
from nuitka.PythonVersions import *
384
import sys
385
import platform
386
387
def generate_version_report():
388
"""
389
Generate comprehensive version and environment report.
390
391
Returns:
392
str: Formatted report string
393
"""
394
report = ["=== Nuitka Version Report ==="]
395
396
# Nuitka version information
397
report.append(f"Nuitka Version: {getNuitkaVersion()}")
398
report.append(f"Nuitka Version Tuple: {getNuitkaVersionTuple()}")
399
report.append(f"Copyright Year: {getNuitkaVersionYear()}")
400
401
commercial = getCommercialVersion()
402
if commercial:
403
report.append(f"Commercial Version: {commercial}")
404
else:
405
report.append("Commercial Version: Not available")
406
407
# Python version information
408
report.append(f"\nCurrent Python: {sys.version}")
409
report.append(f"Python Version: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
410
report.append(f"Python Executable: {sys.executable}")
411
412
# Supported versions
413
supported = getSupportedPythonVersions()
414
report.append(f"\nSupported Python Versions:")
415
for version in supported:
416
report.append(f" - {version}")
417
418
unsupported = getNotYetSupportedPythonVersions()
419
if unsupported:
420
report.append(f"\nNot Yet Supported:")
421
for version in unsupported:
422
report.append(f" - {version}")
423
424
# Platform information
425
report.append(f"\nPlatform Information:")
426
report.append(f" System: {platform.system()}")
427
report.append(f" Machine: {platform.machine()}")
428
report.append(f" Architecture: {platform.architecture()[0]}")
429
430
return "\n".join(report)
431
432
# Usage
433
report = generate_version_report()
434
print(report)
435
436
# Save to file
437
with open("nuitka_version_report.txt", "w") as f:
438
f.write(report)
439
```
440
441
## Error Handling
442
443
### Version Validation Errors
444
445
Handle version-related errors and validation failures.
446
447
```python
448
from nuitka.Version import parseNuitkaVersionToTuple
449
450
def safe_version_check(version_string: str):
451
"""
452
Safely check and validate version string.
453
454
Args:
455
version_string (str): Version to validate
456
457
Returns:
458
tuple | None: Parsed version tuple or None on error
459
"""
460
try:
461
return parseNuitkaVersionToTuple(version_string)
462
except ValueError as e:
463
print(f"Invalid version format '{version_string}': {e}")
464
return None
465
except Exception as e:
466
print(f"Version parsing error: {e}")
467
return None
468
469
# Usage with error handling
470
version = safe_version_check("2.7.13")
471
if version:
472
print(f"Valid version: {version}")
473
else:
474
print("Version validation failed")
475
476
# Invalid version handling
477
invalid = safe_version_check("invalid.version") # Returns None
478
```
479
480
## Types
481
482
```python { .api }
483
# Version types
484
VersionString = str
485
VersionTuple = tuple[int, int, int]
486
CopyrightYear = int
487
488
# Python version types
489
PythonVersionList = list[str]
490
SupportStatus = bool
491
492
# Environment types
493
EnvironmentInfo = dict[str, Any]
494
VersionReport = str
495
```