未验证 提交 72966dcb 编写于 作者: L Linhe Huo 提交者: GitHub

[TD-10828]<fix>: fix PyPI taospy connector failed for master branch (#8571)

* [TD-10828]<fix>: fix PyPI taospy connector failed for master branch

* chore: fix pip install document

* chore: fix CI error
上级 a8b53c24
...@@ -5,14 +5,27 @@ ...@@ -5,14 +5,27 @@
## Install ## Install
```sh You can use `pip` to install the connector from PyPI:
git clone --depth 1 https://github.com/taosdata/TDengine.git
pip install ./TDengine/src/connector/python ```bash
pip install taospy
```
Or with git url:
```bash
pip install git+https://github.com/taosdata/taos-connector-python.git
```
If you have installed TDengine server or client with prebuilt packages, then you can install the connector from path:
```bash
pip install /usr/local/taos/connector/python
``` ```
## Source Code ## Source Code
[TDengine](https://github.com/taosdata/TDengine) connector for Python source code is hosted on [GitHub](https://github.com/taosdata/TDengine/tree/develop/src/connector/python). [TDengine](https://github.com/taosdata/TDengine) connector for Python source code is hosted on [GitHub](https://github.com/taosdata/taos-connector-python).
## Examples ## Examples
......
[tool.poetry] [tool.poetry]
name = "taos" name = "taospy"
version = "2.1.1" version = "2.1.2"
description = "TDengine connector for python" description = "TDengine connector for python"
authors = ["Taosdata Inc. <support@taosdata.com>"] authors = ["Taosdata Inc. <support@taosdata.com>"]
license = "AGPL-3.0" license = "AGPL-3.0"
readme = "README.md" readme = "README.md"
packages = [
{include = "taos"}
]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^2.7 || ^3.4" python = "^2.7 || ^3.4"
...@@ -12,12 +15,12 @@ typing = "*" ...@@ -12,12 +15,12 @@ typing = "*"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
pytest = [ pytest = [
{ version = "^4.6", python = "^2.7" }, { version = "^4.6", python = ">=2.7,<3.0" },
{ version = "^6.2", python = "^3.7" } { version = "^6.2", python = ">=3.7,<4.0" }
] ]
pdoc = { version = "^7.1.1", python = "^3.7" } pdoc = { version = "^7.1.1", python = "^3.7" }
mypy = { version = "^0.910", python = "^3.6" } mypy = { version = "^0.910", python = "^3.6" }
black = { version = "^21.7b0", python = "^3.6" } black = [{ version = "^21.*", python = ">=3.6.2,<4.0" }]
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]
......
...@@ -442,18 +442,14 @@ from .statement import * ...@@ -442,18 +442,14 @@ from .statement import *
from .subscription import * from .subscription import *
from .schemaless import * from .schemaless import *
try: from taos._version import __version__
import importlib.metadata
__version__ = importlib.metadata.version("taos")
except:
None
# Globals # Globals
threadsafety = 0 threadsafety = 0
paramstyle = "pyformat" paramstyle = "pyformat"
__all__ = [ __all__ = [
"__version__",
# functions # functions
"connect", "connect",
"new_bind_param", "new_bind_param",
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
import ctypes import ctypes
import platform import platform
import sys import inspect
from ctypes import * from ctypes import *
try: try:
from typing import Any from typing import Any
except: except:
...@@ -14,6 +15,7 @@ from .bind import * ...@@ -14,6 +15,7 @@ from .bind import *
from .field import * from .field import *
from .schemaless import * from .schemaless import *
_UNSUPPORTED = {}
# stream callback # stream callback
stream_callback_type = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p) stream_callback_type = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p)
...@@ -47,10 +49,13 @@ def _load_taos(): ...@@ -47,10 +49,13 @@ def _load_taos():
"Darwin": _load_taos_darwin, "Darwin": _load_taos_darwin,
"Windows": _load_taos_windows, "Windows": _load_taos_windows,
} }
pf = platform.system()
if load_func[pf] is None:
raise InterfaceError("unsupported platform: %s" % pf)
try: try:
return load_func[platform.system()]() return load_func[pf]()
except: except Exception as err:
raise InterfaceError('unsupported platform or failed to load taos client library') raise InterfaceError("unable to load taos C library: %s" % err)
_libtaos = _load_taos() _libtaos = _load_taos()
...@@ -65,7 +70,6 @@ _libtaos.taos_consume.restype = ctypes.c_void_p ...@@ -65,7 +70,6 @@ _libtaos.taos_consume.restype = ctypes.c_void_p
_libtaos.taos_fetch_lengths.restype = ctypes.POINTER(ctypes.c_int) _libtaos.taos_fetch_lengths.restype = ctypes.POINTER(ctypes.c_int)
_libtaos.taos_free_result.restype = None _libtaos.taos_free_result.restype = None
_libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p) _libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p)
_libtaos.taos_schemaless_insert.restype = ctypes.c_void_p
try: try:
_libtaos.taos_stmt_errstr.restype = c_char_p _libtaos.taos_stmt_errstr.restype = c_char_p
...@@ -181,6 +185,7 @@ def taos_connect(host=None, user="root", password="taosdata", db=None, port=0): ...@@ -181,6 +185,7 @@ def taos_connect(host=None, user="root", password="taosdata", db=None, port=0):
raise ConnectionError("connect to TDengine failed") raise ConnectionError("connect to TDengine failed")
return connection return connection
_libtaos.taos_connect_auth.restype = c_void_p _libtaos.taos_connect_auth.restype = c_void_p
_libtaos.taos_connect_auth.argtypes = c_char_p, c_char_p, c_char_p, c_char_p, c_uint16 _libtaos.taos_connect_auth.argtypes = c_char_p, c_char_p, c_char_p, c_char_p, c_uint16
...@@ -236,6 +241,7 @@ def taos_connect_auth(host=None, user="root", auth="", db=None, port=0): ...@@ -236,6 +241,7 @@ def taos_connect_auth(host=None, user="root", auth="", db=None, port=0):
raise ConnectionError("connect to TDengine failed") raise ConnectionError("connect to TDengine failed")
return connection return connection
_libtaos.taos_query.restype = c_void_p _libtaos.taos_query.restype = c_void_p
_libtaos.taos_query.argtypes = c_void_p, c_char_p _libtaos.taos_query.argtypes = c_void_p, c_char_p
...@@ -287,6 +293,7 @@ def taos_affected_rows(result): ...@@ -287,6 +293,7 @@ def taos_affected_rows(result):
"""The affected rows after runing query""" """The affected rows after runing query"""
return _libtaos.taos_affected_rows(result) return _libtaos.taos_affected_rows(result)
subscribe_callback_type = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p, c_int) subscribe_callback_type = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p, c_int)
_libtaos.taos_subscribe.restype = c_void_p _libtaos.taos_subscribe.restype = c_void_p
# _libtaos.taos_subscribe.argtypes = c_void_p, c_int, c_char_p, c_char_p, subscribe_callback_type, c_void_p, c_int # _libtaos.taos_subscribe.argtypes = c_void_p, c_int, c_char_p, c_char_p, subscribe_callback_type, c_void_p, c_int
...@@ -317,7 +324,7 @@ def taos_subscribe(connection, restart, topic, sql, interval, callback=None, par ...@@ -317,7 +324,7 @@ def taos_subscribe(connection, restart, topic, sql, interval, callback=None, par
_libtaos.taos_consume.restype = c_void_p _libtaos.taos_consume.restype = c_void_p
_libtaos.taos_consume.argstype = c_void_p, _libtaos.taos_consume.argstype = (c_void_p,)
def taos_consume(sub): def taos_consume(sub):
...@@ -503,13 +510,17 @@ def taos_stop_query(result): ...@@ -503,13 +510,17 @@ def taos_stop_query(result):
return _libtaos.taos_stop_query(result) return _libtaos.taos_stop_query(result)
_libtaos.taos_load_table_info.restype = c_int try:
_libtaos.taos_load_table_info.argstype = (c_void_p, c_char_p) _libtaos.taos_load_table_info.restype = c_int
_libtaos.taos_load_table_info.argstype = (c_void_p, c_char_p)
except Exception as err:
_UNSUPPORTED["taos_open_stream"] = err
def taos_load_table_info(connection, tables): def taos_load_table_info(connection, tables):
# type: (ctypes.c_void_p, str) -> None # type: (ctypes.c_void_p, str) -> None
"""Stop current query""" """Stop current query"""
_check_if_supported()
errno = _libtaos.taos_load_table_info(connection, c_char_p(tables.encode("utf-8"))) errno = _libtaos.taos_load_table_info(connection, c_char_p(tables.encode("utf-8")))
if errno != 0: if errno != 0:
msg = taos_errstr() msg = taos_errstr()
...@@ -562,12 +573,13 @@ def taos_select_db(connection, db): ...@@ -562,12 +573,13 @@ def taos_select_db(connection, db):
try: try:
_libtaos.taos_open_stream.restype = c_void_p _libtaos.taos_open_stream.restype = c_void_p
_libtaos.taos_open_stream.argstype = c_void_p, c_char_p, stream_callback_type, c_int64, c_void_p, Any _libtaos.taos_open_stream.argstype = c_void_p, c_char_p, stream_callback_type, c_int64, c_void_p, Any
except: except Exception as err:
pass _UNSUPPORTED["taos_open_stream"] = err
def taos_open_stream(connection, sql, callback, stime=0, param=None, callback2=None): def taos_open_stream(connection, sql, callback, stime=0, param=None, callback2=None):
# type: (ctypes.c_void_p, str, stream_callback_type, c_int64, c_void_p, c_void_p) -> ctypes.pointer # type: (ctypes.c_void_p, str, stream_callback_type, c_int64, c_void_p, c_void_p) -> ctypes.pointer
_check_if_supported()
if callback2 != None: if callback2 != None:
callback2 = stream_callback2_type(callback2) callback2 = stream_callback2_type(callback2)
"""Open an stream""" """Open an stream"""
...@@ -600,6 +612,7 @@ def taos_stmt_init(connection): ...@@ -600,6 +612,7 @@ def taos_stmt_init(connection):
""" """
return c_void_p(_libtaos.taos_stmt_init(connection)) return c_void_p(_libtaos.taos_stmt_init(connection))
_libtaos.taos_stmt_prepare.restype = c_int _libtaos.taos_stmt_prepare.restype = c_int
_libtaos.taos_stmt_prepare.argstype = (c_void_p, c_char_p, c_int) _libtaos.taos_stmt_prepare.argstype = (c_void_p, c_char_p, c_int)
...@@ -618,6 +631,7 @@ def taos_stmt_prepare(stmt, sql): ...@@ -618,6 +631,7 @@ def taos_stmt_prepare(stmt, sql):
_libtaos.taos_stmt_close.restype = c_int _libtaos.taos_stmt_close.restype = c_int
_libtaos.taos_stmt_close.argstype = (c_void_p,) _libtaos.taos_stmt_close.argstype = (c_void_p,)
def taos_stmt_close(stmt): def taos_stmt_close(stmt):
# type: (ctypes.c_void_p) -> None # type: (ctypes.c_void_p) -> None
"""Close a statement query """Close a statement query
...@@ -627,17 +641,12 @@ def taos_stmt_close(stmt): ...@@ -627,17 +641,12 @@ def taos_stmt_close(stmt):
if res != 0: if res != 0:
raise StatementError(msg=taos_stmt_errstr(stmt), errno=res) raise StatementError(msg=taos_stmt_errstr(stmt), errno=res)
try:
_libtaos.taos_stmt_errstr.restype = c_char_p
_libtaos.taos_stmt_errstr.argstype = (c_void_p,)
except AttributeError:
print("WARNING: libtaos(%s) does not support taos_stmt_errstr" % taos_get_client_info())
try: try:
_libtaos.taos_stmt_errstr.restype = c_char_p _libtaos.taos_stmt_errstr.restype = c_char_p
_libtaos.taos_stmt_errstr.argstype = (c_void_p,) _libtaos.taos_stmt_errstr.argstype = (c_void_p,)
except AttributeError: except Exception as err:
print("WARNING: libtaos(%s) does not support taos_stmt_errstr" % taos_get_client_info()) _UNSUPPORTED["taos_stmt_set_tbname"] = err
def taos_stmt_errstr(stmt): def taos_stmt_errstr(stmt):
...@@ -645,16 +654,17 @@ def taos_stmt_errstr(stmt): ...@@ -645,16 +654,17 @@ def taos_stmt_errstr(stmt):
"""Get error message from stetement query """Get error message from stetement query
@stmt: c_void_p TAOS_STMT* @stmt: c_void_p TAOS_STMT*
""" """
_check_if_supported()
err = c_char_p(_libtaos.taos_stmt_errstr(stmt)) err = c_char_p(_libtaos.taos_stmt_errstr(stmt))
if err: if err:
return err.value.decode("utf-8") return err.value.decode("utf-8")
try: try:
_libtaos.taos_stmt_set_tbname.restype = c_int _libtaos.taos_stmt_set_tbname.restype = c_int
_libtaos.taos_stmt_set_tbname.argstype = (c_void_p, c_char_p) _libtaos.taos_stmt_set_tbname.argstype = (c_void_p, c_char_p)
except AttributeError: except Exception as err:
print("WARNING: libtaos(%s) does not support taos_stmt_set_tbname" % taos_get_client_info()) _UNSUPPORTED["taos_stmt_set_tbname"] = err
def taos_stmt_set_tbname(stmt, name): def taos_stmt_set_tbname(stmt, name):
...@@ -662,15 +672,17 @@ def taos_stmt_set_tbname(stmt, name): ...@@ -662,15 +672,17 @@ def taos_stmt_set_tbname(stmt, name):
"""Set table name of a statement query if exists. """Set table name of a statement query if exists.
@stmt: c_void_p TAOS_STMT* @stmt: c_void_p TAOS_STMT*
""" """
_check_if_supported()
res = _libtaos.taos_stmt_set_tbname(stmt, c_char_p(name.encode("utf-8"))) res = _libtaos.taos_stmt_set_tbname(stmt, c_char_p(name.encode("utf-8")))
if res != 0: if res != 0:
raise StatementError(msg=taos_stmt_errstr(stmt), errno=res) raise StatementError(msg=taos_stmt_errstr(stmt), errno=res)
try: try:
_libtaos.taos_stmt_set_tbname_tags.restype = c_int _libtaos.taos_stmt_set_tbname_tags.restype = c_int
_libtaos.taos_stmt_set_tbname_tags.argstype = (c_void_p, c_char_p, c_void_p) _libtaos.taos_stmt_set_tbname_tags.argstype = (c_void_p, c_char_p, c_void_p)
except AttributeError: except Exception as err:
print("WARNING: libtaos(%s) does not support taos_stmt_set_tbname_tags" % taos_get_client_info()) _UNSUPPORTED["taos_stmt_set_tbname_tags"] = err
def taos_stmt_set_tbname_tags(stmt, name, tags): def taos_stmt_set_tbname_tags(stmt, name, tags):
...@@ -678,11 +690,13 @@ def taos_stmt_set_tbname_tags(stmt, name, tags): ...@@ -678,11 +690,13 @@ def taos_stmt_set_tbname_tags(stmt, name, tags):
"""Set table name with tags bind params. """Set table name with tags bind params.
@stmt: c_void_p TAOS_STMT* @stmt: c_void_p TAOS_STMT*
""" """
_check_if_supported()
res = _libtaos.taos_stmt_set_tbname_tags(stmt, ctypes.c_char_p(name.encode("utf-8")), tags) res = _libtaos.taos_stmt_set_tbname_tags(stmt, ctypes.c_char_p(name.encode("utf-8")), tags)
if res != 0: if res != 0:
raise StatementError(msg=taos_stmt_errstr(stmt), errno=res) raise StatementError(msg=taos_stmt_errstr(stmt), errno=res)
_libtaos.taos_stmt_is_insert.restype = c_int _libtaos.taos_stmt_is_insert.restype = c_int
_libtaos.taos_stmt_is_insert.argstype = (c_void_p, POINTER(c_int)) _libtaos.taos_stmt_is_insert.argstype = (c_void_p, POINTER(c_int))
...@@ -702,6 +716,7 @@ def taos_stmt_is_insert(stmt): ...@@ -702,6 +716,7 @@ def taos_stmt_is_insert(stmt):
_libtaos.taos_stmt_num_params.restype = c_int _libtaos.taos_stmt_num_params.restype = c_int
_libtaos.taos_stmt_num_params.argstype = (c_void_p, POINTER(c_int)) _libtaos.taos_stmt_num_params.argstype = (c_void_p, POINTER(c_int))
def taos_stmt_num_params(stmt): def taos_stmt_num_params(stmt):
# type: (ctypes.c_void_p) -> int # type: (ctypes.c_void_p) -> int
"""Params number of the current statement query. """Params number of the current statement query.
...@@ -713,6 +728,7 @@ def taos_stmt_num_params(stmt): ...@@ -713,6 +728,7 @@ def taos_stmt_num_params(stmt):
raise StatementError(msg=taos_stmt_errstr(stmt), errno=res) raise StatementError(msg=taos_stmt_errstr(stmt), errno=res)
return num_params.value return num_params.value
_libtaos.taos_stmt_bind_param.restype = c_int _libtaos.taos_stmt_bind_param.restype = c_int
_libtaos.taos_stmt_bind_param.argstype = (c_void_p, c_void_p) _libtaos.taos_stmt_bind_param.argstype = (c_void_p, c_void_p)
...@@ -729,12 +745,12 @@ def taos_stmt_bind_param(stmt, bind): ...@@ -729,12 +745,12 @@ def taos_stmt_bind_param(stmt, bind):
if res != 0: if res != 0:
raise StatementError(msg=taos_stmt_errstr(stmt), errno=res) raise StatementError(msg=taos_stmt_errstr(stmt), errno=res)
try: try:
_libtaos.taos_stmt_bind_param_batch.restype = c_int _libtaos.taos_stmt_bind_param_batch.restype = c_int
_libtaos.taos_stmt_bind_param_batch.argstype = (c_void_p, c_void_p) _libtaos.taos_stmt_bind_param_batch.argstype = (c_void_p, c_void_p)
except AttributeError: except Exception as err:
print("WARNING: libtaos(%s) does not support taos_stmt_bind_param_batch" % taos_get_client_info()) _UNSUPPORTED["taos_stmt_bind_param_batch"] = err
def taos_stmt_bind_param_batch(stmt, bind): def taos_stmt_bind_param_batch(stmt, bind):
...@@ -745,15 +761,17 @@ def taos_stmt_bind_param_batch(stmt, bind): ...@@ -745,15 +761,17 @@ def taos_stmt_bind_param_batch(stmt, bind):
""" """
# ptr = ctypes.cast(bind, POINTER(TaosMultiBind)) # ptr = ctypes.cast(bind, POINTER(TaosMultiBind))
# ptr = pointer(bind) # ptr = pointer(bind)
_check_if_supported()
res = _libtaos.taos_stmt_bind_param_batch(stmt, bind) res = _libtaos.taos_stmt_bind_param_batch(stmt, bind)
if res != 0: if res != 0:
raise StatementError(msg=taos_stmt_errstr(stmt), errno=res) raise StatementError(msg=taos_stmt_errstr(stmt), errno=res)
try: try:
_libtaos.taos_stmt_bind_single_param_batch.restype = c_int _libtaos.taos_stmt_bind_single_param_batch.restype = c_int
_libtaos.taos_stmt_bind_single_param_batch.argstype = (c_void_p, c_void_p, c_int) _libtaos.taos_stmt_bind_single_param_batch.argstype = (c_void_p, c_void_p, c_int)
except AttributeError: except Exception as err:
print("WARNING: libtaos(%s) does not support taos_stmt_bind_single_param_batch" % taos_get_client_info()) _UNSUPPORTED["taos_stmt_bind_single_param_batch"] = err
def taos_stmt_bind_single_param_batch(stmt, bind, col): def taos_stmt_bind_single_param_batch(stmt, bind, col):
...@@ -763,6 +781,7 @@ def taos_stmt_bind_single_param_batch(stmt, bind, col): ...@@ -763,6 +781,7 @@ def taos_stmt_bind_single_param_batch(stmt, bind, col):
@bind: TAOS_MULTI_BIND* @bind: TAOS_MULTI_BIND*
@col: column index @col: column index
""" """
_check_if_supported()
res = _libtaos.taos_stmt_bind_single_param_batch(stmt, bind, col) res = _libtaos.taos_stmt_bind_single_param_batch(stmt, bind, col)
if res != 0: if res != 0:
raise StatementError(msg=taos_stmt_errstr(stmt), errno=res) raise StatementError(msg=taos_stmt_errstr(stmt), errno=res)
...@@ -810,14 +829,17 @@ def taos_stmt_use_result(stmt): ...@@ -810,14 +829,17 @@ def taos_stmt_use_result(stmt):
raise StatementError(taos_stmt_errstr(stmt)) raise StatementError(taos_stmt_errstr(stmt))
return result return result
try: try:
_libtaos.taos_schemaless_insert.restype = c_void_p _libtaos.taos_schemaless_insert.restype = c_void_p
_libtaos.taos_schemaless_insert.argstype = c_void_p, c_void_p, c_int, c_int, c_int _libtaos.taos_schemaless_insert.argstype = c_void_p, c_void_p, c_int, c_int, c_int
except AttributeError: except Exception as err:
print("WARNING: libtaos(%s) does not support taos_schemaless_insert" % taos_get_client_info()) _UNSUPPORTED["taos_schemaless_insert"] = err
def taos_schemaless_insert(connection, lines, protocol, precision): def taos_schemaless_insert(connection, lines, protocol, precision):
# type: (c_void_p, list[str] | tuple(str), SmlProtocol, SmlPrecision) -> int # type: (c_void_p, list[str] | tuple(str), SmlProtocol, SmlPrecision) -> int
_check_if_supported()
num_of_lines = len(lines) num_of_lines = len(lines)
lines = (c_char_p(line.encode("utf-8")) for line in lines) lines = (c_char_p(line.encode("utf-8")) for line in lines)
lines_type = ctypes.c_char_p * num_of_lines lines_type = ctypes.c_char_p * num_of_lines
...@@ -833,6 +855,18 @@ def taos_schemaless_insert(connection, lines, protocol, precision): ...@@ -833,6 +855,18 @@ def taos_schemaless_insert(connection, lines, protocol, precision):
taos_free_result(res) taos_free_result(res)
return affected_rows return affected_rows
def _check_if_supported():
func = inspect.stack()[1][3]
if func in _UNSUPPORTED:
raise InterfaceError("C function %s is not supported in v%s: %s" % (func, taos_get_client_info(), _UNSUPPORTED[func]))
def unsupported_methods():
for m, e in range(_UNSUPPORTED):
print("unsupported %s: %s", m, e)
class CTaosInterface(object): class CTaosInterface(object):
def __init__(self, config=None): def __init__(self, config=None):
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册