Skip to content

Commit

Permalink
Migrate project from pytools to poetry.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Nov 13, 2023
1 parent da436cb commit adf7212
Show file tree
Hide file tree
Showing 7 changed files with 2,263 additions and 207 deletions.
61 changes: 44 additions & 17 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,57 @@

# Developer Guide

## Prerequisites
## Forking and Cloning

Python 3.6 or newer is required.
Fork this repository on GitHub, and clone locally with `git clone`.


## Building

### Install Pyenv

Use pyenv to manage multiple versions of Python. This can be installed with [pyenv-installer](https://github.com/pyenv/pyenv-installer) on Linux and MacOS, and [pyenv-win](https://github.com/pyenv-win/pyenv-win#installation) on Windows.

```
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
```

### Install Python 3.6 or Newer

Python projects in this repository use at a minimum Python 3.6, but 3.9 is recommended for development. See the [Python Beginners Guide](https://wiki.python.org/moin/BeginnersGuide) if you have never worked with the language.

```
$ python --version
Python 3.11.1
Python 3.9.16
```

You can install dev requirements with `pip install -r dev-requirements.txt`, but it's better to use the docker setup described below.
If you are using pyenv.

```
pyenv install 3.9
pyenv global 3.9
```

Install [Nox](https://nox.thea.codes/en/stable/) for task management.
### Install Poetry

This project uses [poetry](https://python-poetry.org/), which is typically installed with `curl -sSL https://install.python-poetry.org | python3 -`. Poetry automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your `pyproject.toml` as you install/uninstall packages. It also generates the ever-important `poetry.lock`, which is used to produce deterministic builds.

```
$ python -m pip install poetry
$ poetry --version
Poetry (version 1.5.1)
```

### Install Dependencies

```
$ python -m pip install nox
poetry install
```

## Install Docker Image
## Testing

### Install Docker Image

Integration tests require [docker](https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/).

Expand All @@ -41,21 +74,15 @@ 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
```

## Running Tests

Tests require a live instance of OpenSearch running in docker.
### Run Tests

If you have one running.
Run tests and ensure they pass.

```
python setup.py test
poetry run pytest -v
```

To run tests in a specific test file.

```
python setup.py test -s test_opensearchpy/test_connection.py
```
Warnings such as `urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)` are expected.

If you want to auto-start one, the following will start a new instance and run tests against the latest version of OpenSearch.

Expand Down
25 changes: 0 additions & 25 deletions dev-requirements.txt

This file was deleted.

45 changes: 18 additions & 27 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import nox

SOURCE_FILES = (
"setup.py",
"noxfile.py",
"opensearchpy/",
"test_opensearchpy/",
Expand All @@ -41,44 +40,34 @@
"docs/",
)

def setup(session: Any) -> None:
session.install("poetry")
session.run("poetry", "install")


@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]) # type: ignore
def test(session: Any) -> None:
session.install(".")
session.install("-r", "dev-requirements.txt")

session.run("python", "setup.py", "test")
setup(session)
session.run("poetry", "run", "pytest")


@nox.session() # type: ignore
def format(session: Any) -> None:
session.install("black", "isort")
setup(session)

session.run("isort", "--profile=black", *SOURCE_FILES)
session.run("black", "--target-version=py33", *SOURCE_FILES)
session.run("poetry", "run", "isort", *SOURCE_FILES)
session.run("poetry", "run", "black", *SOURCE_FILES)
session.run("python", "utils/license-headers.py", "fix", *SOURCE_FILES)

lint(session)


@nox.session(python=["3.7"]) # type: ignore
def lint(session: Any) -> None:
session.install(
"flake8",
"black",
"mypy",
"isort",
"types-requests",
"types-six",
"types-simplejson",
"types-python-dateutil",
"types-PyYAML",
"types-mock",
"types-pytz",
)

session.run("isort", "--check", "--profile=black", *SOURCE_FILES)
session.run("black", "--target-version=py33", "--check", *SOURCE_FILES)
setup(session)

session.run("poetry", "run", "isort", "--check", *SOURCE_FILES)
session.run("poetry", "run", "black", "--check", *SOURCE_FILES)
session.run("flake8", *SOURCE_FILES)
session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES)

Expand All @@ -100,14 +89,16 @@ def lint(session: Any) -> None:

@nox.session() # type: ignore
def docs(session: Any) -> None:
session.install(".")
session.install(".[docs]")
setup(session)

with session.chdir("docs"):
session.run("make", "html")


@nox.session() # type: ignore
def generate(session: Any) -> None:
session.install("-rdev-requirements.txt")
setup(session)

session.run("python", "utils/generate-api.py")

format(session)
Loading

0 comments on commit adf7212

Please sign in to comment.