-
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
231 additions
and
0 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,29 @@ | ||
name: Rye workflow | ||
on: | ||
push: | ||
paths: | ||
- 'rye-demo/**' | ||
- '.github/workflows/rye.yml' | ||
defaults: | ||
run: | ||
working-directory: ./rye-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 Rye | ||
uses: eifinger/setup-rye@v3 | ||
with: | ||
version: '0.35.0' | ||
- name: Sync | ||
run: rye sync | ||
- name: Lint | ||
run: rye lint | ||
- name: Run tests | ||
run: rye 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12.3 |
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,70 @@ | ||
# Rye Demo | ||
|
||
## Steps | ||
|
||
1. Install `rye`: | ||
```bash | ||
$ curl -sSf https://rye.astral.sh/get | bash | ||
``` | ||
|
||
2. Create a new project (with `--script` option for later): | ||
```bash | ||
$ rye init --script rye-demo | ||
``` | ||
|
||
3. Add dependencies (`requests`, `polars`, `pytest`, `ruff`) | ||
* Note: Add `pytest` and `ruff` under the `dev` group. | ||
|
||
```bash | ||
$ rye add requests | ||
$ rye add polars | ||
$ rye add --dev pytest | ||
$ rye add --dev ruff | ||
``` | ||
|
||
Those commands added the following sections to our initial `pyproject.toml` file, and created/updated `requirements.lock` and `requirements-dev.lock` files. | ||
|
||
```toml | ||
[project] | ||
... | ||
dependencies = [ | ||
"requests>=2.32.3", | ||
"polars>=1.0.0", | ||
] | ||
|
||
[tool.rye] | ||
managed = true | ||
dev-dependencies = [ | ||
"pytest>=8.2.2", | ||
"ruff>=0.5.0", | ||
] | ||
``` | ||
|
||
4. Install the project? | ||
```bash | ||
$ rye sync | ||
``` | ||
|
||
5. Add code (`demo.py`) and tests (`test_demo.py`). | ||
|
||
6. Run tests and lint/format code: | ||
```bash | ||
$ rye run pytest | ||
$ rye run ruff check --fix | ||
$ rye run ruff format | ||
``` | ||
|
||
Note: `rye` comes with formatting/linting commands (as of version `0.20.0`), so we could skip the roundabout call to `ruff` and just call: | ||
```bash | ||
$ rye lint --fix | ||
$ rye fmt | ||
``` | ||
|
||
7. Run the app: | ||
```bash | ||
$ rye run python -m rye_demo | ||
# or | ||
$ rye run rye-demo | ||
``` | ||
|
||
9. Add [rye-based GH workflow](../.github/workflows/rye.yml) to check linting and run tests. |
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,33 @@ | ||
[project] | ||
name = "rye-demo" | ||
version = "0.1.0" | ||
description = "" | ||
authors = [ | ||
{ name = "David Kun", email = "[email protected]" } | ||
] | ||
dependencies = [ | ||
"requests>=2.32.3", | ||
"polars>=1.0.0", | ||
] | ||
readme = "README.md" | ||
requires-python = ">= 3.8" | ||
|
||
[project.scripts] | ||
"rye-demo" = "rye_demo:main" | ||
|
||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[tool.rye] | ||
managed = true | ||
dev-dependencies = [ | ||
"pytest>=8.2.2", | ||
"ruff>=0.5.0", | ||
] | ||
|
||
[tool.hatch.metadata] | ||
allow-direct-references = true | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["src/rye_demo"] |
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,31 @@ | ||
# generated by rye | ||
# use `rye lock` or `rye sync` to update this lockfile | ||
# | ||
# last locked with the following flags: | ||
# pre: false | ||
# features: [] | ||
# all-features: false | ||
# with-sources: false | ||
# generate-hashes: false | ||
|
||
-e file:. | ||
certifi==2024.7.4 | ||
# via requests | ||
charset-normalizer==3.3.2 | ||
# via requests | ||
idna==3.7 | ||
# via requests | ||
iniconfig==2.0.0 | ||
# via pytest | ||
packaging==24.1 | ||
# via pytest | ||
pluggy==1.5.0 | ||
# via pytest | ||
polars==1.0.0 | ||
# via rye-demo | ||
pytest==8.2.2 | ||
requests==2.32.3 | ||
# via rye-demo | ||
ruff==0.5.0 | ||
urllib3==2.2.2 | ||
# via requests |
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,23 @@ | ||
# generated by rye | ||
# use `rye lock` or `rye sync` to update this lockfile | ||
# | ||
# last locked with the following flags: | ||
# pre: false | ||
# features: [] | ||
# all-features: false | ||
# with-sources: false | ||
# generate-hashes: false | ||
|
||
-e file:. | ||
certifi==2024.7.4 | ||
# via requests | ||
charset-normalizer==3.3.2 | ||
# via requests | ||
idna==3.7 | ||
# via requests | ||
polars==1.0.0 | ||
# via rye-demo | ||
requests==2.32.3 | ||
# via rye-demo | ||
urllib3==2.2.2 | ||
# via requests |
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,5 @@ | ||
from . import demo | ||
|
||
def main() -> int: | ||
demo.main() | ||
return 0 |
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,4 @@ | ||
import rye_demo | ||
import sys | ||
|
||
sys.exit(rye_demo.main()) |
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,26 @@ | ||
from io import StringIO | ||
import polars as pl | ||
import requests | ||
|
||
IRIS = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv" | ||
|
||
|
||
def main(): | ||
result = analyze(dataframe_from(iris_data())) | ||
print(result) | ||
|
||
|
||
def iris_data(url: str = IRIS) -> str: | ||
return requests.get(url).text | ||
|
||
|
||
def dataframe_from(csv_data: str) -> pl.DataFrame: | ||
return pl.read_csv(StringIO(csv_data)) | ||
|
||
|
||
def analyze(df: pl.DataFrame) -> pl.DataFrame: | ||
return df.filter(pl.col("sepal_length") > 5).group_by("species").agg(pl.all().sum()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
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,9 @@ | ||
from rye_demo.demo import dataframe_from | ||
|
||
|
||
def test_dataframe_from(): | ||
df = dataframe_from( | ||
"""A,B,C | ||
0.0,10.0,200.1""" | ||
) | ||
assert len(df.count()) == 1 |