Files

149 lines
4.8 KiB
Python
Raw Permalink Normal View History

# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.
#
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
2020-06-24 14:25:28 -05:00
2022-10-04 00:15:18 +05:30
2024-01-19 16:17:32 -05:00
from typing import Any
2020-06-24 14:25:28 -05:00
import nox
SOURCE_FILES = (
"setup.py",
"noxfile.py",
2021-09-16 14:59:29 +05:30
"opensearchpy/",
"test_opensearchpy/",
2020-06-24 14:25:28 -05:00
"utils/",
"samples/",
"benchmarks/",
"docs/",
2020-06-24 14:25:28 -05:00
)
@nox.session(python=["3.8", "3.9", "3.10", "3.11", "3.12"]) # type: ignore
def test(session: Any) -> None:
2024-01-19 13:36:05 -05:00
"""
runs all tests with a fresh python environment using "python setup.py test"
:param session: current nox session
"""
2020-06-24 14:25:28 -05:00
session.install(".")
2023-11-15 19:33:43 -05:00
# ensure client can be imported without aiohttp
session.run("python", "-c", "import opensearchpy\nprint(opensearchpy.OpenSearch())")
# ensure client can be imported with aiohttp
session.install(".[async]")
session.run(
"python", "-c", "import opensearchpy\nprint(opensearchpy.AsyncOpenSearch())"
)
2020-06-24 14:25:28 -05:00
session.install("-r", "dev-requirements.txt")
session.run("python", "setup.py", "test")
@nox.session(python=["3.8"]) # type: ignore
def format(session: Any) -> None:
2024-01-19 13:36:05 -05:00
"""
runs black and isort to format the files accordingly
:param session: current nox session
"""
2023-11-21 13:04:39 -05:00
session.install(".")
session.install("black", "isort")
2020-06-24 14:25:28 -05:00
2023-11-21 13:04:39 -05:00
session.run("isort", *SOURCE_FILES)
session.run("black", *SOURCE_FILES)
session.run("python", "utils/license_headers.py", "fix", *SOURCE_FILES)
2020-06-24 14:25:28 -05:00
session.notify("lint")
2020-06-24 14:25:28 -05:00
@nox.session(python=["3.8"]) # type: ignore
def lint(session: Any) -> None:
2024-01-19 13:36:05 -05:00
"""
runs isort, black, flake8, pylint, and mypy to check the files according to each utility's function
:param session: current nox session
"""
2023-11-06 13:08:19 -05:00
session.install(
"flake8",
"black",
"mypy",
"isort",
2023-11-21 13:04:39 -05:00
"pylint",
2023-11-06 13:08:19 -05:00
"types-requests",
"types-simplejson",
"types-python-dateutil",
"types-PyYAML",
"types-pytz",
2023-11-06 13:08:19 -05:00
)
2020-06-24 14:25:28 -05:00
2023-11-21 13:04:39 -05:00
session.run("isort", "--check", *SOURCE_FILES)
session.run("black", "--check", *SOURCE_FILES)
2020-06-24 14:25:28 -05:00
session.run("flake8", *SOURCE_FILES)
2024-01-19 13:36:05 -05:00
2024-01-19 16:17:32 -05:00
pylint_overrides = ["opensearchpy/", "test_opensearchpy/"]
pylint_defaults = [file for file in SOURCE_FILES if file not in pylint_overrides]
for file in pylint_overrides:
session.run("pylint", "--rcfile", f"{file}.pylintrc", f"{file}")
session.run("pylint", "--rcfile", ".pylintrc", *pylint_defaults)
2024-01-19 13:36:05 -05:00
2023-11-21 13:04:39 -05:00
session.run("python", "utils/license_headers.py", "check", *SOURCE_FILES)
2020-06-24 14:25:28 -05:00
# Workaround to make '-r' to still work despite uninstalling aiohttp below.
session.run("python", "-m", "pip", "install", "aiohttp")
# Run mypy on the package and then the type examples separately for
# the two different mypy use-cases, ourselves and our users.
session.run("mypy", "--strict", *SOURCE_FILES)
2021-09-16 14:59:29 +05:30
session.run("mypy", "--strict", "test_opensearchpy/test_types/sync_types.py")
session.run("mypy", "--strict", "test_opensearchpy/test_types/async_types.py")
# Make sure we don't require aiohttp to be installed for users to
# receive type hint information from mypy.
2020-10-13 15:18:07 -05:00
session.run("python", "-m", "pip", "uninstall", "--yes", "aiohttp")
2021-09-16 14:59:29 +05:30
session.run("mypy", "--strict", "opensearchpy/")
session.run("mypy", "--strict", "test_opensearchpy/test_types/sync_types.py")
2020-06-24 14:25:28 -05:00
@nox.session() # type: ignore
def docs(session: Any) -> None:
2024-01-19 13:36:05 -05:00
"""
builds the html documentation for the client
:param session: current nox session
"""
2020-06-24 14:25:28 -05:00
session.install(".")
session.install(".[docs]")
with session.chdir("docs"):
session.run("make", "html")
@nox.session() # type: ignore
def generate(session: Any) -> None:
2024-01-19 13:36:05 -05:00
"""
generates the base API code
:param session: current nox session
"""
session.install("-rdev-requirements.txt")
2023-11-21 13:04:39 -05:00
session.run("python", "utils/generate_api.py")
session.run("nox", "-s", "format", external=True)
session.run("python", "utils/changelog_updater.py")