Skip to content

Commit f4d114e

Browse files
committed
[CI] Migrate to pyproject.toml and poetry for deterministic builds
1 parent 68f3d9d commit f4d114e

File tree

7 files changed

+1288
-121
lines changed

7 files changed

+1288
-121
lines changed

Diff for: .github/workflows/ci.yml

+5-18
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@ concurrency:
1616
cancel-in-progress: true
1717

1818
jobs:
19-
checks:
20-
runs-on: ubuntu-latest
21-
steps:
22-
- name: "Checkout the source code"
23-
uses: actions/checkout@v2
24-
25-
- name: "Install Python"
26-
uses: actions/setup-python@v2
27-
28-
- name: "Install pre-commit"
29-
run: pip install pre-commit
30-
31-
- name: "Run pre-commit checks"
32-
run: pre-commit run --all-files
33-
3419
build:
3520
runs-on: ubuntu-latest
3621
strategy:
@@ -56,6 +41,7 @@ jobs:
5641
# Test with sqlalchemy 1.3
5742
- { python: "3.10", trino: "latest", sqlalchemy: "~=1.3.0" }
5843
env:
44+
TOX_PARALLEL_NO_SPINNER: 1
5945
TRINO_VERSION: "${{ matrix.trino }}"
6046
steps:
6147
- uses: actions/checkout@v2
@@ -66,7 +52,8 @@ jobs:
6652
run: |
6753
sudo apt-get update
6854
sudo apt-get install libkrb5-dev
69-
pip install .[tests] sqlalchemy${{ matrix.sqlalchemy }}
70-
- name: Run tests
55+
sudo curl -sSL https://install.python-poetry.org | python3
56+
poetry install
57+
- name: Run tox
7158
run: |
72-
pytest -s tests/
59+
poetry run tox --parallel

Diff for: README.md

+93-5
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,12 @@ exits the *with* context and the queries succeed, otherwise
424424

425425
## Improved Python types
426426

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

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

435435
```python
@@ -457,7 +457,95 @@ assert cur.description[0][1] == "timestamp with time zone"
457457

458458
Feel free to create an issue as it makes your request visible to other users and contributors.
459459

460+
## Getting Started With Development
461+
462+
Start by forking the repository and then modify the code in your fork.
463+
464+
Clone the repository and go inside the code directory.
465+
466+
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:
467+
468+
```
469+
$ curl -sSL https://install.python-poetry.org | python3
470+
```
471+
472+
When the code is ready, submit a Pull Request.
473+
474+
### Code Style
475+
476+
- For Python code, adhere to PEP 8.
477+
- Prefer code that is readable over one that is "clever".
478+
- When writing a Git commit message, follow these [guidelines](https://chris.beams.io/posts/git-commit/).
479+
480+
### Running Tests
481+
482+
`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
483+
only unit tests, type:
484+
485+
```
486+
$ poetry run tox -e <environment> -- tests/unit
487+
```
488+
489+
Similarly to run only integration tests, type:
490+
491+
```
492+
$ poetry run tox -e <environment> -- tests/integration
493+
```
494+
495+
where `<environment>` denotes the Python environment (see the configuration in `tox.ini`).
496+
497+
Then you can pass options like `--pdb` or anything supported by `pytest --help`.
498+
499+
They pull a Docker image and then run a container with a Trino server:
500+
- the image is named `trinodb/trino:${TRINO_VERSION}`
501+
- the container is named `trino-python-client-tests-{uuid4()[:7]}`
502+
503+
### pre-commit
504+
505+
`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:
506+
507+
```
508+
poetry run pre-commit install
509+
```
510+
511+
which will run on every commit. You can also run it anytime using:
512+
513+
```
514+
poetry run tox -e pre-commit
515+
```
516+
517+
### Releasing
518+
519+
- [Set up your development environment](#Getting-Started-With-Development).
520+
- Check the local workspace is up to date and has no uncommitted changes
521+
```bash
522+
git fetch -a && git status
523+
```
524+
- Change version in `trino/pyproject.toml` to a new version, e.g. `0.123.0`.
525+
- Commit
526+
```bash
527+
git commit -a -m "Bump version to 0.123.0"
528+
```
529+
- Create an annotated tag
530+
```bash
531+
git tag -m "" 0.123.0
532+
```
533+
- Create release package and upload it to PyPI
534+
```bash
535+
poetry publish --build &&
536+
open https://pypi.org/project/trino/ &&
537+
echo "Released!"
538+
```
539+
- Push the branch and the tag
540+
```bash
541+
git push upstream master 0.123.0
542+
```
543+
- Send release announcement.
544+
545+
## Need Help?
546+
547+
Feel free to create an issue as it make your request visible to other users and contributors.
548+
460549
If an interactive discussion would be better or if you just want to hangout and chat about
461550
the Trino Python client, you can join us on the *#python-client* channel on
462551
[Trino Slack](https://trino.io/slack.html).
463-

0 commit comments

Comments
 (0)