Migrate project to use uv

This commit is contained in:
Sebastian Goscik
2025-04-09 00:00:44 +01:00
parent e11828bd59
commit 855607fa29
7 changed files with 1782 additions and 2333 deletions

View File

@@ -1,90 +1,88 @@
# This is a basic workflow to help you get started with Actions name: Test and Build
name: dev workflow
# Controls when the action will run.
on: on:
# Triggers the workflow on push events but only for the dev branch
push: push:
branches: [ dev ] branches-ignore:
- main
pull_request:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs: jobs:
# This workflow contains a single job called "test"
test: test:
# The type of runner that the job will run on # The type of runner that the job will run on
strategy: strategy:
matrix: matrix:
python-versions: [3.9] python-versions: ["3.10", "3.11", "3.12", "3.13"]
os: [ubuntu-18.04, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps: steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout code
- uses: actions/checkout@v2 uses: actions/checkout@v4
- uses: actions/setup-python@v2
- name: Set up Python
uses: actions/setup-python@v5
with: with:
python-version: ${{ matrix.python-versions }} python-version: ${{ matrix.python-versions }}
- name: Install dependencies - name: Install uv
run: | run: |
python -m pip install --upgrade pip curl -LsSf https://astral.sh/uv/install.sh | sh
pip install poetry tox tox-gh-actions echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: test with tox - name: Install dev dependencies
run: run: |
tox uv sync --dev
- name: list files - name: Run pre-commit
run: ls -l . run: uv run pre-commit run --all-files
- uses: codecov/codecov-action@v1 - name: Run pytest
with: run: uv run pytest
fail_ci_if_error: true
files: coverage.xml - name: Build
run: uv build
dev_container: dev_container:
name: Create dev container name: Create dev container
runs-on: ubuntu-20.04 needs: test
if: github.event_name != 'pull_request' if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job permissions:
contents: read
packages: write
steps: steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout code
- uses: actions/checkout@v2 uses: actions/checkout@v4
- uses: actions/setup-python@v2 - name: Set up Python
uses: actions/setup-python@v5
with: with:
python-version: 3.10 python-version: '3.12'
- name: Install dependencies - name: Install uv
run: | run: |
python -m pip install --upgrade pip curl -LsSf https://astral.sh/uv/install.sh | sh
pip install poetry tox tox-gh-actions echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Build wheels and source tarball - name: Build
run: >- run: uv build
poetry build
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v3
- name: Log in to container registry - name: Login to GitHub Container Registry
uses: docker/login-action@v2 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push dev - name: Build and push Docker image
uses: docker/build-push-action@v2 uses: docker/build-push-action@v5
with: with:
context: . context: .
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64

View File

@@ -1,6 +1,6 @@
# Publish package on main branch if it's tagged with 'v*' # Publish package on main branch if it's tagged with 'v*'
name: release & publish workflow name: Release & Publish Workflow
on: on:
push: push:
@@ -11,16 +11,17 @@ on:
jobs: jobs:
release: release:
name: Create Release name: Create Release
runs-on: ubuntu-20.04 runs-on: ubuntu-latest
steps: steps:
- name: Get version from tag - name: Get version from tag
id: tag_name id: tag_name
run: | run: |
echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v} echo "current_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
shell: bash shell: bash
- uses: actions/checkout@v2 - name: Checkout code
uses: actions/checkout@v4
- name: Get Changelog Entry - name: Get Changelog Entry
id: changelog_reader id: changelog_reader
@@ -29,56 +30,57 @@ jobs:
version: ${{ steps.tag_name.outputs.current_version }} version: ${{ steps.tag_name.outputs.current_version }}
path: ./CHANGELOG.md path: ./CHANGELOG.md
- uses: actions/setup-python@v2 - name: Set up Python
uses: actions/setup-python@v5
with: with:
python-version: "3.10" python-version: "3.10"
- name: Install dependencies - name: Install uv
run: | run: |
python -m pip install --upgrade pip curl -LsSf https://astral.sh/uv/install.sh | sh
pip install poetry echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Build wheels and source tarball - name: Build wheels and source tarball
run: >- run: uv build
poetry build
- name: show temporary files - name: Show build artifacts
run: >- run: ls -lR dist/
ls -lR
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v3
- name: Log in to container registry - name: Log in to container registry
uses: docker/login-action@v2 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push dev - name: Build and push container
uses: docker/build-push-action@v2 uses: docker/build-push-action@v5
with: with:
context: . context: .
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
push: true push: true
tags: ghcr.io/${{ github.repository }}:${{ steps.tag_name.outputs.current_version }}, ghcr.io/${{ github.repository }}:latest tags: |
ghcr.io/${{ github.repository }}:${{ steps.tag_name.outputs.current_version }}
ghcr.io/${{ github.repository }}:latest
- name: create github release - name: Create GitHub release
id: create_release id: create_release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
body: ${{ steps.changelog_reader.outputs.changes }} body: ${{ steps.changelog_reader.outputs.changes }}
files: dist/*.whl files: dist/*
draft: false draft: false
prerelease: false prerelease: false
- name: publish to PyPI - name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1 uses: pypa/gh-action-pypi-publish@release/v1
with: with:
user: __token__ user: __token__

View File

@@ -55,12 +55,11 @@ Ready to contribute? Here's how to set up `unifi-protect-backup` for local devel
$ git clone git@github.com:your_name_here/unifi-protect-backup.git $ git clone git@github.com:your_name_here/unifi-protect-backup.git
``` ```
3. Ensure [poetry](https://python-poetry.org/docs/) is installed. 3. Ensure [uv](https://docs.astral.sh/uv/) is installed.
4. Install dependencies and start your virtualenv: 4. Create virtual environment and install dependencies:
``` ```
$ poetry install --with dev,test $ uv install --dev
$ poetry shell
``` ```
5. Create a branch for local development: 5. Create a branch for local development:
@@ -75,21 +74,21 @@ Ready to contribute? Here's how to set up `unifi-protect-backup` for local devel
be inside the `poetry shell` virtualenv or run it via poetry: be inside the `poetry shell` virtualenv or run it via poetry:
``` ```
$ poetry run unifi-protect-backup {args} $ uv run unifi-protect-backup {args}
``` ```
7. Install pre-commit git hooks to ensure all code commit to the repository 7. Install pre-commit git hooks to ensure all code commit to the repository
is formatted correctly and meets coding standards: is formatted correctly and meets coding standards:
``` ```
$ poetry run pre-commit install $ uv run pre-commit install
``` ```
8. When you're done making changes, check that your changes pass the 8. When you're done making changes, check that your changes pass the
tests: tests:
``` ```
$ poetry run pytest $ uv run pytest
``` ```
8. Commit your changes and push your branch to GitHub: 8. Commit your changes and push your branch to GitHub:
@@ -117,7 +116,7 @@ Before you submit a pull request, check that it meets these guidelines:
## Tips ## Tips
``` ```
$ poetry run pytest tests/test_unifi_protect_backup.py $ uv run pytest tests/test_unifi_protect_backup.py
``` ```
To run a subset of tests. To run a subset of tests.
@@ -130,7 +129,7 @@ Make sure all your changes are committed (including an entry in CHANGELOG.md).
Then run: Then run:
``` ```
$ poetry run bump2version patch # possible: major / minor / patch $ uv run bump2version patch # possible: major / minor / patch
$ git push $ git push
$ git push --tags $ git push --tags
``` ```

View File

@@ -28,5 +28,5 @@ clean:
rm -rf coverage.xml .coverage rm -rf coverage.xml .coverage
docker: docker:
poetry build uv build
docker buildx build . --platform $(container_arches) -t $(container_name) --push docker buildx build . --platform $(container_arches) -t $(container_name) --push

2195
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,61 +1,61 @@
[tool] [build-system]
[tool.poetry] requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "unifi_protect_backup" name = "unifi_protect_backup"
version = "0.12.0" version = "0.12.0"
homepage = "https://github.com/ep1cman/unifi-protect-backup"
description = "Python tool to backup unifi event clips in realtime." description = "Python tool to backup unifi event clips in realtime."
authors = ["sebastian.goscik <sebastian@goscik.com>"]
readme = "README.md" readme = "README.md"
license = "MIT" license = {text = "MIT"}
classifiers=[ authors = [
'Development Status :: 5 - Production/Stable', {name = "sebastian.goscik", email = "sebastian@goscik.com"}
'Intended Audience :: Information Technology',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.10',
] ]
packages = [ classifiers = [
{ include = "unifi_protect_backup" }, "Development Status :: 5 - Production/Stable",
{ include = "tests", format = "sdist" }, "Intended Audience :: Information Technology",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
]
requires-python = ">=3.10.0,<4.0"
dependencies = [
"click==8.0.1",
"aiorun>=2023.7.2",
"aiosqlite>=0.17.0",
"python-dateutil>=2.8.2",
"apprise>=1.5.0",
"expiring-dict>=1.1.0",
"async-lru>=2.0.4",
"aiolimiter>=1.1.0",
"uiprotect>=6.3.1"
] ]
[tool.poetry.dependencies] [project.urls]
python = ">=3.10.0,<4.0" Homepage = "https://github.com/ep1cman/unifi-protect-backup"
click = "8.0.1"
aiorun = "^2023.7.2"
aiosqlite = "^0.17.0"
python-dateutil = "^2.8.2"
apprise = "^1.5.0"
expiring-dict = "^1.1.0"
async-lru = "^2.0.4"
aiolimiter = "^1.1.0"
uiprotect = "^6.3.1"
[tool.poetry.group.dev] [project.scripts]
optional = true unifi-protect-backup = "unifi_protect_backup.cli:main"
[tool.poetry.group.dev.dependencies] [dependency-groups]
mypy = "^1.11.1" dev = [
types-pytz = "^2021.3.5" "mypy>=1.11.1",
types-cryptography = "^3.3.18" "types-pytz>=2021.3.5",
types-python-dateutil = "^2.8.19.10" "types-cryptography>=3.3.18",
bump2version = "^1.0.1" "types-python-dateutil>=2.8.19.10",
pre-commit = "^2.12.0" "bump2version>=1.0.1",
ruff = "^0.5.7" "pre-commit>=2.12.0",
types-aiofiles = "^24.1.0.20241221" "ruff>=0.5.7",
"types-aiofiles>=24.1.0.20241221",
"pytest>=6.2.4",
]
[tool.poetry.group.test] [tool.hatch.build.targets.wheel]
optional = true packages = ["unifi_protect_backup"]
[tool.poetry.group.test.dependencies] [tool.hatch.build.targets.sdist]
pytest = "^6.2.4" include = ["unifi_protect_backup", "tests"]
pytest-cov = "^2.12.0"
tox = "^3.20.1"
tox-asdf = "^0.1.0"
[tool.poetry.scripts]
unifi-protect-backup = 'unifi_protect_backup.cli:main'
[tool.ruff] [tool.ruff]
line-length = 120 line-length = 120
@@ -66,11 +66,10 @@ target-version = "py310"
[tool.ruff.format] [tool.ruff.format]
[tool.mypy] [tool.mypy]
allow_redefinition=true allow_redefinition = true
exclude = [ exclude = [
'unifi_protect_backup/uiprotect_patch.py' 'unifi_protect_backup/uiprotect_patch.py'
] ]
[build-system] [tool.uv]
requires = ["poetry-core>=1.0.0"] default-groups = []
build-backend = "poetry.core.masonry.api"

1646
uv.lock generated Normal file

File diff suppressed because it is too large Load Diff