2022-04-05 14:06:54 -07:00
- [Developer Guide ](#developer-guide )
2023-05-30 13:40:05 -04:00
- [Prerequisites ](#prerequisites )
2023-07-05 12:49:31 -04:00
- [Docker Image Installation ](#docker-setup )
2023-05-30 13:40:05 -04:00
- [Running Tests ](#running-tests )
2023-07-05 12:49:31 -04:00
- [Integration Tests ](#integration-tests )
2023-05-30 13:40:05 -04:00
- [Documentation ](#documentation )
2023-06-27 11:56:55 -07:00
- [Running Python Client Generator ](#running-python-client-generator )
2022-04-05 14:06:54 -07:00
2022-01-19 21:44:52 +01:00
# Developer Guide
2023-05-30 13:40:05 -04:00
## Prerequisites
Python 3.6 or newer is required.
```
$ python --version
Python 3.11.1
```
2023-07-26 12:18:45 -05:00
You can install dev requirements with `pip install -r dev-requirements.txt` , but it's better to use the docker setup described below.
2023-05-30 13:40:05 -04:00
Install [Nox ](https://nox.thea.codes/en/stable/ ) for task management.
2021-08-31 19:42:26 +05:30
```
$ python -m pip install nox
2023-05-30 13:40:05 -04:00
```
2021-08-31 19:42:26 +05:30
2023-07-05 12:49:31 -04:00
## Install Docker Image
Integration tests require [docker ](https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/ ).
Run the following commands to install the docker image:
```
docker pull opensearchproject/opensearch:latest
```
Integration tests will auto-start the docker image. To start it manually:
```
docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:latest
```
2023-05-30 13:40:05 -04:00
## Running Tests
2021-08-31 19:42:26 +05:30
2023-05-30 13:40:05 -04:00
Tests require a live instance of OpenSearch running in docker.
2023-10-23 19:46:19 -04:00
If you have one running.
```
python setup.py test
```
To run tests in a specific test file.
```
python setup.py test -s test_opensearchpy/test_connection.py
```
If you want to auto-start one, the following will start a new instance and run tests against the latest version of OpenSearch.
2023-05-30 13:40:05 -04:00
```
./.ci/run-tests
```
If your OpenSearch docker instance is running, you can execute the test suite directly.
```
2021-08-31 19:42:26 +05:30
$ nox -rs test
```
2023-05-30 13:40:05 -04:00
To run tests against different versions of OpenSearch, use `run-tests [with/without security] [version]` :
2021-08-31 19:42:26 +05:30
```
2022-10-18 11:30:21 -07:00
./.ci/run-tests true 1.3.0
2021-08-31 19:42:26 +05:30
```
2023-05-30 13:40:05 -04:00
The first argument tells whether to run server with security plugin enabled or not. The second argument specifies the version of OpenSearch the tests should run against, if not specified, the tests run against the latest version. You can also run tests against a current SNAPSHOT.
The following example runs tests against the latest SNAPSHOT build of OpenSearch without security.
```
./.ci/run-tests opensearch false SNAPSHOT
```
2021-08-31 19:42:26 +05:30
2023-07-26 12:18:45 -05:00
You can also run individual tests matching a pattern (`pytest -k [pattern]` ).
```
./.ci/run-tests true 1.3.0 test_no_http_compression
2023-10-23 19:46:19 -04:00
test_opensearchpy/test_connection.py::TestUrllib3HttpConnection::test_no_http_compression PASSED [ 33%]
2023-07-26 12:18:45 -05:00
test_opensearchpy/test_connection.py::TestRequestsConnection::test_no_http_compression PASSED [ 66%]
test_opensearchpy/test_async/test_connection.py::TestAIOHttpConnection::test_no_http_compression PASSED [100%]
```
2021-08-31 19:42:26 +05:30
Note that integration tests require docker to be installed and running, and downloads quite a bit of data from over the internet and hence take few minutes to complete.
2022-01-19 21:44:52 +01:00
2023-05-30 13:40:05 -04:00
## Linter
Run the linter and test suite to ensure your changes do not break existing code. The following will auto-format your changes.
```
$ nox -rs format
```
## Documentation
To build the documentation with [Sphinx ](https://www.sphinx-doc.org/ ).
```
pip install -e .[docs]
cd docs
make html
```
2022-01-19 21:44:52 +01:00
2023-05-30 13:40:05 -04:00
Open `opensearch-py/docs/build/html/index.html` to see results.
2023-06-27 11:56:55 -07:00
## Running Python Client Generator
The following code executes a python client generator that updates the client by utilizing the [openapi specifications ](https://github.com/opensearch-project/opensearch-api-specification/blob/main/OpenSearch.openapi.json ) found in the "opensearch-api-specification" repository. This process allows for the automatic generation and synchronization of the client code with the latest API specifications.
```
cd opensearch-py
python utils/generate-api.py
2023-08-02 15:00:20 -07:00
nox -rs format
2023-06-27 11:56:55 -07:00
```