Skip to content

Commit

Permalink
🔧 Use uv instead of Poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Gudsfile committed Oct 26, 2024
1 parent 7f3f21f commit bc29351
Show file tree
Hide file tree
Showing 7 changed files with 483 additions and 66 deletions.
62 changes: 25 additions & 37 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,33 @@ on:
permissions:
contents: read

env:
UV_PROJECT_ENVIRONMENT: $PYTHONPATH

jobs:
build:

name: python
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.12

- name: Set up Poetry cache
id: cache-poetry
uses: actions/cache@v4
with:
path: /opt/poetry
key: ${{ runner.os }}-poetry
- name: Install Poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
pip install --upgrade pip
pip install poetry
poetry --version
- name: Set up Poetry dependencies cache
uses: actions/cache@v4
id: cached-poetry-dependencies
with:
path: .venv
key: ${{ runner.os }}-venv
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry --version
poetry config --local virtualenvs.in-project true
poetry install
- name: Lint with ruff
run: |
poetry run ruff check --ignore ANN001,ANN201
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"

- name: Install the project
run: uv sync --all-extras --dev

- name: Run linter
run: uv run ruff check --ignore ANN001,ANN201

- name: Minimize uv cache
run: uv cache prune --ci
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
venv/
poetry.lock

config.*
.cache
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

Clone this repository.

Install [Poetry](https://python-poetry.org).
Install [uv](https://docs.astral.sh/uv/).

Create the virtualenv and install the dependencies with Poetry
Create the virtualenv and install the dependencies with uv

```shell
poetry install
poetry run python --version
cd sploty/
uv sync
```

This project uses environment variables such as `spotify_client_id`.
You can export them or use a `.env` file and poetry with [poetry-dotenv-plugin](https://github.com/mpeteuil/poetry-dotenv-plugin).
This project uses environment variables such as `SPOTIFY_CLIENT_ID`.
You should add them to the `.env` file.

Environment variables are specified in the `sample.env` file, copy it and complete it

Expand Down Expand Up @@ -76,7 +76,17 @@ Timeout and index name could be configured with the Sploty args.
Run the app

```shell
poetry run python sploty/app.py \
uv run python sploty/app.py \
--resources-path your/path/to/the/extended_streaming_history_folder/ \
--db-path your/path/to/a/folder/to/save/tracks/data \
--index-name your-index-name
```

You can also reduce the syntax with `uv run sploty` instead of `uv run python sploty/app.py` (thanks to the `[project.scripts]` added to `pyproject.toml` file).


```shell
uv run sploty \
--resources-path your/path/to/the/extended_streaming_history_folder/ \
--db-path your/path/to/a/folder/to/save/tracks/data \
--index-name your-index-name
Expand All @@ -101,31 +111,31 @@ The app will :
Use the `--help` option

```shell
poetry run python sploty/app.py --help
uv run python sploty/app.py --help
```

#### How to use a previous `sploty_enriched_history` file?

By default, the `sploty_enriched_history` file in the resources folder is used, but you can choose another one with the `--previous-enriched-streaming-history-path` option

```shell
poetry run python sploty/app.py … --previous-enriched-streaming-history-path your/path/to/another/sploty_enriched_history.csv
uv run python sploty/app.py … --previous-enriched-streaming-history-path your/path/to/another/sploty_enriched_history.csv
```

#### How to skip a part?

Use the `-no-<the part>` options

```shell
poetry run python sploty/app.py … --no-concat --no-filter --no-enrich --no-feature --no-metric --no-elastic
uv run python sploty/app.py … --no-concat --no-filter --no-enrich --no-feature --no-metric --no-elastic
```

#### How to increase or reduce the number of lines processed at once?

Use the `--chunk-size` option, default is 100

```shell
poetry run python sploty/app.py … --chunk-size 101
uv run python sploty/app.py … --chunk-size 101
```

### 👀 Visualize your data
Expand Down
38 changes: 22 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
[tool.poetry]
[project]
name = "sploty"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"elasticsearch>=8.15.1",
"pandas>=2.2.3",
"pydantic-argparse>=0.9.0",
"pydantic-settings>=2.6.0",
"requests>=2.32.3",
"spotipy>=2.24.0",
"tinydb>=4.8.2",
]

[tool.poetry.dependencies]
python = "^3.12"
requests = "^2.31.0"
pandas = "^2.2.2"
spotipy = "^2.23.0"
elasticsearch = "^8.13.1"
tinydb = "^4.8.0"
pydantic-settings = "^2.5.2"

[tool.poetry.group.dev.dependencies]
ruff = "^0.5.5"
[tool.uv]
dev-dependencies = [
"ruff>=0.7.1",
]

[tool.ruff]
line-length = 160
Expand All @@ -25,5 +27,9 @@ select = ["ALL"]
ignore = ["D", "TD", "FIX", "PD901"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
# uv does not provide a build backend yet
requires = ["hatchling"]
build-backend = "hatchling.build"

[project.scripts]
sploty = "sploty.app:main"
3 changes: 2 additions & 1 deletion sploty/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pydantic_argparse
from pydantic import Field, HttpUrl, v1
from pydantic_settings import BaseSettings
from pydantic_settings import BaseSettings, SettingsConfigDict

from sploty import audio_features, concat, enrich, filter, metrics, to_elastic
from sploty.settings import logger
Expand All @@ -28,6 +28,7 @@ class Arguments(v1.BaseModel):


class Environment(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
spotify_client_id: str = Field(description="a required string")
spotify_client_secret: str = Field(description="a required string")
spotify_auth_url: HttpUrl = Field(description="a required string")
Expand Down
Loading

0 comments on commit bc29351

Please sign in to comment.