Coverage for src/robotide/__init__.py: 89%
92 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
1# Copyright 2008-2015 Nokia Networks
2# Copyright 2016- Robot Framework Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
16"""RIDE -- Robot Framework test data editor
18Usage: ride.py [--noupdatecheck] [--debugconsole] [--settingspath <full path|settings filename>] [--version] [inpath]
20RIDE can be started either without any arguments or by giving a path to a test
21data file or directory to be opened.
23To disable update checker use --noupdatecheck.
25To start debug console for RIDE problem debugging use --debugconsole option.
27To use different settings use the option --settingspath followed by the path to the settings file or file name.
29To see RIDE's version use --version.
31RIDE's API is still evolving while the project is moving towards the 1.0
32release. The most stable, and best documented, module is `robotide.pluginapi`.
33"""
35import os 1dcr
36import sys 1dcr
37from string import Template 1dcr
39errorMessageTemplate = Template("""$reason 1dcr
40RIDE depends on wx (wxPython). Known versions for Python3 are: 4.0.7.post2, 4.1.1 and 4.2.1.\
41At the time of this release the current wxPython version is 4.2.1.\
42You can install with 'pip install wxPython' on most operating systems, or find the \
43the download link from https://wxPython.org/""")
45try: 1dcr
46 import wx 1dcr
47 import wx.lib.inspection 1dcr
48 from wx import Colour 1dc
49except ModuleNotFoundError: 1r
50 print(errorMessageTemplate.substitute(reason="wxPython not found.")) 1r
51 sys.exit(1) 1r
53# Insert bundled robot to path before anything else
54sys.path.append(os.path.join(os.path.dirname(__file__), 'spec')) 1dc
55sys.path.append(os.path.join(os.path.dirname(__file__), 'lib')) 1dc
58def main(*args): 1dc
59 _replace_std_for_win() 1lbgam
60 if '--version' in args: 1lbgam
61 try: 1lgm
62 from . import version 1lgm
63 except ImportError: 1g
64 print("Error getting RIDE version!") 1g
65 sys.exit(1) 1g
66 print(version.VERSION) 1lm
67 sys.exit(0) 1lm
68 noupdatecheck, debug_console, settings_path, inpath = _parse_args(args) 1ba
69 if len(args) > 3 or '--help' in args: 1ba
70 print(__doc__) 1a
71 sys.exit() 1a
72 try: 1b
73 _run(inpath, not noupdatecheck, debug_console, settingspath=settings_path) 1b
74 except Exception: # DEBUG 1b
75 import traceback 1b
76 traceback.print_exception(*sys.exc_info()) 1b
77 sys.stderr.write('\n\nUse --help to get usage information.\n') 1b
80def _parse_args(args): 1dc
81 if not args: 1baenowpqshijk
82 return False, False, None, None 1bew
83 arguments = list(args) 1aenopqshijk
84 noupdatecheck = '--noupdatecheck' in arguments 1aenopqshijk
85 if noupdatecheck: 1aenopqshijk
86 arguments.remove('--noupdatecheck') 1aepq
87 debug_console = '--debugconsole' in arguments 1aenopqshijk
88 if debug_console: 1aenopqshijk
89 arguments.remove('--debugconsole') 1aeno
90 settings_path = None 1aenopqshijk
91 if '--settingspath' in arguments: 1aenopqshijk
92 arguments.remove('--settingspath') 1ehijk
93 if len(arguments) > 0: 1ehijk
94 settings_path = arguments.pop(0) 1eijk
95 else:
96 settings_path = None 1h
97 inpath = arguments[0] if arguments else None 1aenopqshijk
98 return noupdatecheck, debug_console, settings_path, inpath 1aenopqshijk
101def _run(inpath=None, updatecheck=True, debug_console=False, settingspath=None): 1dc
102 # print(f"DEBUG: ENTER _run {inpath=}, {updatecheck=}, {debug_console=}")
103 try: 1vtf
104 from robotide.application import RIDE 1vtf
105 from robotide.application import debugconsole 1tf
106 except ImportError: 1v
107 _show_old_wxpython_warning_if_needed() 1v
108 raise 1v
109 ride = RIDE(inpath, updatecheck, settingspath=settingspath) 1tf
110 if wx.VERSION <= (4, 0, 4, '', ''): 1tf
111 _show_old_wxpython_warning_if_needed(ride.frame) 1f
112 else:
113 wx.CallAfter(_show_old_wxpython_warning_if_needed, ride.frame) 1t
114 if debug_console: 1tf
115 wx.lib.inspection.InspectionTool().Show() 1t
116 debugconsole.start(ride) 1t
117 ride.MainLoop() 1tf
120def _replace_std_for_win(): 1dc
122 class NullStream: 1lbgam
123 def close(self): 1lbgam
124 """ Override """
125 pass
127 def flush(self): 1lbgam
128 """ Override """
129 pass
131 def write(self, line): 1lbgam
132 """ Override """
133 pass
135 def writelines(self, sequence): 1lbgam
136 """ Override """
137 pass
139 if sys.executable.endswith('.exe'): 139 ↛ 142line 139 didn't jump to line 142 because the condition on line 139 was never true1lbgam
140 # In windows, when launching RIDE with pythonw.exe
141 # sys.stderr and sys.stdout will be None
142 if sys.stderr is None:
143 sys.stderr = NullStream()
144 if sys.stdout is None:
145 sys.stdout = NullStream()
148def _show_old_wxpython_warning_if_needed(parent=None): 1dc
149 # print("DEBUG: ENTER _show_old_wxpython_warning_if_needed")
150 if wx.VERSION <= (4, 0, 4, '', ''): 1cuf
151 title = "Please upgrade your wxPython installation" 1uf
152 message = ("RIDE needs a newer wxPython version. Your current " 1uf
153 "version is %s."
154 "\n"
155 "At the time of this release the current wxPython version is 4.2.1. See "
156 "https://wxPython.org/ for downloads and instructions."
157 % wx.VERSION_STRING)
158 style = wx.ICON_EXCLAMATION 1uf
159 if not parent: 1uf
160 _ = wx.App() 1u
161 parent = wx.Frame(None, size=(0, 0)) 1u
162 sys.stderr.write("{0}\n{1}\n".format(title, message)) 1uf
163 dlg = wx.MessageDialog(parent, message=message, caption=title, style=style) 1uf
164 dlg.ShowModal() 1uf
167if __name__ == '__main__': 1dc
168 main(*sys.argv[1:])