Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
cocolato committed Jul 15, 2024
2 parents 1042bc6 + 8e226b1 commit c7abcdd
Show file tree
Hide file tree
Showing 25 changed files with 411 additions and 208 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pip-log.txt
env/
.vscode/

# lock file
*.lock

pyvenv.cfg
share/*

Expand Down
41 changes: 37 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
Changelog
=========

0.5.x
~~~~~

Version 0.5.2
-------------

Released on Jul 5, 2024.

- Fix an issue where loading a thrift file in a sub-thread will cause an error with ``load_fp``.
- Move static metadata from ``setup.py`` to ``pyproject.toml``.
- Using a thread pool to avoid ``TAsyncSocket.open`` block the event loop.


Version 0.5.1
-------------

Released on Jun 24, 2024.

- Fix an issue where loading a thrift file in a sub-thread will cause an error.
- Some typo fixes.

Version 0.5.0
-------------

Released on May 7, 2024.

- Dropped Python2 and Python3.5 Support.
- Added SASL transport client.
- Add submodule to sys.path when loading child idl file.
- Support cythonized module on Windows.
- Support using ipv6 in make_client/make_server method.
- Basic multi-thread support in parser.

0.4.x
~~~~~

Expand Down Expand Up @@ -165,7 +198,7 @@ Version 0.4.5
Released on August 27, 2019.

- Support kwargs style parameters passing in TSimpleServer, via `2-#67`_.
- Fix #65 allow double const to ommit integer part, via `2-#66`_.
- Fix #65 allow double const to omit integer part, via `2-#66`_.

.. _2-#67: https://github.com/Thriftpy/thriftpy2/pull/67
.. _2-#66: https://github.com/Thriftpy/thriftpy2/pull/66
Expand Down Expand Up @@ -441,7 +474,7 @@ Released on April 15, 2015.
- add limitation on thrift reserved keyword for compatible with upstream, via
`#115`_.
- bugfix EOF grammar error, via `#103`_.
- bugfix for mis-mach transport in client caused server crash, via `#119`_.
- bugfix for mismatch transport in client caused server crash, via `#119`_.
- bugfix for typedef on included thrift files, via `#121`_.

.. _`#96`: https://github.com/eleme/thriftpy/pull/96
Expand All @@ -467,7 +500,7 @@ Released on March 3, 2015.
- bugfix for transport clean in read_struct in cybin, via `#70`_.
- bugfix for large reading size in framed transport, via `#73`_.
- bugfix for cython build failed in older CentOS, via `#92`_.
- bugfix for thrift file version mis-match caused message corrupt in
- bugfix for thrift file version mismatch caused message corrupt in
`read_struct`, via `#95`_.

Non-Backward Compatible changes:
Expand Down Expand Up @@ -699,7 +732,7 @@ Released on June 7, 2014.
- disabled the magic import hook by default. and add install/remove
function to switch the hook on and off.
- reworked benchmark suit and add benchmark results.
- new `__init__` function code generator. get a noticable speed boost.
- new `__init__` function code generator. get a noticeable speed boost.
- bug fixes


Expand Down
54 changes: 53 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
[build-system]
requires = ["setuptools", "cython>=0.28.4,<4"]
requires = ["setuptools", "cython>=0.28.4,<4", "toml"]

[project]
name = "thriftpy2"
version = "0.5.2"
description = "Pure python implementation of Apache Thrift."
authors = [
{name = "ThriftPy Organization", email = "[email protected]"},
]
dependencies = [
"ply>=3.4,<4.0",
"six~=1.15",
]
requires-python = ">=3.6"
readme = "README.rst"
license = {file = "LICENSE"}
keywords = ["thrift python thriftpy thriftpy2"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development",
]

[project.urls]
Homepage = "https://thriftpy2.readthedocs.io/"
Source = "https://github.com/Thriftpy/thriftpy2"

[project.optional-dependencies]
dev = [
"flake8>=2.5",
"sphinx-rtd-theme>=0.1.9",
"sphinx>=1.3",
"pytest-reraise",
"pytest>=6.1.1,<8.2.0",
"tornado>=4.0,<7.0; python_version>='3.12'",
"tornado>=4.0,<6.0; python_version<'3.12'",
]

tornado = [
"tornado>=4.0,<7.0; python_version>='3.12'",
"tornado>=4.0,<6.0; python_version<'3.12'",
]
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[metadata]
license_files = LICENSE

[wheel]
universal = 1

Expand Down
68 changes: 10 additions & 58 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
import sys
import platform
import toml

from os.path import join, dirname
from setuptools import setup, find_packages, Extension

from setuptools import setup, find_packages
from setuptools.extension import Extension

with open(join(dirname(__file__), 'thriftpy2', '__init__.py'), 'r') as f:
version = re.match(r".*__version__ = '(.*?)'", f.read(), re.S).group(1)

install_requires = [
"ply>=3.4,<4.0",
"six~=1.15",
]

tornado_requires = [
"tornado>=4.0,<7.0; python_version>='3.12'",
"tornado>=4.0,<6.0; python_version<'3.12'",
]
meta = toml.load(join(dirname(__file__), 'pyproject.toml') )
install_requires = meta["project"]["dependencies"]
dev_requires = meta["project"]["optional-dependencies"]["dev"]
tornado_requires = meta["project"]["optional-dependencies"]["tornado"]

try:
from tornado import version as tornado_version
if tornado_version < '5.0':
tornado_requires.append("toro>=0.6")
dev_requires.append("toro>=0.6")
except ImportError:
# tornado will now only get installed and we'll get the newer one
pass

dev_requires = [
"flake8>=2.5",
"pytest>=2.8",
"sphinx-rtd-theme>=0.1.9",
"sphinx>=1.3",
"pytest>=6.1.1",
"multiprocess"
] + tornado_requires


cmdclass = {}
ext_modules = []

# pypy detection
Expand Down Expand Up @@ -71,48 +52,19 @@
libraries=libraries))
ext_modules.append(Extension("thriftpy2.transport.sasl.cysasl",
["thriftpy2/transport/sasl/cysasl.c"]))
ext_modules.append(Extension("thriftpy2.protocol.cybin",
ext_modules.append(Extension("thriftpy2.protocol.cybin.cybin",
["thriftpy2/protocol/cybin/cybin.c"],
libraries=libraries))

setup(name="thriftpy2",
version=version,
description="Pure python implementation of Apache Thrift.",
keywords="thrift python thriftpy thriftpy2",
author="ThriftPy Organization",
author_email="[email protected]",
setup(
packages=find_packages(exclude=['benchmark', 'docs', 'tests']),
entry_points={},
url="https://thriftpy2.readthedocs.io/",
project_urls={
"Source": "https://github.com/Thriftpy/thriftpy2",
},
license="MIT",
zip_safe=False,
long_description=open("README.rst").read(),
install_requires=install_requires,
tests_require=tornado_requires,
python_requires='>=3.6',
extras_require={
"dev": dev_requires,
"tornado": tornado_requires
},
cmdclass=cmdclass,
ext_modules=ext_modules,
include_package_data=True,
classifiers=[
"Topic :: Software Development",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
])
)
2 changes: 1 addition & 1 deletion tests/addressbook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

"""This file is a demo for what the dynamiclly generated code would be like.
"""This file is a demo for what the dynamically generated code would be like.
"""

from thriftpy2.thrift import (
Expand Down
2 changes: 1 addition & 1 deletion tests/compatible/version_2/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, request_id, api, seq, client, server, status, start,
:status: request status
:start: start timestamp
:end: end timestamp
:annotation: application-level key-value datas
:annotation: application-level key-value data
"""
self.request_id = request_id
self.api = api
Expand Down
2 changes: 1 addition & 1 deletion tests/container.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

"""This file is a demo for what the dynamiclly generated code would be like.
"""This file is a demo for what the dynamically generated code would be like.
"""

from thriftpy2.thrift import (
Expand Down
65 changes: 49 additions & 16 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# -*- coding: utf-8 -*-
import asyncio
import os
import random
import socket
import sys
import asyncio
# import uvloop
import threading
import random
import time
from unittest.mock import patch

import pytest

import thriftpy2
from thriftpy2.contrib.aio.protocol import (TAsyncBinaryProtocolFactory,
TAsyncCompactProtocolFactory)
from thriftpy2.contrib.aio.transport import (TAsyncBufferedTransportFactory,
TAsyncFramedTransportFactory)
from thriftpy2.rpc import make_aio_client, make_aio_server
from thriftpy2.thrift import TApplicationException
from thriftpy2.transport import TTransportException

# asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

import time

import pytest

import thriftpy2

from thriftpy2.contrib.aio.transport import (
TAsyncBufferedTransportFactory,
TAsyncFramedTransportFactory,
)
from thriftpy2.contrib.aio.protocol import (
TAsyncBinaryProtocolFactory,
TAsyncCompactProtocolFactory,
)
from thriftpy2.rpc import make_aio_server, make_aio_client
from thriftpy2.transport import TTransportException
from thriftpy2.thrift import TApplicationException



if sys.platform == "win32":
Expand Down Expand Up @@ -113,6 +113,7 @@ class _TestAIO:
@classmethod
def setup_class(cls):
cls._start_server()
cls._start_ipv6_server()
cls.person = _create_person()

@classmethod
Expand All @@ -139,6 +140,22 @@ def _start_server(cls):
st.start()
time.sleep(0.1)

@classmethod
def _start_ipv6_server(cls):
cls.server = make_aio_server(
addressbook.AddressBookService,
Dispatcher(),
trans_factory=cls.TRANSPORT_FACTORY,
proto_factory=cls.PROTOCOL_FACTORY,
loop=asyncio.new_event_loop(),
socket_family=socket.AF_INET6,
**cls.server_kwargs(),
)
st = threading.Thread(target=cls.server.serve)
st.daemon = True
st.start()
time.sleep(0.1)

@classmethod
def server_kwargs(cls):
name = cls.__name__.lower()
Expand All @@ -157,12 +174,28 @@ async def client(self, timeout: int = 3000000):
**self.client_kwargs(),
)

async def ipv6_client(self, timeout: int = 3000000):
return await make_aio_client(
addressbook.AddressBookService,
trans_factory=self.TRANSPORT_FACTORY,
proto_factory=self.PROTOCOL_FACTORY,
timeout=timeout,
socket_family=socket.AF_INET6,
**self.client_kwargs(),
)

@pytest.mark.asyncio
async def test_void_api(self):
c = await self.client()
assert await c.ping() is None
c.close()

@pytest.mark.asyncio
async def test_api_ipv6(self):
c = await self.ipv6_client()
assert await c.ping() is None
c.close()

@pytest.mark.asyncio
async def test_string_api(self):
c = await self.client()
Expand Down
Loading

0 comments on commit c7abcdd

Please sign in to comment.