Repository: BartWojtowicz/videopython (language: python)

Issue:
Migrate dependency management into poetry or rye



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 475a0a8..290cc52 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,69 +1,58 @@
 name: CI Pipeline
-
 on: [push]
 
 jobs:
   build:
     name: Unit tests
     runs-on: ubuntu-latest
-
     steps:
     - name: Checkout code
       uses: actions/checkout@v4
-
     - name: Set up Python
       uses: actions/setup-python@v5
       with:
-        python-version: 3.10.12
-
+        python-version: "3.11"
+    - name: Install the latest version of rye
+      uses: eifinger/setup-rye@v4
     - name: Install FFmpeg
       run: |
         sudo apt-get update
         sudo apt-get install ffmpeg -y
-
     - name: Install dependencies
-      run: pip install -r requirements.txt -r requirements-dev.txt
-
-    - name: Run tests
-      run: PYTHONPATH=./src/ pytest
+      run: rye sync --features dev
+    - name: Run unit tests
+      run: rye run test-unit
 
   static_checks:
-    name: Static code checks
+    name: Static tests
     runs-on: ubuntu-latest
-    
     steps:
       - name: Checkout code
         uses: actions/checkout@v4
-
       - name: Set up Python
         uses: actions/setup-python@v5
         with:
-          python-version: 3.10.12
-
+          python-version: "3.11"
+      - name: Install the latest version of rye
+        uses: eifinger/setup-rye@v4
       - name: Install dev dependencies
-        run: pip install -r requirements-dev.txt
-
-      - name: Run black
-        run: black src -l 120 --check
-
-      - name: Run isort
-        run: isort src --profile black --check
+        run: rye sync --features dev
+      - name: Run static tests
+        run: rye run test-static
 
   mypy:
     name: Type tests
     runs-on: ubuntu-latest
-
     steps:
       - name: Checkout code
         uses: actions/checkout@v4
-
       - name: Set up Python
         uses: actions/setup-python@v5
         with:
-          python-version: 3.10.12
-      
+          python-version: "3.11"
+      - name: Install the latest version of rye
+        uses: eifinger/setup-rye@v4
       - name: Install all dependencies
-        run: pip install -r requirements.txt -r requirements-dev.txt -r requirements-generation.txt
-
-      - name: Run mypy
-        run: mypy src
+        run: rye sync --all-features
+      - name: Run type tests
+        run: rye run test-type
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index db2fad8..51a455c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -133,7 +133,6 @@ dmypy.json
 *.ipynb
 .vscode
 *.csv
