Skip to content

Commit

Permalink
Merge branch 'master' into dismiss-build-error
Browse files Browse the repository at this point in the history
  • Loading branch information
aisk authored Apr 9, 2024
2 parents dc3a08e + a66b339 commit 5dc0172
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ on:
jobs:
build:

runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"]
os: ["ubuntu-20.04", "windows-latest"]

steps:
- uses: actions/checkout@v3
Expand All @@ -28,7 +29,6 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest pytest-asyncio cython
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
15 changes: 11 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,33 @@
# pypy detection
PYPY = "__pypy__" in sys.modules
UNIX = platform.system() in ("Linux", "Darwin")
WINDOWS = platform.system() == "Windows"

# only build ext in CPython with UNIX platform
if UNIX and not PYPY:
# only build ext in CPython
if not PYPY:
from Cython.Build import cythonize
cythonize("thriftpy2/transport/cybase.pyx")
cythonize("thriftpy2/transport/**/*.pyx")
cythonize("thriftpy2/protocol/cybin/cybin.pyx")

libraries = []
if WINDOWS:
libraries.append("Ws2_32")

ext_modules.append(Extension("thriftpy2.transport.cybase",
["thriftpy2/transport/cybase.c"]))
ext_modules.append(Extension("thriftpy2.transport.buffered.cybuffered",
["thriftpy2/transport/buffered/cybuffered.c"]))
ext_modules.append(Extension("thriftpy2.transport.memory.cymemory",
["thriftpy2/transport/memory/cymemory.c"]))
ext_modules.append(Extension("thriftpy2.transport.framed.cyframed",
["thriftpy2/transport/framed/cyframed.c"]))
["thriftpy2/transport/framed/cyframed.c"],
libraries=libraries))
ext_modules.append(Extension("thriftpy2.transport.sasl.cysasl",
["thriftpy2/transport/sasl/cysasl.c"]))
ext_modules.append(Extension("thriftpy2.protocol.cybin",
["thriftpy2/protocol/cybin/cybin.c"]))
["thriftpy2/protocol/cybin/cybin.c"],
libraries=libraries))

setup(name="thriftpy2",
version=version,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import os
import sys
import asyncio
# import uvloop
import threading
Expand All @@ -26,6 +27,12 @@
from thriftpy2.transport import TTransportException
from thriftpy2.thrift import TApplicationException


if sys.platform == "win32":
pytest.skip("Unix domain socket is not supported on Windows",
allow_module_level=True)


addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__),
"addressbook.thrift"))

Expand Down
6 changes: 6 additions & 0 deletions tests/test_all_protocols_binary_field.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import

import sys
import time
import traceback
from multiprocessing import Process
Expand All @@ -24,6 +25,11 @@
make_client as make_rpc_client
from thriftpy2.transport import TBufferedTransportFactory, TCyMemoryBuffer


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)


protocols = [TApacheJSONProtocolFactory,
TJSONProtocolFactory,
TBinaryProtocolFactory,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_apache_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import absolute_import

import json
import sys
import time
from multiprocessing import Process

Expand Down Expand Up @@ -126,6 +127,7 @@ def test(t):
json.loads(final_data.decode('utf8'))[4]['0']


@pytest.mark.skipif(sys.platform == "win32", reason="this test requires fork")
@pytest.mark.parametrize('server_func', [(make_rpc_server, make_rpc_client),
(make_http_server, make_http_client)])
def test_client(server_func):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_buffered_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import logging
import multiprocessing
import sys
import time

from os import path

import pytest
from unittest import TestCase

import thriftpy2
Expand Down Expand Up @@ -43,6 +45,7 @@ def get(self, name):
return self.registry[name]


@pytest.mark.skipif(sys.platform == "win32", reason="requires fork")
class BufferedTransportTestCase(TestCase):
TRANSPORT_FACTORY = TBufferedTransportFactory()
PROTOCOL_FACTORY = TBinaryProtocolFactory()
Expand Down
7 changes: 4 additions & 3 deletions tests/test_cytransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import pytest

from thriftpy2._compat import PYPY
from thriftpy2._compat import CYTHON

pytestmark = pytest.mark.skipif(PYPY, reason="cython not enabled in pypy.")

if not PYPY:
if CYTHON:
from thriftpy2.transport.framed import TCyFramedTransport
from thriftpy2.transport.buffered import TCyBufferedTransport
from thriftpy2.transport import TMemoryBuffer, TTransportException
else:
pytest.skip("cython not enabled.", allow_module_level=True)


def test_transport_mismatch():
Expand Down
10 changes: 9 additions & 1 deletion tests/test_framed_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

import logging
import socket
import sys
import threading
import time

from os import path
from unittest import TestCase

import pytest
from tornado import ioloop

import thriftpy2
from thriftpy2._compat import CYTHON
from thriftpy2.tornado import make_server
from thriftpy2.rpc import make_client
from thriftpy2.transport.framed import TFramedTransportFactory
Expand All @@ -23,7 +26,12 @@
except ImportError:
asyncio = None

from thriftpy2._compat import CYTHON

if sys.platform == "win32":
pytest.skip("add_socket is not implemented on Windiws",
allow_module_level=True)


logging.basicConfig(level=logging.INFO)

addressbook = thriftpy2.load(path.join(path.dirname(__file__),
Expand Down
5 changes: 5 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import multiprocessing
import socket
import sys
import time
import uuid

Expand All @@ -21,6 +22,10 @@
"addressbook.thrift"))


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)


