Skip to content

Commit

Permalink
UI: Major change in console handling
Browse files Browse the repository at this point in the history
* Compiled programs on Windows are now created as GUI
  applications by default and attach to an available
  console if not redirected outputs.

* The new option "--console" controls this, and allows
  to restore old behavior with "force" value, and also
  disable with "disable" value, the new behavior is
  called "attach".

* On macOS the distinction has also been removed,
  technically it wasn't true for a while already,
  you need to use bundles for non-console
  applications through.

* Removed Nuitka Package configuration for the
  "options-nanny" plugin to warn the user about
  disabling console, it now recommend macOS bundle
  instead.

* This should improve the out of the box experience
  esp. on Windows by a lot.
  • Loading branch information
kayhayen committed May 15, 2024
1 parent 8e10aab commit aadd61b
Show file tree
Hide file tree
Showing 20 changed files with 310 additions and 196 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"_Py_DEC_REFTOTAL",
"_Py_DecodeUTF8_surrogateescape",
"_PyDict_NewPresized",
"_wfreopen",
"_wtoi",
"_XOPEN_SOURCE",
"abiflags",
Expand Down Expand Up @@ -133,6 +134,8 @@
"compactify",
"conda",
"condition-evals-to-constant",
"CONIN",
"CONOUT",
"containerfile",
"CORO_CLOSED",
"CORO_CREATED",
Expand Down
51 changes: 18 additions & 33 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ Currently, this means, you need to use one of these compilers:
Python
======

**Python 2** (2.6, 2.7) and **Python 3** (3.4 — 3.11) are supported. If
at any moment, there is a stable Python release that is not in this
**Python 2** (2.6, 2.7) and **Python 3** (3.4 — 3.11) are supported.
If at any moment, there is a stable Python release that is not in this
list, rest assured it is being worked on and will be added.

.. important::
Expand Down Expand Up @@ -352,7 +352,7 @@ will make the debugging only harder, e.g. in case of missing data files.
***********

Use Case 1 — Program compilation with all modules embedded
==========================================================
============================================================

If you want to compile a whole program recursively, and not only the
single file that is the main program, do it like this:
Expand Down Expand Up @@ -405,7 +405,7 @@ executable:
platforms) put inside.

Use Case 2 — Extension Module compilation
=========================================
===========================================

If you want to compile a single extension module, all you have to do is
this:
Expand Down Expand Up @@ -451,7 +451,7 @@ The resulting file ``some_module.so`` can then be used instead of
the same version and doesn't include other extension modules.

Use Case 3 — Package compilation
================================
==================================

If you need to compile a whole package and embed all modules, that is
also feasible, use Nuitka like this:
Expand All @@ -476,7 +476,7 @@ also feasible, use Nuitka like this:
<https://nuitka.net/doc/commercial/protect-data-files.html>`__.

Use Case 4 — Program Distribution
=================================
===================================

For distribution to other systems, there is the standalone mode, which
produces a folder for which you can specify ``--standalone``.
Expand Down Expand Up @@ -665,7 +665,7 @@ Currently, these expanded tokens are available:
``pythonw.exe`` which is behaving like ``{NONE}``.

Use Case 5 — Setuptools Wheels
==============================
================================

If you have a ``setup.py``, ``setup.cfg`` or ``pyproject.toml`` driven
creation of wheels for your software in place, putting Nuitka to use is
Expand Down Expand Up @@ -792,7 +792,7 @@ value:
and not as a file in the wheel.

Use Case 6 — Multidist
======================
========================

If you have multiple programs, that each should be executable, in the
past you had to compile multiple times, and deploy all of these. With
Expand Down Expand Up @@ -824,7 +824,7 @@ This mode works with standalone, onefile, and mere acceleration. It does
not work with module mode.

Use Case 7 — Building with GitHub Workflows
===========================================
=============================================

For integration with GitHub workflows there is this `Nuitka-Action
<https://github.com/Nuitka/Nuitka-Action>`__ that you should use that
Expand Down Expand Up @@ -892,11 +892,6 @@ this should then be a bundle.
# nuitka-project: --standalone
# nuitka-project: --macos-create-app-bundle
#
# Debugging options, controlled via environment variable at compile time.
# nuitka-project-if: os.getenv("DEBUG_COMPILATION", "no") == "yes"
# nuitka-project: --enable-console
# nuitka-project-else:
# nuitka-project: --disable-console
********
Tweaks
Expand Down Expand Up @@ -948,21 +943,10 @@ descriptive text is to be given.
Console Window
==============

On Windows, the console is opened by programs unless you say so. Nuitka
defaults to this, effectively being only good for terminal programs, or
programs where the output is requested to be seen. There is a difference
in ``pythonw.exe`` and ``python.exe`` along those lines. This is
replicated in Nuitka with the option ``--disable-console``. Nuitka
recommends you to consider this in case you are using ``PySide6`` e.g.
and other GUI packages, e.g. ``wx``, but it leaves the decision up to
you. In case, you know your program is console application, just using
``--enable-console`` which will get rid of these kinds of outputs from
Nuitka.

