Esempio n. 1
0
def check_version():
    # Check Taichi version for the user.
    print('Checking your Taichi version...')
    major = _ti_core.get_version_major()
    minor = _ti_core.get_version_minor()
    patch = _ti_core.get_version_patch()
    version = f'{major}.{minor}.{patch}'
    payload = {'version': version, 'platform': '', 'python': ''}

    system = platform.system()
    if system == 'Linux':
        payload['platform'] = 'manylinux1_x86_64'
    elif system == 'Windows':
        payload['platform'] = 'win_amd64'
    elif system == 'Darwin':
        if platform.release() < '19.0.0':
            payload['platform'] = 'macosx_10_14_x86_64'
        elif platform.machine() == 'x86_64':
            payload['platform'] = 'macosx_10_15_x86_64'
        else:
            payload['platform'] = 'macosx_11_0_arm64'

    python_version = platform.python_version()
    if python_version.startswith('3.6'):
        payload['python'] = 'cp36'
    elif python_version.startswith('3.7'):
        payload['python'] = 'cp37'
    elif python_version.startswith('3.8'):
        payload['python'] = 'cp38'
    elif python_version.startswith('3.9'):
        payload['python'] = 'cp39'

    # We do not want request exceptions break users' usage of Taichi.
    try:
        payload = json.dumps(payload)
        payload = payload.encode()
        req = request.Request('https://metadata.taichi.graphics/check_version',
                              method='POST')
        req.add_header('Content-Type', 'application/json')
        with request.urlopen(req, data=payload, timeout=3) as response:
            response = json.loads(response.read().decode('utf-8'))
            if response['status'] == 1:
                print(
                    f'Your Taichi version {version} is outdated. The latest version is {response["latest_version"]}, you can use\n'
                    + f'pip install taichi=={response["latest_version"]}\n' +
                    'to upgrade to the latest Taichi!')
            elif response['status'] == 0:
                # Status 0 means that user already have the latest Taichi. The message here prompts this infomation to users.
                print(response['message'])
    except Exception as error:
        print('Checking lastest version failed:', error)
Esempio n. 2
0
def check_version():
    # Check Taichi version for the user.
    major = _ti_core.get_version_major()
    minor = _ti_core.get_version_minor()
    patch = _ti_core.get_version_patch()
    version = f'{major}.{minor}.{patch}'
    payload = {'version': version, 'platform': '', 'python': ''}

    system = platform.system()
    if system == 'Linux':
        payload['platform'] = 'manylinux1_x86_64'
    elif system == 'Windows':
        payload['platform'] = 'win_amd64'
    elif system == 'Darwin':
        if platform.release() < '19.0.0':
            payload['platform'] = 'macosx_10_14_x86_64'
        elif platform.machine() == 'x86_64':
            payload['platform'] = 'macosx_10_15_x86_64'
        else:
            payload['platform'] = 'macosx_11_0_arm64'

    python_version = platform.python_version()
    if python_version.startswith('3.6.'):
        payload['python'] = 'cp36'
    elif python_version.startswith('3.7.'):
        payload['python'] = 'cp37'
    elif python_version.startswith('3.8.'):
        payload['python'] = 'cp38'
    elif python_version.startswith('3.9.'):
        payload['python'] = 'cp39'

    # We do not want request exceptions break users' usage of Taichi.
    try:
        payload = json.dumps(payload)
        payload = payload.encode()
        req = request.Request('https://metadata.taichi.graphics/check_version',
                              method='POST')
        req.add_header('Content-Type', 'application/json')
        with request.urlopen(req, data=payload, timeout=5) as response:
            response = json.loads(response.read().decode('utf-8'))
            return response
    except:
        return None
Esempio n. 3
0
def check_require_version(require_version):
    '''
    Check if installed version meets the requirements.
    Allow to specify <major>.<minor>.<patch>.<hash>.
    <patch>.<hash> is optional. If not match, raise an exception.
    '''
    # Extract version number part (i.e. toss any revision / hash parts).
    version_number_str = require_version
    for c_idx, c in enumerate(require_version):
        if not (c.isdigit() or c == "."):
            version_number_str = require_version[:c_idx]
            break
    # Get required version.
    try:
        version_number_tuple = tuple(
            [int(n) for n in version_number_str.split(".")])
        major = version_number_tuple[0]
        minor = version_number_tuple[1]
        patch = 0
        if len(version_number_tuple) > 2:
            patch = version_number_tuple[2]
    except:
        raise Exception("The require_version should be formatted following PEP 440, " \
            "and inlucdes major, minor, and patch number, " \
            "e.g., major.minor.patch.") from None
    # Get installed version
    versions = [
        int(_ti_core.get_version_major()),
        int(_ti_core.get_version_minor()),
        int(_ti_core.get_version_patch()),
    ]
    # Match installed version and required version.
    match = major == versions[0] and (
        minor < versions[1] or minor == versions[1] and patch <= versions[2])

    if not match:
        raise Exception(
            f"Taichi version mismatch. Required version >= {major}.{minor}.{patch}, installed version = {_ti_core.get_version_string()}."
        )
Esempio n. 4
0
else:

    def __getattr__(attr):
        # There's no easy way to hook accessing attribute with function calls in python3.6.
        # So let's skip it for now.
        import warnings  # pylint: disable=C0415,W0621
        if attr == 'cfg':
            return None if lang.impl.get_runtime(
            ).prog is None else lang.impl.current_cfg()
        if attr in __deprecated_names__:
            warnings.warn(
                f'ti.{attr} is deprecated. Please use ti.{__deprecated_names__[attr]} instead.',
                DeprecationWarning)
            exec(f'{attr} = {__deprecated_names__[attr]}')
            return locals()[attr]
        if attr in __customized_deprecations__:
            msg, fun = __customized_deprecations__[attr]
            warnings.warn(
                f'ti.{attr} is deprecated. Please use ti.{msg} instead.',
                DeprecationWarning)
            exec(f'{attr} = {fun}')
            return locals()[attr]
        raise AttributeError(f"module '{__name__}' has no attribute '{attr}'")


__version__ = (_ti_core.get_version_major(), _ti_core.get_version_minor(),
               _ti_core.get_version_patch())

del sys
del _ti_core