Skip to content

Commit db6eaad

Browse files
Merge pull request #2934 from HelioGuilherme66/backward_compatible
Backward compatible
2 parents fce171b + af0287a commit db6eaad

File tree

14 files changed

+146
-17
lines changed

14 files changed

+146
-17
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to http://semver.org/spec/v2.0.0.html[Semantic Versioni
1515
when selecting in Tree shows the filename in StatusBar.
1616

1717
=== Changed
18+
- Modified import statements to allow running RIDE without Robot Framework installed or versions older than 6.0.
1819
- On Windows ignore false modification on files when opening Test Suites, causing confirmation dialog.
1920

2021
== https://github.com/robotframework/RIDE/blob/master/doc/releasenotes/ride-2.1.3.rst[2.1.3] - 2025-03-24

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Likewise, the current version of wxPython, is 4.2.2, but RIDE is known to work w
4040

4141
`pip install -U robotframework-ride`
4242

43-
(3.8 <= python <= 3.13) Install current development version (**2.2dev17**) with:
43+
(3.8 <= python <= 3.13) Install current development version (**2.2dev18**) with:
4444

4545
`pip install -U https://github.com/robotframework/RIDE/archive/develop.zip`
4646

src/robotide/application/CHANGELOG.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Added divided Status Bar. Left side for main window, right side for Plugins. Working example in Text Editor,
99
when selecting in Tree shows the filename in StatusBar.
1010
</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_changed"></a>1.2. Changed</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
11+
Modified import statements to allow running RIDE without Robot Framework installed or versions older than 6.0.
12+
</li><li class="listitem">
1113
On Windows ignore false modification on files when opening Test Suites, causing confirmation dialog.
1214
</li></ul></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_ulink_url_https_github_com_robotframework_ride_blob_master_doc_releasenotes_ride_2_1_3_rst_2_1_3_ulink_2025_03_24"></a>2. <a class="ulink" href="https://github.com/robotframework/RIDE/blob/master/doc/releasenotes/ride-2.1.3.rst" target="_top">2.1.3</a> - 2025-03-24</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="_added_2"></a>2.1. Added</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
1315
Added syntax colorization for the ``GROUP`` marker.

src/robotide/application/releasenotes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def set_content(self, html_win, content):
170170
</ul>
171171
<p><strong>New Features and Fixes Highlights</strong></p>
172172
<ul class="simple">
173+
<li>Modified import statements to allow running RIDE without Robot Framework installed or versions older than 6.0.</li>
173174
<li>Added Config Panel button to supported installed Plugins next to their name in Plugin Manager dialog.</li>
174175
<li>Added Config Panel button to Plugins, working example in Text Editor.</li>
175176
<li>On Windows ignore false modification on files when opening Test Suites, causing confirmation dialog.</li>
@@ -229,7 +230,7 @@ def set_content(self, html_win, content):
229230
<pre class="literal-block">python -m robotide.postinstall -install</pre>
230231
<p>or</p>
231232
<pre class="literal-block">ride_postinstall.py -install</pre>
232-
<p>RIDE {VERSION} was released on 30/March/2025.</p>
233+
<p>RIDE {VERSION} was released on 02/April/2025.</p>
233234
<!-- <br/>
234235
<h3>May The Fourth Be With You!</h3>
235236
<h3>Celebrate the bank holiday, 10th June, Day of Portugal, Portuguese Communities and Camões!!</h3>

src/robotide/controller/dataloader.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ def __init__(self, path, settings, language=None):
9898

9999
def _run(self):
100100
if not self.language:
101-
self.language = lang.check_file_language(self._path)
101+
try:
102+
self.language = lang.check_file_language(self._path)
103+
except Exception:
104+
self.language = 'en'
102105
return test_data(source=self._path, settings=self._settings, language=self.language)
103106

104107

@@ -115,7 +118,10 @@ def _run(self):
115118
language=self.language)
116119
result.initfile = self._path
117120
if not self.language:
118-
self.language = lang.check_file_language(self._path)
121+
try:
122+
self.language = lang.check_file_language(self._path)
123+
except Exception:
124+
self.language = 'en'
119125
robotapi.FromFilePopulator(result, lang=self.language).populate(self._path)
120126
return result
121127

src/robotide/editor/texteditor.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,73 @@ def _set_shared_doc_lang(self, lang='en'):
717717
def set_editor(self, editor):
718718
self._editor = editor
719719