-*.png
 
 # Data directories
 data/downloaded/*.mp4
diff --git a/README.md b/README.md
index f65727d..070cc63 100644
--- a/README.md
+++ b/README.md
@@ -86,7 +86,7 @@ transformed_video = Resize(width=1000, height=1000).apply(transformed_video)
 # Add generated music
 # MusicGen cannot generate more than 1503 tokens (~30seconds of audio)
 text_to_music = TextToMusic()
-audio = text_to_music.generate_audio("Description of the music to generate", max_new_tokens=256)
+audio = text_to_music.generate_audio("Happy dogs playing together in a park", max_new_tokens=256)
 transformed_video.add_audio(audio=audio)
 
 filepath = transformed_video.save()
diff --git a/mypy.ini b/mypy.ini
deleted file mode 100644
index d8e1ae6..0000000
--- a/mypy.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[mypy]
-mypy_path = "typehints"
diff --git a/pyproject.toml b/pyproject.toml
index df32a3a..39fc9fa 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,43 +1,90 @@
-[build-system]
-requires = ["setuptools>=66.1"]
-build-backend = "setuptools.build_meta"
-
-[tool.setuptools.packages.find]
-where = ["src"]
-include = ["videopython.*"]
-
-[tool.setuptools.package-data]
-"videopython" = ["py.typed"]
-
 [project]
 name = "videopython"
-version = "0.2.0"
+version = "0.2.1"
 description = "Minimal video generation and processing library."
+authors = [
+    { name = "Bartosz Wójtowicz", email = "bartoszwojtowicz@outlook.com" },
+    { name = "Bartosz Rudnikowicz", email = "bartoszrudnikowicz840@gmail.com" },
+    { name = "Piotr Pukisz", email = "piotr.pukisz@gmail.com" }
+]
+license = { text = "Apache-2.0" }
 readme = "README.md"
-requires-python = ">=3.10"
-license = {file = "LICENSE"}
+requires-python = ">=3.10, <3.13"
 keywords = ["python", "videopython", "video", "movie", "opencv", "generation", "editing"]
-dynamic = ["dependencies", "optional-dependencies"]
-
-authors = [
-  {name = "Bartosz Wójtowicz", email = "bartoszwojtowicz@outlook.com" },
-  {name = "Bartosz Rudnikowicz", email = "bartoszrudnikowicz840@gmail.com" }, 
-  {name = "Piotr Pukisz", email = "piotr.pukisz@gmail.com" },
+classifiers = [
+    "License :: OSI Approved :: Apache Software License",
+    "Programming Language :: Python :: 3",
+    "Programming Language :: Python :: 3.10",
+    "Programming Language :: Python :: 3.11",
+    "Operating System :: OS Independent",
 ]
 
-classifiers = [
-  "License :: OSI Approved :: Apache Software License",
-  "Programming Language :: Python :: 3",
-  "Programming Language :: Python :: 3.10",
-  "Programming Language :: Python :: 3.11",
-  "Operating System :: OS Independent",
+dependencies = [
+    "numpy>=1.25.2",
+    "opencv-python>=4.9.0.80",
+    "pillow>=10.3.0",
+    "pydub>=0.25.1",
+    "tqdm>=4.66.3",
 ]
 
-[tool.setuptools.dynamic]
-dependencies = {file = ["requirements.txt"]}
-optional-dependencies = { dev = {file = ["requirements-dev.txt"]}, generation = {file = ["requirements-generation.txt"]} }
+[project.optional-dependencies]
+dev = [
+    "black==24.3.0",
+    "isort==5.12.0",
+    "mypy==1.8.0",
+    "pytest==7.4.0",
+    "types-Pillow==10.2.0.20240213",
+    "types-tqdm==4.66.0.20240106",
+    "pydub-stubs==0.25.1.1",
+]
+generation = [
+    "accelerate>=0.29.2",
+    "diffusers>=0.26.3",
+    "torch>=2.1.0",
+    "transformers>=4.38.1",
+]
 
 [project.urls]
-"Homepage" = "https://github.com/bartwojtowicz/videopython/"
-"Bug Reports" = "https://github.com/bartwojtowicz/videopython/issues"
-"Source" = "https://github.com/bartwojtowicz/videopython/"
+Homepage = "https://github.com/bartwojtowicz/videopython/"
+Repository = "https://github.com/bartwojtowicz/videopython/"
+Documentation = "https://github.com/bartwojtowicz/videopython/"
+
+[tool.rye]
+managed = true
+dev-dependencies = [
+    "black==24.3.0",
+    "isort==5.12.0",
+    "mypy==1.8.0",
+    "pytest==7.4.0",
+    "types-Pillow==10.2.0.20240213",
+    "types-tqdm==4.66.0.20240106",
+    "pydub-stubs==0.25.1.1",
+]
+
+[tool.rye.scripts]
+test-unit = "pytest"
+test-type = "mypy src"
+test-static = { chain = [
+    "black src -l 120 --check",
+    "isort src --profile black --check"
+]}
+
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+[tool.hatch.build.targets.wheel]
+packages = ["src/videopython"]
+
+[tool.hatch.build.targets.sdist]
+include = [
+    "src/videopython/py.typed",
+]
+
+[tool.mypy]
+mypy_path = "stubs"
+
+[tool.pytest]
+testpaths = ["src/tests"]
+python_files = ["test_*.py"]
+addopts = "-v --tb=short"
diff --git a/requirements-dev.txt b/requirements-dev.txt
deleted file mode 100644
index b82d72c..0000000
--- a/requirements-dev.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-black==24.3.0
-isort==5.12.0
-mypy==1.8.0
-pytest==7.4.0
-types-Pillow==10.2.0.20240213
-types-tqdm==4.66.0.20240106
-pydub-stubs==0.25.1.1
diff --git a/requirements-generation.txt b/requirements-generation.txt
deleted file mode 100644
index 3314025..0000000
--- a/requirements-generation.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-accelerate>=0.29.2
-diffusers>=0.26.3
-torch>=2.1.0
-transformers>=4.38.1
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index 9d37c9f..0000000
--- a/requirements.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-click>=8.1.7
-numpy>=1.25.2
-opencv-python>=4.9.0.80
-pillow>=10.3.0
-pydub>=0.25.1
-tqdm>=4.66.3
diff --git a/scripts/README.md b/scripts/README.md
deleted file mode 100644
index 7cc8204..0000000
--- a/scripts/README.md
+++ /dev/null
@@ -1,13 +0,0 @@
-#  How to use the scripts in this folder
-
-## 1. [Script for downloading videos with Pexels API](./download_videos.py)
-First, you need to set up our Pexels account and get the API key from https://www.pexels.com/api/.
-
-Basic usage:
-```bash
-python scripts/download_videos.py \
-    -s "dogs playing in the snow" \
-    -k <PEXELS_API_KEY> \
-    -d data/downloaded \
-    -n 10
-```
diff --git a/scripts/download_videos.py b/scripts/download_videos.py
deleted file mode 100644
index 3584e21..0000000
--- a/scripts/download_videos.py
+++ /dev/null
@@ -1,67 +0,0 @@
-import os
-from pathlib import Path
-
-import click
-import requests
-
-PEXELS_API_URL = "https://api.pexels.com/videos/search"
-
-
-@click.command(help="Downloads videos with Pexels API.")
-@click.option(
-    "-s",
-    "--search-query",
-    help="Search query e.g. 'dogs playing in the snow'.",
-    prompt="Search query",
-    required=True,
-    type=str,
-)
-@click.option(
-    "-k",
-    "--api-key",
-    default=os.getenv("PEXELS_API_KEY"),
-    help="Pexels API key.",
-    required=True,
-    type=str,
-)
-@click.option(
-    "-d",
-    "--download-dir",
-    help="Directory to save downloaded videos.",
-    prompt="Download directory",
-    required=True,
-    type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True),
-)
-@click.option(
-    "-n",
-    "--n_videos",
-    default=10,
-    prompt="Number of videos",
-    help="Number of videos to download. Defaults to 10.",
-    type=int,
-)
-def download_videos(search_query: str, api_key: str, n_videos: int, download_dir: str):
-    params = {"query": search_query, "per_page": n_videos, "page": 1}
-    headers = {"Authorization": api_key}
-
-    response = requests.get(PEXELS_API_URL, headers=headers, params=params)
-    data = response.json()
-
-    # Download videos
-    skipped = 0
-    for video in data["videos"]:
-        video_path = Path(download_dir) / f"{video['id']}.mp4"
-        if video_path.exists():
-            print(f"Video {video_path} already exists. Skipping...")
-            skipped += 1
-            continue
-        video_url = video["video_files"][0]["link"]
-        video_data = requests.get(video_url).content
-
-        with open(video_path, "wb") as f:
-            f.write(video_data)
-        print(f"Video {video_path} downloaded.")
-
-
-if __name__ == "__main__":
-    download_videos()
diff --git a/src/typehints/cv2/__init__.pyi b/src/stubs/cv2/__init__.pyi
similarity index 100%
rename from src/typehints/cv2/__init__.pyi
rename to src/stubs/cv2/__init__.pyi
diff --git a/src/typehints/cv2/classes.pyi b/src/stubs/cv2/classes.pyi
similarity index 100%
rename from src/typehints/cv2/classes.pyi
rename to src/stubs/cv2/classes.pyi
diff --git a/src/typehints/cv2/constants.pyi b/src/stubs/cv2/constants.pyi
similarity index 100%
rename from src/typehints/cv2/constants.pyi
rename to src/stubs/cv2/constants.pyi
diff --git a/src/typehints/cv2/functions.pyi b/src/stubs/cv2/functions.pyi
similarity index 100%
rename from src/typehints/cv2/functions.pyi
rename to src/stubs/cv2/functions.pyi
diff --git a/src/typehints/transformers/__init__.pyi b/src/stubs/transformers/__init__.pyi
similarity index 100%
rename from src/typehints/transformers/__init__.pyi
rename to src/stubs/transformers/__init__.pyi
diff --git a/src/typehints/transformers/models.pyi b/src/stubs/transformers/models.pyi
similarity index 100%
rename from src/typehints/transformers/models.pyi
rename to src/stubs/transformers/models.pyi


Test patch:
diff --git a/tests/conftest.py b/src/tests/conftest.py
similarity index 100%
rename from tests/conftest.py
rename to src/tests/conftest.py
diff --git a/tests/test_compose.py b/src/tests/test_compose.py
similarity index 100%
rename from tests/test_compose.py
rename to src/tests/test_compose.py
diff --git a/tests/test_data/fast_benchmark.mp4 b/src/tests/test_data/fast_benchmark.mp4
similarity index 100%
rename from tests/test_data/fast_benchmark.mp4
rename to src/tests/test_data/fast_benchmark.mp4
diff --git a/tests/test_data/slow_benchmark.mp4 b/src/tests/test_data/slow_benchmark.mp4
similarity index 100%
rename from tests/test_data/slow_benchmark.mp4
rename to src/tests/test_data/slow_benchmark.mp4
diff --git a/tests/test_data/small_image.png b/src/tests/test_data/small_image.png
similarity index 100%
rename from tests/test_data/small_image.png
rename to src/tests/test_data/small_image.png
diff --git a/tests/test_data/test_audio.mp3 b/src/tests/test_data/test_audio.mp3
similarity index 100%
rename from tests/test_data/test_audio.mp3
rename to src/tests/test_data/test_audio.mp3
diff --git a/tests/test_data/test_font.ttf b/src/tests/test_data/test_font.ttf
similarity index 100%
rename from tests/test_data/test_font.ttf
rename to src/tests/test_data/test_font.ttf
diff --git a/tests/test_effects.py b/src/tests/test_effects.py
similarity index 100%
rename from tests/test_effects.py
rename to src/tests/test_effects.py
diff --git a/tests/test_transforms.py b/src/tests/test_transforms.py
similarity index 100%
rename from tests/test_transforms.py
rename to src/tests/test_transforms.py
diff --git a/tests/test_transitions.py b/src/tests/test_transitions.py
similarity index 100%
rename from tests/test_transitions.py
rename to src/tests/test_transitions.py
diff --git a/tests/test_utils.py b/src/tests/test_utils.py
similarity index 100%
rename from tests/test_utils.py
rename to src/tests/test_utils.py
diff --git a/tests/test_video.py b/src/tests/test_video.py
similarity index 100%
rename from tests/test_video.py
rename to src/tests/test_video.py