Skip to content

Commit 32bdd56

Browse files
committed
Version bump v2.0.0-beta.22
+ Python 3 compatibility: Fix languages stdlib II + Client: Check pipe exists
1 parent a661a07 commit 32bdd56

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

codeintel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.0-beta.21'
1+
__version__ = '2.0.0-beta.22'

codeintel/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,8 @@ def _send(self, callback=None, **kwargs):
818818
calling thread until the data has been written (though possibly not yet
819819
received on the other end).
820820
"""
821+
if not self.pipe:
822+
return
821823
req_id = hex(self._next_id)
822824
kwargs['req_id'] = req_id
823825
text = json.dumps(kwargs, separators=(',', ':'))

codeintel/codeintel2/database/stdlib.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,29 @@ def reportMemory(self):
271271
return total_mem_usage
272272

273273

274+
class Version(tuple):
275+
def __init__(self, ver):
276+
self.ver = ver
277+
278+
def __gt__(self, other):
279+
try:
280+
if isinstance(other, Version):
281+
return self.ver > other.ver
282+
else:
283+
return self.ver > other
284+
except TypeError:
285+
return False
286+
287+
def __lt__(self, other):
288+
try:
289+
if isinstance(other, Version):
290+
return self.ver < other.ver
291+
else:
292+
return self.ver < other
293+
except TypeError:
294+
return False
295+
296+
274297
class StdLibsZone(object):
275298
"""Singleton zone managing the db/stdlibs/... area.
276299
@@ -297,7 +320,7 @@ def vers_and_names_from_lang(self, lang):
297320
# ((5,3), "php-5.3")
298321
# ],
299322
# "ruby": [
300-
# ((0,0), "ruby"),
323+
# (None, "ruby"),
301324
# ],
302325
# ...
303326
# }
@@ -314,12 +337,12 @@ def vers_and_names_from_lang(self, lang):
314337
ver = _ver_from_ver_str(ver_str)
315338
else:
316339
base = name
317-
ver = (0, 0)
340+
ver = None
318341
if base.lower() != lang.lower():
319342
# Only process when the base name matches the language.
320343
# I.e. skip if base is "python3" and lang is "python".
321344
continue
322-
vers_and_names.append((ver, name))
345+
vers_and_names.append(Version((ver, name)))
323346
vers_and_names.sort()
324347
self._vers_and_names_from_lang[lang] = vers_and_names
325348
return vers_and_names
@@ -383,7 +406,7 @@ def get_lib(self, lang, ver_str=None):
383406

384407
# Here is something like what we have for PHP:
385408
# vers_and_names = [
386-
# ((0,0), "php"),
409+
# (None, "php"),
387410
# ((4,0), "php-4.0"),
388411
# ((4,1), "php-4.1"),
389412
# ((4,2), "php-4.2"),
@@ -399,7 +422,7 @@ def get_lib(self, lang, ver_str=None):
399422
# PHP 4.0.2: php-4.0 (higher sub-version)
400423
# PHP 4.4: php-4.3
401424
# PHP 6.0: php-5.1
402-
key = (ver, "zzz") # 'zzz' > any stdlib name (e.g., 'zzz' > 'php-4.2')
425+
key = Version((ver, "zzz")) # 'zzz' > any stdlib name (e.g., 'zzz' > 'php-4.2')
403426
idx = max(0, bisect.bisect_right(vers_and_names, key)-1)
404427
log.debug("best stdlib fit for %s ver=%s in %s is %s",
405428
lang, ver, vers_and_names, vers_and_names[idx])
@@ -508,7 +531,7 @@ def _update_lang_with_ver(self, lang, ver=None, progress_cb=None):
508531
if progress_cb:
509532
try: progress_cb("Determining necessary updates...", 5)
510533
except: log.exception("error in progress_cb (ignoring)")
511-
if ver != (0, 0):
534+
if ver is not None:
512535
ver_str = ".".join(map(str, ver))
513536
cix_path = join(self.stdlibs_dir,
514537
"%s-%s.cix" % (safe_lang_from_lang(lang), ver_str))
@@ -539,9 +562,9 @@ def _update_lang_with_ver(self, lang, ver=None, progress_cb=None):
539562

540563
def update_lang(self, lang, progress_cb=None, ver=None):
541564
vers_and_names = self.vers_and_names_from_lang(lang)
542-
if ver != (0, 0):
565+
if ver is not None:
543566
ver = _ver_from_ver_str(ver)
544-
key = (ver, "zzz") # 'zzz' > any stdlib name (e.g., 'zzz' > 'php-4.2')
567+
key = Version((ver, "zzz")) # 'zzz' > any stdlib name (e.g., 'zzz' > 'php-4.2')
545568
idx = max(0, bisect.bisect_right(vers_and_names, key)-1)
546569
log.debug("update_lang: best stdlib fit for %s ver=%s in %s is %s",
547570
lang, ver, vers_and_names, vers_and_names[idx])

0 commit comments

Comments
 (0)