Skip to content

Commit

Permalink
[CI] Migrate to pyproject.toml and poetry for deterministic builds
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley committed Aug 31, 2022
1 parent 4e375c9 commit 3d2464c
Show file tree
Hide file tree
Showing 14 changed files with 1,605 additions and 214 deletions.
23 changes: 5 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ concurrency:
cancel-in-progress: true

jobs:
checks:
runs-on: ubuntu-latest
steps:
- name: "Checkout the source code"
uses: actions/checkout@v2

- name: "Install Python"
uses: actions/setup-python@v2

- name: "Install pre-commit"
run: pip install pre-commit

- name: "Run pre-commit checks"
run: pre-commit run --all-files

build:
runs-on: ubuntu-latest
strategy:
Expand All @@ -49,6 +34,7 @@ jobs:
# Test with older Trino versions for backward compatibility
- { python: "3.10", trino: "351" } # first Trino version
env:
TOX_PARALLEL_NO_SPINNER: 1
TRINO_VERSION: "${{ matrix.trino }}"
steps:
- uses: actions/checkout@v2
Expand All @@ -59,7 +45,8 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install libkrb5-dev
pip install .[tests]
- name: Run tests
sudo curl -sSL https://install.python-poetry.org | python3
poetry install
- name: Run tox
run: |
pytest -s tests/
poetry run tox --parallel
78 changes: 34 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ the [Password file authentication type, LDAP authentication type or Salesforce a

```python
from sqlalchemy import create_engine

engine = create_engine("trino://<username>:<password>@<host>:<port>/<catalog>")

# or
from trino.auth import BasicAuthentication
engine = create_engine(
Expand All @@ -162,7 +162,7 @@ the [`JWT` authentication type](https://trino.io/docs/current/security/jwt.html)
```python
from trino.dbapi import connect
from trino.auth import JWTAuthentication

conn = connect(
user="<username>",
auth=JWTAuthentication("<jwt_token>"),
Expand All @@ -175,7 +175,7 @@ the [`JWT` authentication type](https://trino.io/docs/current/security/jwt.html)

```python
from sqlalchemy import create_engine

engine = create_engine("trino://<username>@<host>:<port>/<catalog>/<schema>?access_token=<jwt_token>")

# or
Expand Down Expand Up @@ -273,7 +273,7 @@ the [`Kerberos` authentication type](https://trino.io/docs/current/security/kerb
```python
from trino.dbapi import connect
from trino.auth import KerberosAuthentication

conn = connect(
user="<username>",
auth=KerberosAuthentication(...),
Expand Down Expand Up @@ -382,12 +382,12 @@ exits the *with* context and the queries succeed, otherwise

# Improved Python types

If you enable the flag `experimental_python_types`, the client will convert the results of the query to the
If you enable the flag `experimental_python_types`, the client will convert the results of the query to the
corresponding Python types. For example, if the query returns a `DECIMAL` column, the result will be a `Decimal` object.

Limitations of the Python types are described in the
[Python types documentation](https://docs.python.org/3/library/datatypes.html). These limitations will generate an
exception `trino.exceptions.DataError` if the query returns a value that cannot be converted to the corresponding Python
Limitations of the Python types are described in the
[Python types documentation](https://docs.python.org/3/library/datatypes.html). These limitations will generate an
exception `trino.exceptions.DataError` if the query returns a value that cannot be converted to the corresponding Python
type.

```python
Expand Down Expand Up @@ -417,29 +417,14 @@ assert cur.description[0][1] == "timestamp with time zone"

Start by forking the repository and then modify the code in your fork.

Clone the repository and go inside the code directory. Then you can get the
version with `./setup.py --version`.

We recommend that you use Python3's `venv` for development:
Clone the repository and go inside the code directory.

```
$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip install .
```

For development purpose, pip can reference the code you are modifying in a
*virtual env*:
Python dependencies are managed using [Poetry](https://python-poetry.org/) which helps to ensure the project is managed in a deterministic way. Poetry [creates a virtual environment](https://python-poetry.org/docs/managing-environments/) to aid with the process. Poetry should be installed via:

```
$ pip install -e .
# To additionally install all dependencies for development run below command
$ pip install -e '.[tests]'
$ curl -sSL https://install.python-poetry.org | python3
```

That way, you do not need to run `pip install` again to make your changes
applied to the *virtual env*.

When the code is ready, submit a Pull Request.

### Code Style
Expand All @@ -450,40 +435,49 @@ When the code is ready, submit a Pull Request.

### Running Tests

`trino-python-client` uses [pytest](https://pytest.org/) for its tests. To run
`trino-python-client` uses [tox](https://tox.wiki/en/latest/)—a tool for standardizing testing in Python—which leverages the [pytest](https://pytest.org/) testing framework. To run
only unit tests, type:

```
$ pytest tests/unit
$ poetry run tox -e <environment> -- tests/unit
```

Then you can pass options like `--pdb` or anything supported by `pytest --help`.

To run the tests with different versions of Python in managed *virtual envs*,
use `tox` (see the configuration in `tox.ini`):
Similarly to run only integration tests, type:

```
$ tox
$ poetry run tox -e <environment> -- tests/integration
```

To run integration tests:
where `<environment>` denotes the Python environment (see the configuration in `tox.ini`).

```
$ pytest tests/integration
```
Then you can pass options like `--pdb` or anything supported by `pytest --help`.

They pull a Docker image and then run a container with a Trino server:
- the image is named `trinodb/trino:${TRINO_VERSION}`
- the container is named `trino-python-client-tests-{uuid4()[:7]}`

### pre-commit

`trino-python-client` leverages [pre-commit](https://pre-commit.com/) to help identify simple issues before submission to code review. Checks include the validity of the `pyproject.toml` file, type checks via [Mypy](https://github.com/python/mypy), etc. To enable `pre-commit` run:

```
poetry run pre-commit install
```

which will run on every commit. You can also run it anytime using:

```
poetry run tox -e pre-commit
```

### Releasing

- [Set up your development environment](#Getting-Started-With-Development).
- Check the local workspace is up to date and has no uncommitted changes
```bash
git fetch -a && git status
```
- Change version in `trino/__init__.py` to a new version, e.g. `0.123.0`.
- Change version in `trino/pyproject.toml` to a new version, e.g. `0.123.0`.
- Commit
```bash
git commit -a -m "Bump version to 0.123.0"
Expand All @@ -494,11 +488,7 @@ They pull a Docker image and then run a container with a Trino server:
```
- Create release package and upload it to PyPI
```bash
. .venv/bin/activate &&
pip install twine &&
rm -rf dist/ &&
./setup.py sdist bdist_wheel &&
twine upload dist/* &&
poetry publish --build &&
open https://pypi.org/project/trino/ &&
echo "Released!"
```
Expand Down
Loading

0 comments on commit 3d2464c

Please sign in to comment.