-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
476 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Poetry workflow | ||
on: | ||
push: | ||
paths: | ||
- 'poetry-demo/**' | ||
defaults: | ||
run: | ||
working-directory: ./poetry-demo | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
- name: Lint | ||
run: poetry run ruff check | ||
- name: Run tests | ||
run: poetry run pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Comparing Hatch, Poetry, and Rye | ||
|
||
* [hatch-demo](./hatch-demo/README.md) | ||
* [poetry-demo](./poetry-demo/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Poetry Demo | ||
|
||
## Steps | ||
|
||
1. Install `poetry`: | ||
|
||
```bash | ||
$ pipx install poetry | ||
# or | ||
$ brew install poetry | ||
``` | ||
|
||
2. Create new project (with [src-layout](https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/)): | ||
```bash | ||
$ poetry new --src poetry-demo | ||
``` | ||
|
||
3. Add dependencies (`requests`, `polars`, `pytest`, `ruff`) | ||
* Note: Add `pytest` and `ruff` under the `dev` group. | ||
|
||
```bash | ||
$ poetry add requests | ||
$ poetry add polars | ||
$ poetry add pytest --group dev | ||
$ poetry add ruff --group dev | ||
``` | ||
|
||
Those commands added the following sections to our initial `pyproject.toml` file, and created/updated a `poetry.lock` file. | ||
|
||
```toml | ||
[tool.poetry.dependencies] | ||
python = "^3.12" | ||
requests = "^2.32.3" | ||
polars = "^1.0.0" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pytest = "^8.2.2" | ||
ruff = "^0.5.0" | ||
``` | ||
|
||
4. Install the project: | ||
```bash | ||
$ poetry install | ||
``` | ||
|
||
5. Add code (`demo.py`) and tests (`test_demo.py`). | ||
|
||
6. Run tests and lint/format code: | ||
```bash | ||
$ poetry run pytest | ||
$ poetry run ruff check --fix | ||
$ poetry run ruff format | ||
``` | ||
|
||
7. Add entrypoint script to run the app: | ||
```toml | ||
[tool.poetry.scripts] | ||
rundemo = 'poetry_demo.demo:main' | ||
``` | ||
|
||
8. Run the app: | ||
```bash | ||
$ rundemo | ||
|
||
shape: (3, 5) | ||
┌────────────┬──────────────┬─────────────┬──────────────┬─────────────┐ | ||
│ species ┆ sepal_length ┆ sepal_width ┆ petal_length ┆ petal_width │ | ||
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │ | ||
│ str ┆ f64 ┆ f64 ┆ f64 ┆ f64 │ | ||
╞════════════╪══════════════╪═════════════╪══════════════╪═════════════╡ | ||
│ setosa ┆ 116.9 ┆ 81.7 ┆ 33.2 ┆ 6.1 │ | ||
│ virginica ┆ 324.5 ┆ 146.2 ┆ 273.1 ┆ 99.6 │ | ||
│ versicolor ┆ 281.9 ┆ 131.8 ┆ 202.9 ┆ 63.3 │ | ||
└────────────┴──────────────┴─────────────┴──────────────┴─────────────┘ | ||
``` | ||
|
||
9. Add [poetry-based GH workflow](../.github/workflows/poetry.yml) to check linting and run tests. |
Oops, something went wrong.