720+
720721
def validate_and_update(self, data, text, lang='en'):
722+
723+
try:
724+
from robot.parsing.parser.parser import get_model # RF > 4.0
725+
except ImportError:
726+
return self._old_validate_and_update(data, text)
727+
return self._new_validate_and_update(data, text, lang)
728+
729+
"""
730+
Backwards compatible code v1.7.4.2
731+
"""
732+
733+
def _old_validate_and_update(self, data, text):
734+
m_text = text.decode("utf-8")
735+
if not self._old_sanity_check(data, m_text):
736+
handled = self._old_handle_sanity_check_failure()
737+
if not handled:
738+
return False
739+
self._editor.reset()
740+
# print("DEBUG: updating text") # %s" % (self._editor.GetCurrentPos()))
741+
data.update_from(m_text)
742+
# print("DEBUG: AFTER updating text")
743+
self._editor.set_editor_caret_position()
744+
# %s" % (self._editor.GetCurrentPos()))
745+
return True
746+
747+
def _old_sanity_check(self, data, text):
748+
formatted_text = data.format_text(text)
749+
# print(f"DEBUG: texteditor old_sanity_check {formatted_text=}")
750+
c = self._normalize(formatted_text)
751+
e = self._normalize(text)
752+
return len(c) == len(e)
753+
754+
@staticmethod
755+
def _normalize(text):
756+
for item in [' ', r'\t', r'\n', r'\r\n', '...', '*']:
757+
if item in text:
758+
# print("DEBUG: _normaliz item %s txt %s" % (item, text))
759+
text = text.replace(item, '')
760+
return text
761+
762+
def _old_handle_sanity_check_failure(self):
763+
if self._last_answer == wx.ID_NO and \
764+
time() - self._last_answer_time <= 0.2:
765+
self._editor._mark_file_dirty()
766+
return False
767+
# TODO: use widgets.Dialog
768+
id = wx.MessageDialog(self._editor,
769+
'ERROR: Data sanity check failed!\n'
770+
'Reset changes?',
771+
'Can not apply changes from Txt Editor',
772+
style=wx.YES | wx.NO).ShowModal()
773+
self._last_answer = id
774+
self._last_answer_time = time()
775+
if id == wx.ID_YES:
776+
self._editor._revert()
777+
return True
778+
else:
779+
self._editor._mark_file_dirty()
780+
return False
781+
782+
"""
783+
End Backwards compatible code v1.7.4.2
784+
"""
785+
786+
def _new_validate_and_update(self, data, text, lang='en'):
721787
from robotide.lib.robot.errors import DataError
722788
m_text = text.decode("utf-8")
723789
# print(f"DEBUG: textedit.py validate_and_update ENTER"

src/robotide/lib/compat/parsing/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from .validator import ErrorReporter
15+
try:
16+
from .validator import ErrorReporter
17+
except ImportError:
18+
pass
1619
from .language import get_english_label, get_localized_setting
17-
from .languages import *
20+
try:
21+
from .languages import *
22+
except ImportError:
23+
pass

src/robotide/lib/compat/parsing/language.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
try:
2323
# Using local copy of https://github.com/robotframework/robotframework/blob/v7.0.1/src/robot/conf/languages.py
2424
from .languages import Language
25-
except ImportError:
25+
except ImportError as e:
26+
sys.stderr.write(f"RIDE: Trying to import robot's languages module returned error: {repr(e)}\n")
2627
Language = None
2728
from robot.errors import DataError
2829
from robotide.lib.robot.utils import Utf8Reader
@@ -236,11 +237,12 @@ def get_english_label(lang, label):
236237
try:
237238
mlang = Language.from_name(lang[0].replace('_', '-')) # Only care for a single language
238239
except ValueError:
239-
print(f"DEBUG: language.py get_english_label Exception at language={lang}")
240+
# print(f"DEBUG: language.py get_english_label Exception at language={lang}")
241+
pass
240242
else:
241243
mlang = Language.from_name(lang.replace('_', '-'))
242244
if not mlang:
243-
print(f"DEBUG: language.py get_english_label lang={lang} not found")
245+
# print(f"DEBUG: language.py get_english_label lang={lang} not found")
244246
return None
245247
setting_names = list(mlang.settings.keys())
246248
try:

src/robotide/lib/compat/parsing/languages.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,36 @@
2020
from typing import cast, Iterable, Iterator, Union
2121

2222
from robot.errors import DataError
23-
from robot.utils import classproperty, is_list_like, Importer, normalize
23+
from robot.utils import is_list_like, Importer, normalize
24+
try:
25+
from robot.utils import classproperty
26+
except ImportError: # This is when using RF older than 6.0
27+
28+
class classproperty(property):
29+
"""Property that works with classes in addition to instances.
30+
31+
Only supports getters. Setters and deleters cannot work with classes due
32+
to how the descriptor protocol works, and they are thus explicitly disabled.
33+
Metaclasses must be used if they are needed.
34+
"""
35+
36+
def __init__(self, fget, fset=None, fdel=None, doc=None):
37+
if fset:
38+
self.setter(fset)
39+
if fdel:
40+
self.deleter(fset)
41+
super().__init__(fget)
42+
if doc:
43+
self.__doc__ = doc
44+
45+
def __get__(self, instance, owner):
46+
return self.fget(owner)
47+
48+
def setter(self, fset):
49+
raise TypeError('Setters are not supported.')
50+
51+
def deleter(self, fset):
52+
raise TypeError('Deleters are not supported.')
2453

2554

2655
LanguageLike = Union['Language', str, Path]

src/robotide/lib/robot/parsing/model.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,10 @@ def __iter__(self):
473473
for table in self.tables:
474474
yield table
475475

476-
477-
from robotide.lib.compat.parsing.language import get_headers_for
476+
try:
477+
from robotide.lib.compat.parsing.language import get_headers_for
478+
except ImportError:
479+
get_headers_for = lambda l, t, lowercase=False: t
478480

479481

480482
class _Table(object):

0 commit comments

Comments
 (0)