Skip to content

Commit

Permalink
Support Python 3.11, 3.12. Drop 3.7 (#121)
Browse files Browse the repository at this point in the history
* Support Python 3.9-3.12

* Skip unit tests that Python behabvior changed

* Make setup.py's version is the source of truth

* Fix pyopenssl handling

* Install self on test
  • Loading branch information
chezou authored Sep 6, 2024
1 parent f8f23bb commit b6da038
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/pythontest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
max-parallel: 4
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -20,6 +20,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install -r requirements.txt -r test-requirements.txt
pip install -U coveralls pyyaml
- name: Run test
Expand Down
22 changes: 6 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import os
import re
import sys

from setuptools import find_packages, setup
Expand All @@ -13,16 +12,6 @@ def read(fname):
return fp.read()


m = re.search(
r"^__version__ *= *\"([^\"]*)\" *$", read("tdclient/version.py"), re.MULTILINE
)

if m is None:
raise (RuntimeError("could not read tdclient/version.py"))
else:
version = m.group(1)


class PyTest(TestCommand):
user_options = [("pytest-args=", "a", "Arguments to pass to py.test")]

Expand All @@ -39,14 +28,14 @@ def run_tests(self):

setup(
name="td-client",
version=version,
version="1.2.2.dev0",
description="Treasure Data API library for Python",
long_description=read("README.rst"),
long_description_content_type="text/x-rst; charset=UTF-8",
author="Treasure Data, Inc.",
author_email="support@treasure-data.com",
url="http://treasuredata.com/",
python_requires=">=3.5",
python_requires=">=3.8",
install_requires=["msgpack>=0.6.2", "python-dateutil", "urllib3"],
tests_require=["coveralls", "mock", "pytest", "pytest-cov", "tox"],
extras_require={
Expand All @@ -64,10 +53,11 @@ def run_tests(self):
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Topic :: Internet",
"Programming Language :: Python :: 3.5",
"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",
],
Expand Down
3 changes: 2 additions & 1 deletion tdclient/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import socket
import ssl
import sys
import tempfile
import time
import urllib.parse as urlparse
Expand Down Expand Up @@ -506,7 +507,7 @@ def send_request(self, method, url, fields=None, body=None, headers=None, **kwar
body = memoryview(body)
if urllib3.util.IS_PYOPENSSL and isinstance(body, array):
# workaround for https://github.com/pyca/pyopenssl/issues/621
body = body.tostring()
body = body.tobytes()
return self.http.urlopen(method, url, body=body, headers=headers, **kwargs)

def raise_error(self, msg, res, body):
Expand Down
10 changes: 7 additions & 3 deletions tdclient/test/import_api_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python

import io
import json
import sys
import tempfile
import time
import zlib
from unittest import mock

import msgpack
import pytest

from tdclient import api
Expand Down Expand Up @@ -302,6 +300,9 @@ def import_data(db, table, format, stream, size, unique_id=None):
td.import_file("db", "table", "csv", stream)


@pytest.mark.skipif(
sys.version_info > (3, 11), reason="Python 3.11+ changed CSV behavior"
)
def test_import_file_csv_dict_failure():
td = api.API("APIKEY")
td.import_data = mock.MagicMock()
Expand Down Expand Up @@ -329,6 +330,9 @@ def import_data(db, table, format, stream, size, unique_id=None):
td.import_file("db", "table", "tsv", stream)


@pytest.mark.skipif(
sys.version_info > (3, 11), reason="Python 3.11+ changed CSV behavior"
)
def test_import_file_tsv_dict_failure():
td = api.API("APIKEY")
td.import_data = mock.MagicMock()
Expand Down
4 changes: 3 additions & 1 deletion tdclient/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__ = "1.2.2.dev0"
import importlib.metadata

__version__ = importlib.metadata.version("td-client")
23 changes: 13 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
[tox]
envlist = py{35,36,37,38,py}-{pyopenssl,no_pyopenssl},format
envlist = py{38,39,310,311,312,py}-{pyopenssl,no_pyopenssl},format

[testenv]
deps=-r{toxinidir}/test-requirements.txt
pyopenssl: pyopenssl
commands=pytest

[testenv:py35]
basepython=python3.5
[testenv:py38]
basepython=python3.9

[testenv:py36]
basepython=python3.6
[testenv:py39]
basepython=python3.9

[testenv:py37]
basepython=python3.7
[testenv:py310]
basepython=python3.10

[testenv:py38]
basepython=python3.8
[testenv:py311]
basepython=python3.11

[testenv:py312]
basepython=python3.12

[testenv:pypy]
basepython=pypy

[testenv:format]
basepython=python3.7
basepython=python3.8
deps=
-e.[dev]
-r{toxinidir}/test-requirements.txt
Expand Down

0 comments on commit b6da038

Please sign in to comment.