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 Jul 18, 2022
1 parent 951ad82 commit f7bec24
Show file tree
Hide file tree
Showing 8 changed files with 1,195 additions and 151 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ jobs:
- 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 Down Expand Up @@ -59,7 +53,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install libkrb5-dev
pip install .[tests]
sudo curl -sSL https://install.python-poetry.org | python3 - --preview
- name: Run tests
run: |
pytest -s tests/
poetry run tox --parallel
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ repos:
additional_dependencies:
- "types-pytz"
- "types-requests"

- repo: "https://github.com/python-poetry/poetry"
rev: "1.2.0b3"
hooks:
- id: poetry-check
- id: poetry-lock
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,9 +175,9 @@ 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
from trino.auth import JWTAuthentication
engine = create_engine(
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`.
Clone the repository and go inside the code directory.

We recommend that you use Python3's `venv` for development:
Python dependencies are managed using [Poetry](https://python-poetry.org/) which helps to ensure the project is managed in a deterministic way. Currently this project leverages [dependency groups](https://python-poetry.org/docs/master/managing-dependencies/) which are a pre-release feature and thus Poetry should be installed via:

```
$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip install .
$ curl -sSL https://install.python-poetry.org | python3 - --preview
```

For development purpose, pip can reference the code you are modifying in a
*virtual env*:

```
$ pip install -e .
# To additionally install all dependencies for development run below command
$ pip install -e '.[tests]'
```

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,32 +435,41 @@ 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).
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 &&
open https://pypi.org/project/trino/ &&
echo "Released!"
```
Expand Down
Loading

0 comments on commit f7bec24

Please sign in to comment.