Skip to content

Commit

Permalink
Remove support for Python 2.x. (opensearch-project#548)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
Signed-off-by: roma2023 <[email protected]>
  • Loading branch information
dblock authored and roma2023 committed Dec 28, 2023
1 parent 93b4698 commit 2b164de
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 179 deletions.
3 changes: 0 additions & 3 deletions .ci/test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ TEST_SUITE:
- oss

PYTHON_VERSION:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Deprecated
- Deprecated point-in-time APIs (list_all_point_in_time, create_point_in_time, delete_point_in_time) and Security Client APIs (health_check and update_audit_config) ([#502](https://github.com/opensearch-project/opensearch-py/pull/502))
### Removed
- Removed leftover support for Python 2.7 ([#548](https://github.com/opensearch-project/opensearch-py/pull/548))
### Fixed
### Security
### Dependencies
Expand Down
11 changes: 5 additions & 6 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ pytz
numpy; python_version<"3.10"
pandas; python_version<"3.10"

pyyaml>=5.4; python_version>="3.6"
pyyaml==5.3.1; python_version<"3.6"
pyyaml>=5.4

isort
black; python_version>="3.6"
black
twine

# Requirements for testing [async] extra
aiohttp; python_version>="3.6"
pytest-asyncio<=0.21.1; python_version>="3.6"
unasync; python_version>="3.6"
aiohttp
pytest-asyncio<=0.21.1
unasync
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)


@nox.session(python=["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"])
@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"])
def test(session):
session.install(".")
session.install("-r", "dev-requirements.txt")
Expand Down
29 changes: 11 additions & 18 deletions opensearchpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,22 +248,15 @@
"tokenizer",
]

try:
# Asyncio only supported on Python 3.6+
if sys.version_info < (3, 6):
raise ImportError
from ._async.client import AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection
from ._async.transport import AsyncTransport
from .connection import AsyncHttpConnection

from ._async.client import AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection
from ._async.transport import AsyncTransport
from .connection import AsyncHttpConnection

__all__ += [
"AIOHttpConnection",
"AsyncConnection",
"AsyncTransport",
"AsyncOpenSearch",
"AsyncHttpConnection",
]
except (ImportError, SyntaxError):
pass
__all__ += [
"AIOHttpConnection",
"AsyncConnection",
"AsyncTransport",
"AsyncOpenSearch",
"AsyncHttpConnection",
]
19 changes: 6 additions & 13 deletions opensearchpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import sys
from typing import Tuple

from ._async.client import AsyncOpenSearch as AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection as AIOHttpConnection
from ._async.http_aiohttp import AsyncConnection as AsyncConnection
from ._async.transport import AsyncTransport as AsyncTransport
from .client import OpenSearch as OpenSearch
from .connection import AsyncHttpConnection as AsyncHttpConnection
from .connection import Connection as Connection
Expand Down Expand Up @@ -54,6 +58,8 @@ from .exceptions import SSLError as SSLError
from .exceptions import TransportError as TransportError
from .exceptions import UnknownDslObject as UnknownDslObject
from .exceptions import ValidationException as ValidationException
from .helpers import AWSV4SignerAsyncAuth as AWSV4SignerAsyncAuth
from .helpers import AWSV4SignerAuth as AWSV4SignerAuth
from .helpers.aggs import A as A
from .helpers.analysis import Analyzer, CharFilter, Normalizer, TokenFilter, Tokenizer
from .helpers.document import Document as Document
Expand Down Expand Up @@ -120,19 +126,6 @@ from .helpers.wrappers import Range as Range
from .serializer import JSONSerializer as JSONSerializer
from .transport import Transport as Transport

try:
if sys.version_info < (3, 6):
raise ImportError

from ._async.client import AsyncOpenSearch as AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection as AIOHttpConnection
from ._async.http_aiohttp import AsyncConnection as AsyncConnection
from ._async.transport import AsyncTransport as AsyncTransport
from .helpers import AWSV4SignerAsyncAuth as AWSV4SignerAsyncAuth
from .helpers import AWSV4SignerAuth as AWSV4SignerAuth
except (ImportError, SyntaxError):
pass

VERSION: Tuple[int, int, int]
__version__: Tuple[int, int, int]
__versionstr__: str
17 changes: 2 additions & 15 deletions opensearchpy/connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
# under the License.


import sys

from .base import Connection
from .http_async import AsyncHttpConnection
from .http_requests import RequestsHttpConnection
from .http_urllib3 import Urllib3HttpConnection, create_ssl_context

Expand All @@ -36,17 +35,5 @@
"RequestsHttpConnection",
"Urllib3HttpConnection",
"create_ssl_context",
"AsyncHttpConnection",
]

try:
# Asyncio only supported on Python 3.6+
if sys.version_info < (3, 6):
raise ImportError

from .http_async import AsyncHttpConnection

__all__ += [
"AsyncHttpConnection",
]
except (ImportError, SyntaxError):
pass
24 changes: 10 additions & 14 deletions opensearchpy/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
# under the License.


import sys

from .._async.helpers.actions import (
async_bulk,
async_reindex,
async_scan,
async_streaming_bulk,
)
from .actions import (
_chunk_actions,
_process_bulk_chunk,
Expand Down Expand Up @@ -56,16 +60,8 @@
"AWSV4SignerAsyncAuth",
"RequestsAWSV4SignerAuth",
"Urllib3AWSV4SignerAuth",
"async_scan",
"async_bulk",
"async_reindex",
"async_streaming_bulk",
]


# Asyncio only supported on Python 3.6+
if sys.version_info >= (3, 6):
from .._async.helpers.actions import (
async_bulk,
async_reindex,
async_scan,
async_streaming_bulk,
)

__all__ += ["async_scan", "async_bulk", "async_reindex", "async_streaming_bulk"]
22 changes: 7 additions & 15 deletions opensearchpy/helpers/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

import sys

from .._async.helpers.actions import async_bulk as async_bulk
from .._async.helpers.actions import async_reindex as async_reindex
from .._async.helpers.actions import async_scan as async_scan
from .._async.helpers.actions import async_streaming_bulk as async_streaming_bulk
from .actions import _chunk_actions as _chunk_actions
from .actions import _process_bulk_chunk as _process_bulk_chunk
from .actions import bulk as bulk
Expand All @@ -34,20 +38,8 @@ from .actions import parallel_bulk as parallel_bulk
from .actions import reindex as reindex
from .actions import scan as scan
from .actions import streaming_bulk as streaming_bulk
from .asyncsigner import AWSV4SignerAsyncAuth as AWSV4SignerAsyncAuth
from .errors import BulkIndexError as BulkIndexError
from .errors import ScanError as ScanError

try:
# Asyncio only supported on Python 3.6+
if sys.version_info < (3, 6):
raise ImportError

from .._async.helpers.actions import async_bulk as async_bulk
from .._async.helpers.actions import async_reindex as async_reindex
from .._async.helpers.actions import async_scan as async_scan
from .._async.helpers.actions import async_streaming_bulk as async_streaming_bulk
from .asyncsigner import AWSV4SignerAsyncAuth as AWSV4SignerAsyncAuth
from .signer import AWSV4SignerAuth as AWSV4SignerAuth
from .signer import RequestsAWSV4SignerAuth, Urllib3AWSV4SignerAuth
except (ImportError, SyntaxError):
pass
from .signer import AWSV4SignerAuth as AWSV4SignerAuth
from .signer import RequestsAWSV4SignerAuth, Urllib3AWSV4SignerAuth
15 changes: 3 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


import re
import sys
from os.path import abspath, dirname, join

from setuptools import find_packages, setup
Expand All @@ -54,8 +53,7 @@
"requests>=2.4.0, <3.0.0",
"six",
"python-dateutil",
# ipaddress is included in stdlib since python 3.3
'ipaddress; python_version<"3.3"',
"certifi>=2022.12.07",
]
tests_require = [
"requests>=2.0.0, <3.0.0",
Expand All @@ -65,11 +63,9 @@
"pytest>=3.0.0",
"pytest-cov",
"pytz",
"botocore;python_version>='3.6'",
"botocore",
"pytest-mock<4.0.0",
]
if sys.version_info >= (3, 6):
tests_require.append("pytest-mock<4.0.0")
install_requires.append("certifi>=2022.12.07")

async_require = ["aiohttp>=3,<4"]

Expand Down Expand Up @@ -103,11 +99,6 @@
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
Expand Down
25 changes: 8 additions & 17 deletions test_opensearchpy/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,19 @@ def run_all(argv=None):
if test_pattern:
argv.append("-k %s" % test_pattern)
else:
ignores = []
# Python 3.6+ is required for async
if sys.version_info < (3, 6):
ignores.append("test_opensearchpy/test_async/")

ignores.extend(
[
"test_opensearchpy/test_server/",
"test_opensearchpy/test_server_secured/",
"test_opensearchpy/test_async/test_server/",
"test_opensearchpy/test_async/test_server_secured/",
]
)
ignores = [
"test_opensearchpy/test_server/",
"test_opensearchpy/test_server_secured/",
"test_opensearchpy/test_async/test_server/",
"test_opensearchpy/test_async/test_server_secured/",
]

# Jenkins/Github actions, only run server tests
if environ.get("TEST_TYPE") == "server":
test_dir = abspath(dirname(__file__))
if secured:
argv.append(join(test_dir, "test_server_secured"))
if sys.version_info >= (3, 6):
argv.append(join(test_dir, "test_async/test_server_secured"))
argv.append(join(test_dir, "test_async/test_server_secured"))
ignores.extend(
[
"test_opensearchpy/test_server/",
Expand All @@ -145,8 +137,7 @@ def run_all(argv=None):
)
else:
argv.append(join(test_dir, "test_server"))
if sys.version_info >= (3, 6):
argv.append(join(test_dir, "test_async/test_server"))
argv.append(join(test_dir, "test_async/test_server"))
ignores.extend(
[
"test_opensearchpy/test_server_secured/",
Expand Down
13 changes: 0 additions & 13 deletions test_opensearchpy/test_async/test_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.

import sys
import uuid

import pytest
Expand Down Expand Up @@ -42,9 +41,6 @@ async def test_aws_signer_async_as_http_auth(self):
assert "X-Amz-Date" in headers
assert "X-Amz-Security-Token" in headers

@pytest.mark.skipif(
sys.version_info < (3, 6), reason="AWSV4SignerAuth requires python3.6+"
)
async def test_aws_signer_async_when_region_is_null(self):
session = self.mock_session()

Expand All @@ -58,9 +54,6 @@ async def test_aws_signer_async_when_region_is_null(self):
AWSV4SignerAsyncAuth(session, "")
assert str(e.value) == "Region cannot be empty"

@pytest.mark.skipif(
sys.version_info < (3, 6), reason="AWSV4SignerAuth requires python3.6+"
)
async def test_aws_signer_async_when_credentials_is_null(self):
region = "us-west-1"

Expand All @@ -70,9 +63,6 @@ async def test_aws_signer_async_when_credentials_is_null(self):
AWSV4SignerAsyncAuth(None, region)
assert str(e.value) == "Credentials cannot be empty"

@pytest.mark.skipif(
sys.version_info < (3, 6), reason="AWSV4SignerAsyncAuth requires python3.6+"
)
async def test_aws_signer_async_when_service_is_specified(self):
region = "us-west-2"
service = "aoss"
Expand Down Expand Up @@ -100,9 +90,6 @@ def mock_session(self, disable_get_frozen=True):

return dummy_session

@pytest.mark.skipif(
sys.version_info < (3, 6), reason="AWSV4SignerAsyncAuth requires python3.6+"
)
async def test_aws_signer_async_frozen_credentials_as_http_auth(self):
region = "us-west-2"

Expand Down
Loading

0 comments on commit 2b164de

Please sign in to comment.