Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .array import DocumentArray
from .dataclasses import dataclass, field

if 'DA_NO_RICH_HANDLER' not in os.environ:
if 'DA_RICH_HANDLER' in os.environ:
from rich.traceback import install

install()
58 changes: 3 additions & 55 deletions docarray/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@
import pathlib
import random
import sys
import threading
import uuid
import warnings
from distutils.version import LooseVersion
from typing import Any, Dict, Optional, Sequence, Tuple
from urllib.request import Request, urlopen

import pkg_resources
from rich import print
from rich.panel import Panel

ALLOWED_PROTOCOLS = {'pickle', 'protobuf', 'protobuf-array', 'pickle-array'}
ALLOWED_COMPRESSIONS = {'lz4', 'bz2', 'lzma', 'zlib', 'gzip'}


__resources_path__ = os.path.join(
os.path.dirname(
Expand Down Expand Up @@ -402,6 +391,9 @@ def protocol_and_compress_from_file_path(
(None, gzip)
"""

ALLOWED_PROTOCOLS = {'pickle', 'protobuf', 'protobuf-array', 'pickle-array'}
ALLOWED_COMPRESSIONS = {'lz4', 'bz2', 'lzma', 'zlib', 'gzip'}

protocol = default_protocol
compress = default_compress

Expand Down Expand Up @@ -449,47 +441,3 @@ def filter_dict(d: Dict) -> Dict:
:return: filtered dict
"""
return dict(filter(lambda item: item[1] is not None, d.items()))


def _version_check(package: str = None, github_repo: str = None):
try:
if not package:
package = vars(sys.modules[__name__])['__package__']
if not github_repo:
github_repo = package

cur_ver = LooseVersion(pkg_resources.get_distribution(package).version)
req = Request(
f'https://pypi.python.org/pypi/{package}/json',
headers={'User-Agent': 'Mozilla/5.0'},
)
with urlopen(
req, timeout=1
) as resp: # 'with' is important to close the resource after use
j = json.load(resp)
releases = j.get('releases', {})
latest_release_ver = list(
sorted(LooseVersion(v) for v in releases.keys() if '.dev' not in v)
)[-1]
if cur_ver < latest_release_ver:
print(
Panel(
f'You are using [b]{package} {cur_ver}[/b], but [bold green]{latest_release_ver}[/] is available. '
f'You may upgrade it via [b]pip install -U {package}[/b]. [link=https://github.com/jina-ai/{github_repo}/releases]Read Changelog here[/link].',
title=':new: New version available!',
width=50,
)
)
except Exception:
# no network, too slow, PyPi is down
pass


def is_latest_version(package: str = None, github_repo: str = None) -> None:
"""Check if there is a latest version from Pypi, set env `NO_VERSION_CHECK` to disable it.

:param package: package name if none auto-detected
:param github_repo: repo name that contains CHANGELOG if none then the same as package name
"""

threading.Thread(target=_version_check, args=(package, github_repo)).start()