1

I work on a GUI program that emits messages to console. Most of the time the messages can be ignored so a console window isn't needed. Linux users choose to show or not show messages by simply choosing to launch app from a shell session or the window manager. Windows users need to run different scripts: app for normal GUI-only mode or app-with-messages for gui with a command prompt window.

entry_points={
   # only needed for Windows:
   'console_scripts': ['app-with-messages= app.runApp:run'],
   # Used on both Linux and Windows:
   'gui_scripts': ['app = app.runApp:run']
   }

Both of these scripts call the same function. The only difference is that on Windows app will be started with pythonw.exe instead of python.exe. How can we avoid confusing our linux users and not create the redundant-for-them app-with-messages script?

matt wilkie
  • 17,268
  • 24
  • 80
  • 115

1 Answers1

2

If I understand your question correctly, you're trying to alter your entry_points depending on the OS that is being used. If so you could just include something like this in setup.py, and specify setup(entry_points=entry_points):

import os

entry_points = {'gui_scripts': ['app = app.runApp:run']}

if os.name == "nt":
    entry_points.update({'console_scripts': ['app-with-messages= app.runApp:run']})

print(entry_points)
#> {'console_scripts': ['app-with-messages= app.runApp:run'], 'gui_scripts': ['app = app.runApp:run']}

Created on 2018-09-27 by the reprexpy package

import reprexpy
print(reprexpy.SessionInfo())
#> Session info --------------------------------------------------------------------
#> Python: 3.5
#> Platform: Windows-7-6.1.7601-SP1 (64-bit)
#> Date: 2018-09-27
#> Packages ------------------------------------------------------------------------
#> reprexpy==0.1.1
Chris
  • 1,575
  • 13
  • 20
  • 1
    I accepted the answer as it solves the question I asked, however it may not be a good idea as one _"should be able to build a wheel of your package on Linux and install it on Windows (since it's an universal wheel), for this reason, changing the entry-points based on the platform setup.py is executed on is not a good idea"_ -- https://github.com/leo-editor/leo-editor/issues/968#issuecomment-425281750 – matt wilkie Oct 01 '18 at 19:24
  • Hmm, yeah, I guess if you wanted to build on Linux and install on Windows then it wouldn't work, but I'm not sure there would be any solution that would work in that case. – Chris Oct 02 '18 at 14:20