Skip to content

Commit 7489e74

Browse files
John Bodleyjohn-bodley
John Bodley
authored andcommitted
[CI] Migrate to pyproject.toml and poetry for deterministic builds
1 parent 951ad82 commit 7489e74

File tree

8 files changed

+1194
-151
lines changed

8 files changed

+1194
-151
lines changed

Diff for: .github/workflows/ci.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ jobs:
2323
- name: "Install Python"
2424
uses: actions/setup-python@v2
2525

26-
- name: "Install pre-commit"
27-
run: pip install pre-commit
28-
29-
- name: "Run pre-commit checks"
30-
run: pre-commit run --all-files
31-
3226
build:
3327
runs-on: ubuntu-latest
3428
strategy:
@@ -59,7 +53,7 @@ jobs:
5953
run: |
6054
sudo apt-get update
6155
sudo apt-get install libkrb5-dev
62-
pip install .[tests]
56+
sudo curl -sSL https://install.python-poetry.org | python3 - --preview
6357
- name: Run tests
6458
run: |
65-
pytest -s tests/
59+
poetry run tox --parallel

Diff for: .pre-commit-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ repos:
1313
additional_dependencies:
1414
- "types-pytz"
1515
- "types-requests"
16+
17+
- repo: "https://github.com/python-poetry/poetry"
18+
rev: "1.2.0b3"
19+
hooks:
20+
- id: poetry-check
21+
- id: poetry-lock

Diff for: README.md

+34-44
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ the [Password file authentication type, LDAP authentication type or Salesforce a
138138

139139
```python
140140
from sqlalchemy import create_engine
141-
141+
142142
engine = create_engine("trino://<username>:<password>@<host>:<port>/<catalog>")
143-
143+
144144
# or
145145
from trino.auth import BasicAuthentication
146146
engine = create_engine(
@@ -162,7 +162,7 @@ the [`JWT` authentication type](https://trino.io/docs/current/security/jwt.html)
162162
```python
163163
from trino.dbapi import connect
164164
from trino.auth import JWTAuthentication
165-
165+
166166
conn = connect(
167167
user="<username>",
168168
auth=JWTAuthentication("<jwt_token>"),
@@ -175,9 +175,9 @@ the [`JWT` authentication type](https://trino.io/docs/current/security/jwt.html)
175175

176176
```python
177177
from sqlalchemy import create_engine
178-
178+
179179
engine = create_engine("trino://<username>@<host>:<port>/<catalog>/<schema>?access_token=<jwt_token>")
180-
180+
181181
# or
182182
from trino.auth import JWTAuthentication
183183
engine = create_engine(
@@ -273,7 +273,7 @@ the [`Kerberos` authentication type](https://trino.io/docs/current/security/kerb
273273
```python
274274
from trino.dbapi import connect
275275
from trino.auth import KerberosAuthentication
276-
276+
277277
conn = connect(
278278
user="<username>",
279279
auth=KerberosAuthentication(...),
@@ -382,12 +382,12 @@ exits the *with* context and the queries succeed, otherwise
382382

383383
# Improved Python types
384384

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

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

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

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

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

423-
We recommend that you use Python3's `venv` for development:
422+
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:
424423

425424
```
426-
$ python3 -m venv .venv
427-
$ . .venv/bin/activate
428-
$ pip install .
425+
$ curl -sSL https://install.python-poetry.org | python3 - --preview
429426
```
430427

431-
For development purpose, pip can reference the code you are modifying in a
432-
*virtual env*:
433-
434-
```
435-
$ pip install -e .
436-
# To additionally install all dependencies for development run below command
437-
$ pip install -e '.[tests]'
438-
```
439-
440-
That way, you do not need to run `pip install` again to make your changes
441-
applied to the *virtual env*.
442-
443428
When the code is ready, submit a Pull Request.
444429

445430
### Code Style
@@ -450,32 +435,41 @@ When the code is ready, submit a Pull Request.
450435

451436
### Running Tests
452437

453-
`trino-python-client` uses [pytest](https://pytest.org/) for its tests. To run
438+
`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
454439
only unit tests, type:
455440

456441
```
457-
$ pytest tests/unit
442+
$ poetry run tox -e <environment> -- tests/unit
458443
```
459444

460-
Then you can pass options like `--pdb` or anything supported by `pytest --help`.
461-
462-
To run the tests with different versions of Python in managed *virtual envs*,
463-
use `tox` (see the configuration in `tox.ini`):
445+
Similarly to run only integration tests, type:
464446

465447
```
466-
$ tox
448+
$ poetry run tox -e <environment> -- tests/integration
467449
```
468450

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

471-
```
472-
$ pytest tests/integration
473-
```
453+
Then you can pass options like `--pdb` or anything supported by `pytest --help`.
474454

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

459+
### pre-commit
460+
461+
`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:
462+
463+
```
464+
poetry run pre-commit install
465+
```
466+
467+
which will run on every commit. You can also run it anytime using:
468+
469+
```
470+
poetry run tox -e pre-commit
471+
```
472+
479473
### Releasing
480474

481475
- [Set up your development environment](#Getting-Started-With-Development).
@@ -494,11 +488,7 @@ They pull a Docker image and then run a container with a Trino server:
494488
```
495489
- Create release package and upload it to PyPI
496490
```bash
497-
. .venv/bin/activate &&
498-
pip install twine &&
499-
rm -rf dist/ &&
500-
./setup.py sdist bdist_wheel &&
501-
twine upload dist/* &&
491+
poetry publish &&
502492
open https://pypi.org/project/trino/ &&
503493
echo "Released!"
504494
```

0 commit comments

Comments
 (0)