class Dispatcher():
def __init__(self):
self.ab = addressbook.AddressBook()
Expand Down
7 changes: 6 additions & 1 deletion tests/test_multiplexed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import absolute_import

import os
import multiprocessing
import os
import sys
import time

import pytest
Expand All @@ -19,6 +20,10 @@
from thriftpy2.transport import TBufferedTransportFactory, TServerSocket


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)


mux = thriftpy2.load(os.path.join(os.path.dirname(__file__),
"multiplexed.thrift"))
sock_path = "/tmp/thriftpy_test.sock"
Expand Down
10 changes: 9 additions & 1 deletion tests/test_oneway.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import sys
import time

import pytest

import multiprocessing
import thriftpy2
import time
from thriftpy2.rpc import make_client, make_server


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)


class Dispatcher(object):
def Test(self, req):
print("Get req msg: %s" % req)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_protocol_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_write_huge_struct():
proto.TBinaryProtocol(b).write_struct(item)


@pytest.mark.skipif(_compat.PYPY, reason="cybin can't be used in pypy")
@pytest.mark.skipif(not _compat.CYTHON, reason="cybin required")
def test_string_binary_equivalency():
from thriftpy2.protocol.binary import TBinaryProtocolFactory
from thriftpy2.protocol.cybin import TCyBinaryProtocolFactory
Expand Down
8 changes: 5 additions & 3 deletions tests/test_protocol_cybinary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import collections
import multiprocessing
import os
import sys
import time

import pytest

from thriftpy2._compat import PYPY
from thriftpy2._compat import CYTHON
from thriftpy2.thrift import TDecodeException, TPayload, TType
from thriftpy2.transport import TServerSocket, TSocket
from thriftpy2.utils import hexlify
if not PYPY:
if CYTHON:
from thriftpy2.protocol import cybin as proto
from thriftpy2.transport.buffered import TCyBufferedTransport
from thriftpy2.transport.memory import TCyMemoryBuffer
else:
pytest.skip("cython not enabled in pypy.", allow_module_level=True)
pytest.skip("cython not enabled.", allow_module_level=True)


class TItem(TPayload):
Expand Down Expand Up @@ -317,6 +318,7 @@ def test_skip_struct():
assert 123 == proto.read_val(b, TType.I32)


@pytest.mark.skipif(sys.platform == "win32", reason="Unix domain socket required")
def test_read_long_data():
val = 'z' * 97 * 1024

Expand Down
9 changes: 7 additions & 2 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from __future__ import absolute_import

import os
import multiprocessing
import os
import socket
import time
import ssl
import sys
import time

import pytest

Expand All @@ -19,6 +20,10 @@
from thriftpy2.thrift import TApplicationException # noqa


if sys.platform == "win32":
pytest.skip("requires unix domain socket", allow_module_level=True)


addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__),
"addressbook.thrift"))
unix_sock = "/tmp/thriftpy_test.sock"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def test_inet6_socket():
@pytest.mark.skipif(
sys.platform == 'darwin' and os.getuid() != 0,
reason='os.mknod() requires super-user privileges on darwin')
@pytest.mark.skipif(sys.platform == "win32",
reason="os.mknod is missing on Windows")
def test_unix_domain_socket():
sock_file = "/tmp/thriftpy_test.sock"

Expand Down
5 changes: 5 additions & 0 deletions tests/test_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
import logging
import socket

import pytest
from tornado import gen, testing

import thriftpy2
from thriftpy2.tornado import make_client
from thriftpy2.tornado import make_server
from thriftpy2.transport import TTransportException

if sys.platform == "win32":
pytest.skip("add_socket is not implemented on Windiws",
allow_module_level=True)

logging.basicConfig(level=logging.INFO)

addressbook = thriftpy2.load(path.join(path.dirname(__file__),
Expand Down
6 changes: 6 additions & 0 deletions tests/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import pickle
import random
import socket
import sys
import tempfile
import time

Expand Down Expand Up @@ -57,6 +58,11 @@
else:
cleanup_on_sigterm()


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)


addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__),
"addressbook.thrift"))
_, db_file = tempfile.mkstemp()
Expand Down
2 changes: 1 addition & 1 deletion thriftpy2/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
PYPY = "__pypy__" in sys.modules

UNIX = platform.system() in ("Linux", "Darwin")
CYTHON = UNIX and not PYPY # Cython always disabled in pypy and windows
CYTHON = not PYPY # Cython always disabled in pypy
Loading

0 comments on commit 5dc0172

Please sign in to comment.