/
Options.py
2226 lines (1664 loc) · 67.5 KB
/
Options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2023, Kay Hayen, mailto:kay.hayen@gmail.com
#
# Part of "Nuitka", an optimizing Python compiler that is compatible and
# integrates with CPython, but also works on its own.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
""" Options module
This exposes the choices made by the user. Defaults will be applied here, and
some handling of defaults.
"""
# These are for use in option values.
# spell-checker: ignore uiaccess,noannotations,reexecution,etherium
# spell-checker: ignore nodocstrings,noasserts,nowarnings,norandomization
import fnmatch
import os
import re
import shlex
import sys
from nuitka import Progress, Tracing
from nuitka.containers.OrderedDicts import OrderedDict
from nuitka.containers.OrderedSets import OrderedSet
from nuitka.importing.StandardLibrary import isStandardLibraryPath
from nuitka.OptionParsing import parseOptions, runSpecialCommandsFromOptions
from nuitka.PythonFlavors import (
getPythonFlavorName,
isAnacondaPython,
isApplePython,
isDebianPackagePython,
isMSYS2MingwPython,
isNuitkaPython,
isPyenvPython,
isTermuxPython,
isUninstalledPython,
)
from nuitka.PythonVersions import (
getNotYetSupportedPythonVersions,
getSupportedPythonVersions,
isDebugPython,
python_version,
python_version_str,
)
from nuitka.utils.Execution import getExecutablePath
from nuitka.utils.FileOperations import (
isPathExecutable,
openTextFile,
resolveShellPatternToFilenames,
)
from nuitka.utils.Images import checkIconUsage
from nuitka.utils.StaticLibraries import getSystemStaticLibPythonPath
from nuitka.utils.Utils import (
getArchitecture,
getCPUCoreCount,
getLinuxDistribution,
getOS,
getWindowsRelease,
hasOnefileSupportedOS,
hasStandaloneSupportedOS,
isDebianBasedLinux,
isFreeBSD,
isLinux,
isMacOS,
isOpenBSD,
isPosixWindows,
isWin32OrPosixWindows,
isWin32Windows,
)
from nuitka.Version import getCommercialVersion, getNuitkaVersion
options = None
positional_args = None
extra_args = []
is_nuitka_run = None
is_debug = None
is_non_debug = None
is_full_compat = None
is_report_missing = None
is_verbose = None
def checkPathSpec(value, arg_name, allow_disable):
# There are never enough checks here, pylint: disable=too-many-branches
if "%NONE%" in value:
if not allow_disable:
Tracing.options_logger.sysexit(
"Using value '%%NONE%%' in '%s=%s' value is not allowed."
% (arg_name, value)
)
if value != "%NONE%":
Tracing.options_logger.sysexit(
"Using value '%%NONE%%' in '%s=%s' value does not allow anything else used too."
% (arg_name, value)
)
if "%NULL%" in value:
if not allow_disable:
Tracing.options_logger.sysexit(
"Using value '%%NULL%%' in '%s=%s' value is not allowed."
% (arg_name, value)
)
if value != "%NULL%":
Tracing.options_logger.sysexit(
"Using value '%%NULL%%' in '%s=%s' value does not allow anything else used too."
% (arg_name, value)
)
if "%COMPANY%" in value and not getCompanyName():
Tracing.options_logger.sysexit(
"Using value '%%COMPANY%%' in '%s=%s' value without being specified."
% (arg_name, value)
)
if "%PRODUCT%" in value and not getProductName():
Tracing.options_logger.sysexit(
"Using value '%%PRODUCT%%' in '%s=%s' value without being specified."
% (arg_name, value)
)
if "%VERSION%" in value and not (getFileVersion() or getProductVersion()):
Tracing.options_logger.sysexit(
"Using value '%%VERSION%%' in '%s=%s' value without being specified."
% (arg_name, value)
)
if value.count("%") % 2 != 0:
Tracing.options_logger.warning(
"""Unmatched '%%' is suspicious for '%s=%s' and may \
not do what you want it to do."""
% (arg_name, value)
)
for candidate in (
"%PROGRAM%",
"%PROGRAM_BASE%",
"%CACHE_DIR%",
"%HOME%",
"%TEMP%",
):
if candidate in value[1:]:
Tracing.options_logger.sysexit(
"""Absolute run time path of '%s' can only be at the \
start of '%s=%s', using it in the middle is not allowed."""
% (candidate, arg_name, value)
)
if candidate == value:
Tracing.options_logger.sysexit(
"""Cannot use general system folder %s, may only be the \
start of '%s=%s', using that alone is not allowed."""
% (candidate, arg_name, value)
)
def _checkOnefileTargetSpec():
checkPathSpec(
options.onefile_tempdir_spec,
arg_name="--onefile-tempdir-spec",
allow_disable=False,
)
if os.path.normpath(options.onefile_tempdir_spec) == ".":
Tracing.options_logger.sysexit(
"""\
Error, using '.' as a value for '--onefile-tempdir-spec' is not supported,
you cannot unpack the onefile payload into the same directory as the binary,
as that would overwrite it and cause locking issues as well."""
)
if options.onefile_tempdir_spec.count("%") == 0:
Tracing.options_logger.warning(
"""Not using any variables for '--onefile-tempdir-spec' should only be \
done if your program absolutely needs to be in the same path always: '%s'"""
% options.onefile_tempdir_spec
)
if os.path.isabs(options.onefile_tempdir_spec):
Tracing.options_logger.warning(
"""Using an absolute path should be avoided unless you are targeting a \
very well known environment: anchor with e.g. %%TEMP%%, %%CACHE_DIR%% is recommended: '%s'"""
% options.onefile_tempdir_spec
)
elif not options.onefile_tempdir_spec.startswith(
("%TEMP%", "%HOME%", "%CACHE_DIR%")
):
Tracing.options_logger.warning(
"""Using an relative to the executable should be avoided unless you are targeting a \
very well known environment, anchor with e.g. %%TEMP%%, %%CACHE_DIR%% is recommended: '%s'"""
% options.onefile_tempdir_spec
)
def _getVersionInformationValues():
# TODO: Might be nice if we could delay version information computation
# until it's actually used.
yield getNuitkaVersion()
yield "Commercial: %s" % getCommercialVersion()
yield "Python: %s" % sys.version.split("\n", 1)[0]
yield "Flavor: %s" % getPythonFlavorName()
yield "Executable: %s" % sys.executable
yield "OS: %s" % getOS()
yield "Arch: %s" % getArchitecture()
if isLinux():
dist_name, dist_base, dist_version = getLinuxDistribution()
if dist_base is not None:
yield "Distribution: %s (based on %s) %s" % (
dist_name,
dist_base,
dist_version,
)
else:
yield "Distribution: %s %s" % (dist_name, dist_version)
if isWin32OrPosixWindows():
yield "WindowsRelease: %s" % getWindowsRelease()
def printVersionInformation():
print("\n".join(_getVersionInformationValues()))
from nuitka.build.SconsInterface import (
asBoolStr,
runScons,
setCommonSconsOptions,
)
scons_options = {"compiler_version_mode": asBoolStr("true")}
env_values = setCommonSconsOptions(options=scons_options)
runScons(
options=scons_options,
env_values=env_values,
scons_filename="CCompilerVersion.scons",
)
def parseArgs():
"""Parse the command line arguments
:meta private:
"""
# singleton with many cases checking the options right away.
# pylint: disable=global-statement,too-many-branches,too-many-locals,too-many-statements
global is_nuitka_run, options, positional_args, extra_args, is_debug, is_non_debug
global is_full_compat, is_report_missing, is_verbose
if os.name == "nt":
# Windows store Python's don't allow looking at the python, catch that.
try:
with openTextFile(sys.executable, "rb"):
pass
except OSError:
Tracing.general.sysexit(
"""\
Error, the Python from Windows app store is not supported.""",
mnemonic="unsupported-windows-app-store-python",
)
is_nuitka_run, options, positional_args, extra_args = parseOptions(
logger=Tracing.options_logger
)
is_debug = _isDebug()
is_non_debug = not is_debug
is_full_compat = _isFullCompat()
if hasattr(options, "experimental"):
_experimental.update(options.experimental)
# Dedicated option for caches, ccache and bytecode
if options.disable_ccache:
options.disabled_caches.append("ccache")
if options.disable_bytecode_cache:
options.disabled_caches.append("bytecode")
if getattr(options, "disable_dll_dependency_cache", False):
options.disabled_caches.append("dll-dependencies")
# TODO: Have dedicated option for it.
is_report_missing = is_debug
if options.quiet or int(os.environ.get("NUITKA_QUIET", "0")):
Tracing.setQuiet()
def _quoteArg(arg):
if " " in arg:
if "=" in arg and arg.startswith("--"):
arg_name, value = arg.split("=", 1)
return '%s="%s"' % (arg_name, value)
else:
return '"%s"' % arg
else:
return arg
# This will not return if a non-compiling command is given.
runSpecialCommandsFromOptions(options)
if not options.version:
Tracing.options_logger.info(
"Used command line options: %s"
% " ".join(_quoteArg(arg) for arg in sys.argv[1:])
)
if os.environ.get("NUITKA_REEXECUTION") and not isAllowedToReexecute():
Tracing.general.sysexit(
"Error, not allowed to re-execute, but that has happened."
)
if options.progress_bar:
Progress.enableProgressBar()
if options.verbose_output:
Tracing.optimization_logger.setFileHandle(
# Can only have unbuffered binary IO in Python3, therefore not disabling buffering here.
openTextFile(options.verbose_output, "w", encoding="utf8")
)
options.verbose = True
is_verbose = options.verbose
Tracing.optimization_logger.is_quiet = not options.verbose
if options.version:
printVersionInformation()
sys.exit(0)
if options.clean_caches:
from nuitka.CacheCleanup import cleanCaches
cleanCaches()
if not positional_args:
sys.exit(0)
if options.show_inclusion_output:
Tracing.inclusion_logger.setFileHandle(
# Can only have unbuffered binary IO in Python3, therefore not disabling buffering here.
openTextFile(options.show_inclusion_output, "w", encoding="utf8")
)
options.show_inclusion = True
Tracing.progress_logger.is_quiet = not options.show_progress
# Onefile implies standalone build.
if options.is_onefile:
options.is_standalone = True
# Standalone implies no_site build
if options.is_standalone:
options.python_flags.insert(0, "no_site")
# Check onefile tempdir spec.
if options.onefile_tempdir_spec:
_checkOnefileTargetSpec()
if not options.is_onefile:
Tracing.options_logger.warning(
"""\
Using onefile specific option '--onefile-windows-splash-screen-image' has no effect \
when '--onefile' is not specified."""
)
# Check onefile splash image
if options.splash_screen_image:
if not os.path.exists(options.splash_screen_image):
Tracing.options_logger.sysexit(
"Error, splash screen image path '%s' does not exist."
% options.splash_screen_image
)
if not options.is_onefile:
Tracing.options_logger.warning(
"""\
Using onefile specific option '--onefile-windows-splash-screen-image' has no effect \
when '--onefile' is not specified."""
)
if options.onefile_child_grace_time is not None:
if not options.onefile_child_grace_time.isdigit():
Tracing.options_logger.sysexit(
"""\
Error, value given for '--onefile-child-grace-time' must be integer."""
)
if not options.is_onefile:
Tracing.options_logger.warning(
"""\
Using onefile specific option '--onefile-windows-splash-screen-image' has no effect \
when '--onefile-child-grace-time' is not specified."""
)
if options.force_stdout_spec:
checkPathSpec(
options.force_stdout_spec, "--force-stdout-spec", allow_disable=True
)
if options.force_stderr_spec:
checkPathSpec(
options.force_stderr_spec, "--force-stderr-spec", allow_disable=True
)
# Provide a tempdir spec implies onefile tempdir, even on Linux.
# Standalone mode implies an executable, not importing "site" module, which is
# only for this machine, recursing to all modules, and even including the
# standard library.
if options.is_standalone:
if options.module_mode:
Tracing.options_logger.sysexit(
"""\
Error, conflicting options, cannot make standalone module, only executable.
Modules are supposed to be imported to an existing Python installation, therefore it
makes no sense to include a Python runtime."""
)
for any_case_module in getShallFollowModules():
if any_case_module.startswith("."):
bad = True
else:
for char in "/\\:":
if char in any_case_module:
bad = True
break
else:
bad = False
if bad:
Tracing.options_logger.sysexit(
"""\
Error, '--follow-import-to' takes only module names or patterns, not directory path '%s'."""
% any_case_module
)
for no_case_module in getShallFollowInNoCase():
if no_case_module.startswith("."):
bad = True
else:
for char in "/\\:":
if char in no_case_module:
bad = True
break
else:
bad = False
if bad:
Tracing.options_logger.sysexit(
"""\
Error, '--nofollow-import-to' takes only module names or patterns, not directory path '%s'."""
% no_case_module
)
scons_python = getPythonPathForScons()
if scons_python is not None and not os.path.isfile(scons_python):
Tracing.options_logger.sysexit(
"Error, no such Python binary '%s', should be full path." % scons_python
)
output_filename = getOutputFilename()
if output_filename is not None:
if shallMakeModule():
Tracing.options_logger.sysexit(
"""\
Error, may not module mode where filenames and modules matching are
mandatory."""
)
elif (
isStandaloneMode() and os.path.basename(output_filename) != output_filename
):
Tracing.options_logger.sysexit(
"""\
Error, output filename for standalone cannot contain a directory part."""
)
output_dir = os.path.dirname(output_filename) or "."
if not os.path.isdir(output_dir):
Tracing.options_logger.sysexit(
"""\
Error, specified output directory does not exist, you have to create
it before using it: '%s' (from --output-filename='%s')."""
% (
output_dir,
output_filename,
)
)
if isLinux():
if len(getIconPaths()) > 1:
Tracing.options_logger.sysexit(
"Error, can only use one icon file on Linux."
)
if isMacOS():
if len(getIconPaths()) > 1:
Tracing.options_logger.sysexit(
"Error, can only use one icon file on macOS."
)
for icon_path in getIconPaths():
if "#" in icon_path and isWin32Windows():
icon_path, icon_index = icon_path.rsplit("#", 1)
if not icon_index.isdigit() or int(icon_index) < 0:
Tracing.options_logger.sysexit(
"Error, icon number in '%s#%s' not valid."
% (icon_path + "#" + icon_index)
)
if not os.path.exists(icon_path):
Tracing.options_logger.sysexit(
"Error, icon path '%s' does not exist." % icon_path
)
checkIconUsage(logger=Tracing.options_logger, icon_path=icon_path)
if getWindowsIconExecutablePath():
Tracing.options_logger.sysexit(
"Error, can only use icons from template executable or from icon files, but not both."
)
icon_exe_path = getWindowsIconExecutablePath()
if icon_exe_path is not None and not os.path.exists(icon_exe_path):
Tracing.options_logger.sysexit(
"Error, icon path executable '%s' does not exist." % icon_exe_path
)
if isMacOS() and not shallCreateAppBundle() and shallDisableConsoleWindow():
Tracing.options_logger.sysexit(
"Error, cannot disable console unless also using '--macos-create-app-bundle'."
)
try:
file_version = getFileVersion()
# Catch all the things, don't want any interface, pylint: disable=broad-except
except Exception:
Tracing.options_logger.sysexit(
"Error, file version must be a tuple of up to 4 integer values."
)
try:
product_version = getProductVersion()
# Catch all the things, don't want any interface, pylint: disable=broad-except
except Exception:
Tracing.options_logger.sysexit(
"Error, product version must be a tuple of up to 4 integer values."
)
if getCompanyName() == "":
Tracing.options_logger.sysexit(
"""Error, empty string is not an acceptable company name."""
)
if getProductName() == "":
Tracing.options_logger.sysexit(
"""Error, empty string is not an acceptable product name."""
)
splash_screen_filename = getWindowsSplashScreen()
if splash_screen_filename is not None:
if not os.path.isfile(splash_screen_filename):
Tracing.options_logger.sysexit(
"Error, specified splash screen image '%s' does not exist."
% splash_screen_filename
)
if (
file_version
or product_version
or getWindowsVersionInfoStrings()
and isWin32Windows()
):
if not (file_version or product_version) and getCompanyName():
Tracing.options_logger.sysexit(
"Error, company name and file or product version need to be given when any version information is given."
)
if isOnefileMode() and not hasOnefileSupportedOS():
Tracing.options_logger.sysexit(
"Error, unsupported OS for onefile '%s'." % getOS()
)
for module_pattern, _filename_pattern in getShallIncludePackageData():
if (
module_pattern.startswith("-")
or "/" in module_pattern
or "\\" in module_pattern
):
Tracing.options_logger.sysexit(
"Error, '--include-package-data' needs module name or pattern as an argument, not '%s'."
% module_pattern
)
for module_pattern in getShallFollowModules():
if (
module_pattern.startswith("-")
or "/" in module_pattern
or "\\" in module_pattern
):
Tracing.options_logger.sysexit(
"Error, '--follow-import-to' options needs module name or pattern as an argument, not '%s'."
% module_pattern
)
for module_pattern in getShallFollowInNoCase():
if (
module_pattern.startswith("-")
or "/" in module_pattern
or "\\" in module_pattern
):
Tracing.options_logger.sysexit(
"Error, '--nofollow-import-to' options needs module name or pattern as an argument, not '%s'."
% module_pattern
)
for data_file_desc in options.data_files:
if "=" not in data_file_desc:
Tracing.options_logger.sysexit(
"Error, malformed data file description, must specify relative target path separated with '='."
)
if data_file_desc.count("=") == 1:
src, dst = data_file_desc.split("=", 1)
src = os.path.expanduser(src)
src_pattern = src
else:
src, dst, pattern = data_file_desc.split("=", 2)
src = os.path.expanduser(src)
src_pattern = os.path.join(src, pattern)
filenames = resolveShellPatternToFilenames(src_pattern)
if len(filenames) > 1 and not dst.endswith(("/", os.path.sep)):
Tracing.options_logger.sysexit(
"Error, pattern '%s' matches more than one file, but target has no trailing slash, not a directory."
% src
)
if not filenames:
Tracing.options_logger.sysexit(
"Error, '%s' does not match any files." % src
)
if os.path.isabs(dst):
Tracing.options_logger.sysexit(
"Error, must specify relative target path for data file, not absolute path '%s'."
% data_file_desc
)
for data_dir in options.data_dirs:
if "=" not in data_dir:
Tracing.options_logger.sysexit(
"Error, malformed data dir description, must specify relative target path with '=' separating it."
)
src, dst = data_dir.split("=", 1)
if os.path.isabs(dst):
Tracing.options_logger.sysexit(
"Error, must specify relative target path for data dir, not '%s' as in '%s'."
% (dst, data_dir)
)
if not os.path.isdir(src):
Tracing.options_logger.sysexit(
"Error, must specify existing source data directory, not '%s' as in '%s'."
% (dst, data_dir)
)
for pattern in getShallFollowExtraFilePatterns():
if os.path.isdir(pattern):
Tracing.options_logger.sysexit(
"Error, pattern '%s' given to '--include-plugin-files' cannot be a directory name."
% pattern
)
for directory_name in getShallFollowExtra():
if not os.path.isdir(directory_name):
Tracing.options_logger.sysexit(
"Error, value '%s' given to '--include-plugin-directory' must be a directory name."
% directory_name
)
if isStandardLibraryPath(directory_name):
Tracing.options_logger.sysexit(
"""\
Error, directory '%s' given to '--include-plugin-directory' must not be a \
standard library path. Use '--include-module' or '--include-package' \
options instead."""
% pattern
)
if options.static_libpython == "yes" and getSystemStaticLibPythonPath() is None:
Tracing.options_logger.sysexit(
"Error, static libpython is not found or not supported for this Python installation."
)
if shallUseStaticLibPython() and getSystemStaticLibPythonPath() is None:
Tracing.options_logger.sysexit(
"""Error, usable static libpython is not found for this Python installation. You \
might be missing required packages. Disable with --static-libpython=no" if you don't \
want to install it."""
)
if isApplePython():
if isStandaloneMode():
Tracing.options_logger.sysexit(
"""\
Error, on macOS, for standalone mode, Apple Python is not supported \
due to being tied to specific OS releases, use e.g. CPython instead \
which is available from https://www.python.org/downloads/macos/ for \
download. With that, your program will work on macOS 10.9 or higher."""
)
if str is bytes:
Tracing.options_logger.sysexit(
"Error, Apple Python 2.7 from macOS is not usable as per Apple decision, use e.g. CPython 2.7 instead."
)
if isStandaloneMode() and isLinux() and getExecutablePath("patchelf") is None:
Tracing.options_logger.sysexit(
"Error, standalone mode on Linux requires 'patchelf' to be installed. Use 'apt/dnf/yum install patchelf' first."
)
pgo_executable = getPgoExecutable()
if pgo_executable and not isPathExecutable(pgo_executable):
Tracing.options_logger.sysexit(
"Error, path '%s' to binary to use for PGO is not executable."
% pgo_executable
)
if (
isOnefileMode()
and isTermuxPython()
and getExecutablePath("termux-elf-cleaner") is None
):
Tracing.options_logger.sysexit(
"""\
Error, onefile mode on Termux requires 'termux-elf-cleaner' to be installed, \
use 'pkg install termux-elf-cleaner' to use it."""
)
# This triggers checks inside that code
getCompilationReportUserData()
def commentArgs():
"""Comment on options, where we know something is not having the intended effect.
:meta private:
"""
# A ton of cases to consider, pylint: disable=too-many-branches,too-many-statements
# Check files to exist or be suitable first before giving other warnings.
for filename in getMainEntryPointFilenames():
if not os.path.exists(filename):
Tracing.general.sysexit("Error, file '%s' is not found." % filename)
if (
shallMakeModule()
and os.path.normcase(os.path.basename(filename)) == "__init__.py"
):
Tracing.general.sysexit(
"""\
Error, to compile a package, specify its directory but, not the '__init__.py'."""
)
# Inform the user about potential issues with the running version. e.g. unsupported
# version.
if python_version_str not in getSupportedPythonVersions():
# Do not disturb run of automatic tests with, detected from the presence of
# that environment variable.
if "PYTHON" not in os.environ:
Tracing.general.warning(
"""\
The Python version '%s' is only experimentally supported by Nuitka '%s', \
but an upcoming release will change that. In the mean time use Python \
version '%s' instead or newer Nuitka."""
% (
python_version_str,
getNuitkaVersion(),
getSupportedPythonVersions()[-1],
)
)
if python_version_str in getNotYetSupportedPythonVersions():
if not isExperimental("python" + python_version_str):
Tracing.general.sysexit(
"""\
The Python version '%s' is not supported by Nuitka '%s', but an upcoming \
release will add it. In the mean time use '%s' instead."""
% (
python_version_str,
getNuitkaVersion(),
getSupportedPythonVersions()[-1],
)
)
default_reference_mode = (
"runtime" if shallMakeModule() or isStandaloneMode() else "original"
)
if getFileReferenceMode() is None:
options.file_reference_mode = default_reference_mode
else:
if options.file_reference_mode != default_reference_mode:
Tracing.options_logger.warning(
"Using non-default file reference mode '%s' rather than '%s' may cause run time issues."
% (getFileReferenceMode(), default_reference_mode)
)
else:
Tracing.options_logger.info(
"Using default file reference mode '%s' need not be specified."
% default_reference_mode
)
default_mode_name_mode = "runtime" if shallMakeModule() else "original"
if getModuleNameMode() is None:
options.module_name_mode = default_mode_name_mode
elif getModuleNameMode() == default_mode_name_mode:
Tracing.options_logger.info(
"Using module name mode '%s' need not be specified."
% default_mode_name_mode
)
# TODO: Not all of these are usable with MSYS2 really, split those off.
if not isWin32OrPosixWindows():
# Too many Windows specific options clearly
if (
getWindowsIconExecutablePath()
or shallAskForWindowsAdminRights()
or shallAskForWindowsUIAccessRights()
or getWindowsSplashScreen()
):
Tracing.options_logger.warning(
"Using Windows specific options has no effect on other platforms."
)
if options.mingw64 or options.msvc_version:
Tracing.options_logger.warning(
"Requesting Windows specific compilers has no effect on other platforms."
)
if options.msvc_version:
if isMSYS2MingwPython() or isPosixWindows():
Tracing.options_logger.sysexit("Requesting MSVC on MSYS2 is not allowed.")
if isMingw64():
Tracing.options_logger.sysexit(
"Requesting both Windows specific compilers makes no sense."
)
if getMsvcVersion() and getMsvcVersion() not in ("list", "latest"):
if getMsvcVersion().count(".") != 1 or not all(
x.isdigit() for x in getMsvcVersion().split(".")
):
Tracing.options_logger.sysexit(
"For --msvc only values 'latest', 'info', and 'X.Y' values are allowed, but not '%s'."
% getMsvcVersion()
)
if isOnefileMode():
standalone_mode = "onefile"
elif isStandaloneMode():
standalone_mode = "standalone"
else:
standalone_mode = None
if standalone_mode and not hasStandaloneSupportedOS():
Tracing.options_logger.warning(
"Standalone mode on %s is not known to be supported, might fail to work."
% getOS()
)
if options.follow_all is True and shallMakeModule():
Tracing.optimization_logger.sysexit(
"""\
In module mode you must follow modules more selectively, and e.g. should \
not include standard library or all foreign modules or else it will fail \
to work. You need to instead selectively add them with \
'--follow-import-to=name' though."""
)
if options.follow_all is True and standalone_mode:
Tracing.options_logger.info(
"Following all imports is the default for %s mode and need not be specified."
% standalone_mode
)
if options.follow_all is False and standalone_mode:
Tracing.options_logger.warning(
"Following no imports is unlikely to work for %s mode and should not be specified."
% standalone_mode
)
if options.follow_stdlib:
if standalone_mode:
Tracing.options_logger.warning(
"Following imports to stdlib is the default in standalone mode.."
)
else:
Tracing.options_logger.warning(
"Following imports to stdlib not well tested and should not be specified."
)
if (
not standalone_mode
and options.follow_all is None
and not options.follow_modules
and not options.follow_stdlib
and not options.include_modules
and not options.include_packages
and not options.include_extra
and not options.follow_not_modules
):
Tracing.options_logger.warning(
"""You did not specify to follow or include anything but main %s. Check options and \
make sure that is intended."""
% ("module" if shallMakeModule() else "program")
)
if options.dependency_tool:
Tracing.options_logger.warning(
"Using removed option '--windows-dependency-tool' is deprecated and has no impact anymore."
)
if shallMakeModule() and options.static_libpython == "yes":
Tracing.options_logger.warning(
"In module mode, providing '--static-libpython' has no effect, it's not used."
)
options.static_libpython = "no"
if (
not isPgoMode()
and not isPythonPgoMode()
and (getPgoArgs() or getPgoExecutable())
):
Tracing.optimization_logger.warning(
"Providing PGO arguments without enabling PGO mode has no effect."
)
if isPgoMode():
if isStandaloneMode():
Tracing.optimization_logger.warning(
"Using PGO with standalone/onefile mode is not currently working. Expect errors."
)
if shallMakeModule():
Tracing.optimization_logger.warning(
"Using PGO with module mode is not currently working. Expect errors."
)
if (
options.static_libpython == "auto"
and not shallMakeModule()
and not shallUseStaticLibPython()
and getSystemStaticLibPythonPath() is not None
):
Tracing.options_logger.info(
"""Detected static libpython to exist, consider '--static-libpython=yes' for better performance, \
but errors may happen."""
)
if not shallExecuteImmediately():
if shallRunInDebugger():
Tracing.options_logger.warning(
"The '--debugger' option has no effect outside of '--debug' without '--run' option."
)
if not shallClearPythonPathEnvironment():
Tracing.options_logger.warning(
"The '--execute-with-pythonpath' option has no effect without '--run' option."
)
# Check if the fallback is used, except for Python2 on Windows, where we cannot