.. note::

The ``pythonw.exe`` is never good to be used with Nuitka, as you
cannot see its output.
On Windows, the console is not opened by programs unless you say so.
Nuitka defaults to not show it, you can force it by using
``--console=force`` though, then the program will open a new terminal
Window when its executed.

Splash screen
=============
Expand Down Expand Up @@ -1414,10 +1398,11 @@ which you expect to be inside the onefile binary, access them like this.
Windows Programs without console give no errors
===============================================

For debugging purposes, remove ``--disable-console`` or use the options
``--force-stdout-spec`` and ``--force-stderr-spec`` with paths as
documented for ``--onefile-tempdir-spec`` above. These can be relative
to the program or absolute, so you can see the outputs given.
For debugging purposes, use the options ``--force-stdout-spec`` and
``--force-stderr-spec`` with paths as documented for
``--onefile-tempdir-spec`` above. These can be relative to the program
or absolute, so you can see the outputs given. Also you can run the
program on a terminal prompt like ``CMD.exe`` to see its outputs.

Deep copying uncompiled functions
=================================
Expand Down
2 changes: 0 additions & 2 deletions UserPlugin-Creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ the methods have no argument.
+--------------------------------------+-----------------------------------------------------------------------------------+
| shallDetectMissingPlugins | *bool* = **not** ``--plugin-no-detection`` |
+--------------------------------------+-----------------------------------------------------------------------------------+
| shallDisableConsoleWindow | *bool* = ``--win-disable-console`` |
+--------------------------------------+-----------------------------------------------------------------------------------+
| shallExecuteImmediately | *bool* = ``--run`` |
+--------------------------------------+-----------------------------------------------------------------------------------+
| shallExplainImports | *bool* = ``--explain-imports`` |
Expand Down
17 changes: 7 additions & 10 deletions doc/nuitka-run.1
Original file line number Diff line number Diff line change
Expand Up @@ -576,16 +576,13 @@ filename. Default is standard output.
.IP
General OS controls:
.TP
\fB\-\-disable\-console\fR
When compiling for Windows or macOS, disable the
console window and create a GUI application. Defaults
to off.
.TP
\fB\-\-enable\-console\fR
When compiling for Windows or macOS, enable the
console window and create a console application. This
disables hints from certain modules, e.g. "PySide"
that suggest to disable it. Defaults to true.
\fB\-\-windows\-console\-mode\fR=\fI\,CONSOLE_MODE\/\fR
Select console mode to use. Default mode is 'force'
and creates a console window if not available, i.e.
the program was started from one. With 'disable' it
doesn't create or use a console. With 'attach' an
existing console will be used for outputs. Default is
\&'force'.
.TP
\fB\-\-force\-stdout\-spec\fR=\fI\,FORCE_STDOUT_SPEC\/\fR
Force standard output of the program to go to this
Expand Down
17 changes: 7 additions & 10 deletions doc/nuitka.1
Original file line number Diff line number Diff line change
Expand Up @@ -576,16 +576,13 @@ filename. Default is standard output.
.IP
General OS controls:
.TP
\fB\-\-disable\-console\fR
When compiling for Windows or macOS, disable the
console window and create a GUI application. Defaults
to off.
.TP
\fB\-\-enable\-console\fR
When compiling for Windows or macOS, enable the
console window and create a console application. This
disables hints from certain modules, e.g. "PySide"
that suggest to disable it. Defaults to true.
\fB\-\-windows\-console\-mode\fR=\fI\,CONSOLE_MODE\/\fR
Select console mode to use. Default mode is 'force'
and creates a console window if not available, i.e.
the program was started from one. With 'disable' it
doesn't create or use a console. With 'attach' an
existing console will be used for outputs. Default is
\&'force'.
.TP
\fB\-\-force\-stdout\-spec\fR=\fI\,FORCE_STDOUT_SPEC\/\fR
Force standard output of the program to go to this
Expand Down
8 changes: 0 additions & 8 deletions misc/nuitka-package-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,6 @@
"description": {
"type": "string"
},
"console": {
"type": "string",
"enum": [
"yes",
"no",
"recommend"
]
},
"macos_bundle": {
"type": "string",
"enum": [
Expand Down
22 changes: 16 additions & 6 deletions nuitka/OptionParsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,20 +1300,30 @@
action="store_true",
dest="disable_console",
default=None,
help="""\
When compiling for Windows or macOS, disable the console window and create a GUI
application. Defaults to off.""",
help=SUPPRESS_HELP,
)

os_group.add_option(
"--enable-console",
action="store_false",
dest="disable_console",
default=None,
help=SUPPRESS_HELP,
)

os_group.add_option(
"--windows-console-mode",
action="store",
dest="console_mode",
choices=("force", "disable", "attach"),
metavar="CONSOLE_MODE",
default=None,
help="""\
When compiling for Windows or macOS, enable the console window and create a console
application. This disables hints from certain modules, e.g. "PySide" that suggest
to disable it. Defaults to true.""",
Select console mode to use. Default mode is 'force' and creates a
console window if not available, i.e. the program was started from one. With
'disable' it doesn't create or use a console. With 'attach' an existing console
will be used for outputs. Default is 'force'.
""",
)

os_group.add_option(
Expand Down
57 changes: 34 additions & 23 deletions nuitka/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,6 @@ def _quoteArg(arg):
"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 = getFileVersionTuple()
# Catch all the things, don't want any interface, pylint: disable=broad-except
Expand Down Expand Up @@ -1122,15 +1117,10 @@ def commentArgs():
"""
)

if (
isMacOS()
and shallCreateAppBundle()
and shallDisableConsoleWindow()
and not getMacOSIconPaths()
):
if isMacOS() and shallCreateAppBundle() and not getMacOSIconPaths():
Tracing.general.warning(
"""\
For GUI applications, you ought to specify an icon with '--macos-app-icon'.", \
For application bundles, you ought to specify an icon with '--macos-app-icon'.", \
otherwise a dock icon may not be present."""
)

Expand All @@ -1149,7 +1139,7 @@ def commentArgs():
if (
isWin32Windows()
and 0x340 <= python_version < 0x380
and not shallDisableConsoleWindow()
and not getWindowsConsoleMode() != "disable"
):
Tracing.general.warning(
"""\
Expand All @@ -1162,6 +1152,30 @@ def commentArgs():
mnemonic="old-python-windows-console",
)

if shallMakeModule() and options.console_mode is not None:
Tracing.general.warning(
"""\
Extension modules are not binaries, and therefore the option \
'--windows-console-mode' does not have an impact and should \
not be specified."""
)

if options.disable_console in (True, False):
Tracing.general.warning(
"""\
The old console option '%s' should not be given anymore, use '%s' \
instead. It also has the extra mode 'attach' to consider."""
% (
(
"--disable-console"
if options.disable_console
else "--enable-console"
),
"--windows-console-module=%s"
% ("force" if options.disable_console else "disable"),
)
)


def isVerbose():
""":returns: bool derived from ``--verbose``"""
Expand Down Expand Up @@ -1668,16 +1682,13 @@ def shallDisableCompressionCacheUsage():
return shallDisableCacheUsage("compression")


def shallDisableConsoleWindow():
""":returns: None (not given), False, or True derived from ``--disable-console or ``--enable-console``"""
return options.disable_console


def mayDisableConsoleWindow():
""":returns: bool derived from platform support of disabling the console,"""

# TODO: What about MSYS2?
return isWin32Windows() or isMacOS()
def getWindowsConsoleMode():
""":returns: str from ``--windows-console-mode``"""
if options.disable_console is True:
return "disable"
if options.disable_console is False:
return "force"
return options.console_mode or "force"


def _isFullCompat():
Expand Down
6 changes: 3 additions & 3 deletions nuitka/build/Backend.scons
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ lto_mode = getArgumentDefaulted("lto_mode", "auto")
# PGO mode: Use profile guided optimization of C compiler if available.
pgo_mode = getArgumentDefaulted("pgo_mode", "no")

# Windows subsystem mode: Disable console for windows builds.
disable_console = getArgumentBool("disable_console", False)
# Console mode specified
console_mode = getArgumentDefaulted("console_mode", "attach")

# Windows might be running a Python whose DLL we have to use.
uninstalled_python = getArgumentBool("uninstalled_python", False)
Expand Down Expand Up @@ -354,7 +354,7 @@ env.the_cc_name = os.path.normcase(os.path.basename(env.the_compiler))
env.standalone_mode = standalone_mode
env.debug_mode = debug_mode
env.unstripped_mode = unstripped_mode
env.disable_console = disable_console
env.console_mode = console_mode
env.source_dir = source_dir
env.nuitka_src = nuitka_src
env.low_memory = low_memory
Expand Down
6 changes: 3 additions & 3 deletions nuitka/build/CCompilerVersion.scons
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ experimental = getArgumentList("experimental", "")
# good with the compiler in question.
lto_mode = getArgumentDefaulted("lto_mode", "auto")

# Windows subsystem mode: Disable console for windows builds.
disable_console = getArgumentBool("disable_console", False)
# Console mode specified
console_mode = getArgumentDefaulted("console_mode", "attach")

# Unstripped mode: Do not remove debug symbols.
unstripped_mode = getArgumentBool("unstripped_mode", False)
Expand Down Expand Up @@ -207,7 +207,7 @@ env.the_compiler = env["CC"] or env["CXX"]
env.the_cc_name = os.path.normcase(os.path.basename(env.the_compiler))
env.debug_mode = debug_mode
env.unstripped_mode = unstripped_mode
env.disable_console = disable_console
env.console_mode = console_mode
env.nuitka_src = nuitka_src
env.low_memory = False
env.macos_min_version = macos_min_version
Expand Down

0 comments on commit aadd61b

Please sign in to comment.