diff --git a/docarray/__init__.py b/docarray/__init__.py index c8f62c6fbe8..2cba2695129 100644 --- a/docarray/__init__.py +++ b/docarray/__init__.py @@ -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() diff --git a/docarray/helper.py b/docarray/helper.py index 865f19ff80d..30c074ae833 100644 --- a/docarray/helper.py +++ b/docarray/helper.py @@ -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( @@ -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 @@ -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()