Skip to content

Commit

Permalink
[Backport 8.13] Ensure optional dependencies are optional (#2511)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0e6c4cd)

Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
  • Loading branch information
github-actions[bot] and pquentin committed Mar 27, 2024
1 parent cafa395 commit 833e779
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion elasticsearch/__init__.py
Expand Up @@ -65,7 +65,7 @@

try:
from .serializer import OrjsonSerializer
except ModuleNotFoundError:
except ImportError:
OrjsonSerializer = None # type: ignore[assignment,misc]

# Only raise one warning per deprecation message so as not
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/serializer.py
Expand Up @@ -45,7 +45,7 @@
from elastic_transport import OrjsonSerializer as _OrjsonSerializer

__all__.append("OrjsonSerializer")
except ModuleNotFoundError:
except ImportError:
_OrjsonSerializer = None # type: ignore[assignment,misc]


Expand Down
7 changes: 5 additions & 2 deletions noxfile.py
Expand Up @@ -84,14 +84,17 @@ def format(session):

@nox.session()
def lint(session):
session.install("flake8", "black~=24.0", "mypy", "isort", "types-requests")
# Check that importing the client still works without optional dependencies
session.install(".", env=INSTALL_ENV)
session.run("python", "-c", "from elasticsearch import Elasticsearch")
session.run("python", "-c", "from elasticsearch._otel import OpenTelemetry")

session.install("flake8", "black~=24.0", "mypy", "isort", "types-requests")
session.run("isort", "--check", "--profile=black", *SOURCE_FILES)
session.run("black", "--check", *SOURCE_FILES)
session.run("flake8", *SOURCE_FILES)
session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES)

# Workaround to make '-r' to still work despite uninstalling aiohttp below.
session.install(".[async,requests,orjson]", env=INSTALL_ENV)

# Run mypy on the package and then the type examples separately for
Expand Down

0 comments on commit 833e779

Please sign in to comment.