-
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.
refactor: refactored to use uv as the package manager (#29)
* chore: refactored to use uv as the package manager * chore: update dependencies in requirements.txt * refactor: update Chaturbate poller utility functions * chore: update ci-cd.yml to use uv as the package manager and cache uv dependencies
- Loading branch information
1 parent
79fa931
commit ad3a835
Showing
7 changed files
with
2,043 additions
and
210 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 |
---|---|---|
|
@@ -7,53 +7,56 @@ on: | |
branches: [ main ] | ||
|
||
jobs: | ||
|
||
ci: | ||
runs-on: ubuntu-latest | ||
env: | ||
# Configure a constant location for the uv cache | ||
UV_CACHE_DIR: /tmp/.uv-cache | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
- name: Install uv | ||
uses: astral-sh/setup-[email protected] | ||
with: | ||
python-version: "3.12" | ||
enable-cache: true | ||
cache-dependency-glob: "uv.lock" | ||
|
||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
virtualenvs-create: false | ||
virtualenvs-in-project: true | ||
- name: Set up Python | ||
id: setup-python | ||
run: uv python install | ||
|
||
- name: Load cached venv | ||
id: cached-poetry-dependencies | ||
- name: Restore uv cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | ||
path: /tmp/.uv-cache | ||
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} | ||
restore-keys: | | ||
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} | ||
uv-${{ runner.os }} | ||
- name: Install dependencies | ||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | ||
run: poetry install --no-interaction --no-root | ||
|
||
- name: Install library | ||
run: poetry install --no-interaction | ||
- name: Install dependencies and project | ||
if: steps.setup-python.outputs.cache-hit != 'true' | ||
run: uv sync | ||
|
||
- name: Format with ruff | ||
run: poetry run ruff format ./ | ||
run: uv run ruff format ./ | ||
|
||
- name: Lint with ruff and fix issues | ||
run: poetry run ruff check --fix ./ | ||
run: uv run ruff check --fix ./ | ||
|
||
- name: Type check with mypy | ||
run: poetry run mypy ./ | ||
run: uv run mypy ./ | ||
|
||
- name: Test with pytest | ||
env: | ||
CB_USERNAME: ${{ secrets.CB_USERNAME }} | ||
CB_TOKEN: ${{ secrets.CB_TOKEN }} | ||
run: poetry run pytest --cov-report term --cov-report xml:coverage.xml --cov=chaturbate_poller | ||
run: uv run pytest | ||
|
||
- name: Scan with SonarCloud | ||
uses: SonarSource/[email protected] | ||
|
@@ -68,14 +71,16 @@ jobs: | |
fail_ci_if_error: true | ||
|
||
- name: Build documentation | ||
run: poetry run make clean html --directory docs/ | ||
run: uv run make clean html --directory docs/ | ||
|
||
- name: Upload documentation to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
personal_token: ${{ secrets.PERSONAL_TOKEN }} | ||
publish_dir: docs/_build/html | ||
|
||
- name: Minimize uv cache | ||
run: uv cache prune --ci | ||
cd: | ||
permissions: | ||
id-token: write | ||
|
@@ -148,6 +153,7 @@ jobs: | |
type=sha | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
|
@@ -173,7 +179,8 @@ jobs: | |
push: ${{ github.event_name != 'pull_request' }} | ||
tags: | | ||
${{ steps.meta.outputs.tags }} | ||
${{ steps.release.outputs.version }} | ||
# Add version tag | ||
${{ steps.meta.outputs.tags }}-v${{ steps.meta.outputs.version }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
|
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 |
---|---|---|
@@ -1,80 +1,83 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Example usage\n", | ||
"\n", | ||
"To use `chaturbate_poller` in a project:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"2024-08-13 18:57:31 - INFO - mountaingod2 sent message: test\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# ruff: noqa: PLE1142\n", | ||
"import asyncio\n", | ||
"import os\n", | ||
"from contextlib import suppress\n", | ||
"\n", | ||
"from chaturbate_poller.chaturbate_client import ChaturbateClient\n", | ||
"from chaturbate_poller.event_handlers import create_event_handler\n", | ||
"from dotenv import load_dotenv\n", | ||
"\n", | ||
"load_dotenv()\n", | ||
"\n", | ||
"username = os.getenv(\"CB_USERNAME\", \"\")\n", | ||
"token = os.getenv(\"CB_TOKEN\", \"\")\n", | ||
"\n", | ||
"async def main() -> None:\n", | ||
" \"\"\"Fetch Chaturbate events.\"\"\"\n", | ||
" event_handler = create_event_handler(\"logging\")\n", | ||
"\n", | ||
" async with ChaturbateClient(username, token) as client:\n", | ||
" url = None\n", | ||
" while True:\n", | ||
" response = await client.fetch_events(url)\n", | ||
" if response is None:\n", | ||
" break\n", | ||
" for event in response.events:\n", | ||
" await event_handler.handle_event(event)\n", | ||
" url = str(response.next_url)\n", | ||
"\n", | ||
"with suppress(KeyboardInterrupt, asyncio.CancelledError):\n", | ||
" await main()\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Example usage\n", | ||
"\n", | ||
"To use `chaturbate_poller` in a project:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"2024-08-13 18:57:31 - INFO - mountaingod2 sent message: test\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# ruff: noqa: PLE1142\n", | ||
"import asyncio\n", | ||
"import os\n", | ||
"from contextlib import suppress\n", | ||
"\n", | ||
"from dotenv import load_dotenv\n", | ||
"\n", | ||
"from chaturbate_poller.chaturbate_client import ChaturbateClient\n", | ||
"from chaturbate_poller.event_handlers import create_event_handler\n", | ||
"\n", | ||
"load_dotenv()\n", | ||
"\n", | ||
"username = os.getenv(\"CB_USERNAME\", \"\")\n", | ||
"token = os.getenv(\"CB_TOKEN\", \"\")\n", | ||
"\n", | ||
"\n", | ||
"async def main() -> None:\n", | ||
" \"\"\"Fetch Chaturbate events.\"\"\"\n", | ||
" event_handler = create_event_handler(\"logging\")\n", | ||
"\n", | ||
" async with ChaturbateClient(username, token) as client:\n", | ||
" url = None\n", | ||
" while True:\n", | ||
" response = await client.fetch_events(url)\n", | ||
" if response is None:\n", | ||
" break\n", | ||
" for event in response.events:\n", | ||
" await event_handler.handle_event(event)\n", | ||
" url = str(response.next_url)\n", | ||
"\n", | ||
"\n", | ||
"with suppress(KeyboardInterrupt, asyncio.CancelledError):\n", | ||
" await main()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.