From 16312656a73d9b58345ea9f14369a848051a0198 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Sun, 27 Jul 2025 05:49:07 +0200 Subject: [PATCH 1/5] initial commit --- .github/workflows/docs.yml | 1 + .gitignore | 135 ++++++++++++++++++++++- .pre-commit-config.yaml | 30 ++++- mkdocs.yml | 12 +- pyproject.toml | 45 +++++--- src/flet_flashlight/__init__.py | 11 ++ src/flet_flashlight/exceptions.py | 11 ++ src/flet_flashlight/flashlight.py | 23 +++- src/flutter/flet_flashlight/pubspec.yaml | 2 +- 9 files changed, 233 insertions(+), 37 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 80ee047..845e7c0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - dev paths: - 'LICENSE' - 'CHANGELOG.md' diff --git a/.gitignore b/.gitignore index 006e58f..891876a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,135 @@ -*.egg-info/ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python build/ develop-eggs/ dist/ -.DS_store -.venv/ \ No newline at end of file +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock +uv.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# VS Code +.vscode/ + +# PDM +.pdm.toml +__pypackages__/ + +.DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e69f06f..0997bef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,27 @@ repos: - - repo: https://github.com/pycqa/isort - rev: 5.13.2 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.12.5 hooks: - - id: isort - - repo: https://github.com/ambv/black - rev: 22.12.0 + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format + + - repo: https://github.com/executablebooks/mdformat + rev: 0.7.22 hooks: - - id: black + - id: mdformat + additional_dependencies: + - mdformat-ruff + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/aio-libs/sort-all + rev: v1.3.0 + hooks: + - id: sort-all diff --git a/mkdocs.yml b/mkdocs.yml index fd4251d..f532e28 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -106,6 +106,7 @@ plugins: # - footnotes - search: lang: en + - open-in-new-tab - mike: alias_type: symlink - glightbox @@ -130,21 +131,16 @@ plugins: show_labels: false show_if_no_docstring: true docstring_section_style: spacy + separate_signature: true inherited_members: true preload_modules: [ flet ] filters: - "!^_" # Exclude private members starting with only one underscore - - "!before_update" - - "!before_event" - - "!clean" - - "!did_mount" - - "!init" - - "!is_isolated" - - "!update" - - "!will_unmount" extensions: - griffe_modernized_annotations + - griffe_warnings_deprecated inventories: + - url: https://docs.flet.dev/objects.inv - url: https://docs.python.org/3/objects.inv domains: [ py, std ] - url: https://typing-extensions.readthedocs.io/en/latest/objects.inv diff --git a/pyproject.toml b/pyproject.toml index 27380fb..4ece3d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,22 +20,40 @@ Issues = "https://github.com/flet-dev/flet-flashlight/issues" "flutter.flet_flashlight" = ["**/*"] [dependency-groups] +test = [ + "pytest >=7.2.0", +] dev = [ - "pre-commit>=4.2.0", - "ruff>=0.11.7", + "pre-commit >=4.2.0", + "ruff >=0.11.7", + { include-group = 'test' }, +] +docs-coverage = [ + "docstr-coverage >=2.3.2", ] docs = [ - "mkdocs", - "mkdocs-material", - "mkdocstrings[python]", - "mkdocstrings-python-xref", - "mike", - "markdown>=3.6", - "pymdown-extensions", - "mkdocs-glightbox", - "mkdocs-section-index", - "griffe-modernized-annotations", - "pygments>=2.16", + "mkdocs >=1.6.1", + "mkdocs-material >=9.6.15", + "mkdocstrings-python >=1.16.12", + "mkdocstrings-python-xref >=1.16.3", + "mike >=2.1.3", + "markdown >=3.6", + "pymdown-extensions >=10.16", + "mkdocs-exclude >=1.0.2", + "mkdocs-glightbox >=0.4.0", + "mkdocs-open-in-new-tab >=1.0.8", + "mkdocs-section-index >=0.3.10", + "griffe-modernized-annotations >=1.0.8", + "griffe-warnings-deprecated >=1.1.0", + "pygments >=2.16", + "markdown-exec[ansi] >=1.11.0", + "pydocstyle >=6.3.0", + "linkcheckmd >=1.4.0", + { include-group = 'docs-coverage' }, +] +all = [ + { include-group = 'dev' }, + { include-group = 'docs' }, ] [build-system] @@ -64,6 +82,7 @@ select = [ "I" ] preview = true +pydocstyle = { convention = 'google' } [tool.ruff.format] quote-style = "double" diff --git a/src/flet_flashlight/__init__.py b/src/flet_flashlight/__init__.py index 2d56c89..43dae39 100644 --- a/src/flet_flashlight/__init__.py +++ b/src/flet_flashlight/__init__.py @@ -8,3 +8,14 @@ FlashlightException, ) from .flashlight import Flashlight + +__all__ = [ + "Flashlight", + "FlashlightDisableException", + "FlashlightDisableExistentUserException", + "FlashlightDisableNotAvailableException", + "FlashlightEnableException", + "FlashlightEnableExistentUserException", + "FlashlightEnableNotAvailableException", + "FlashlightException", +] diff --git a/src/flet_flashlight/exceptions.py b/src/flet_flashlight/exceptions.py index d01f769..ae0b7e8 100644 --- a/src/flet_flashlight/exceptions.py +++ b/src/flet_flashlight/exceptions.py @@ -1,3 +1,14 @@ +__all__ = [ + "FlashlightDisableException", + "FlashlightDisableExistentUserException", + "FlashlightDisableNotAvailableException", + "FlashlightEnableException", + "FlashlightEnableExistentUserException", + "FlashlightEnableNotAvailableException", + "FlashlightException", +] + + class FlashlightException(Exception): """ Base class for all [`Flashlight`][(p).] exceptions. diff --git a/src/flet_flashlight/flashlight.py b/src/flet_flashlight/flashlight.py index c3b739e..7dd9275 100644 --- a/src/flet_flashlight/flashlight.py +++ b/src/flet_flashlight/flashlight.py @@ -1,8 +1,17 @@ import asyncio +from typing import Optional import flet as ft -from .exceptions import * +from .exceptions import ( + FlashlightDisableException, + FlashlightDisableExistentUserException, + FlashlightDisableNotAvailableException, + FlashlightEnableException, + FlashlightEnableExistentUserException, + FlashlightEnableNotAvailableException, + FlashlightException, +) __all__ = ["Flashlight"] @@ -10,10 +19,11 @@ @ft.control("Flashlight") class Flashlight(ft.Service): """ - A control to use FlashLight. Works on iOS and Android. Based on torch_light Flutter widget (https://pub.dev/packages/torch_light). + A control to use FlashLight. Works on iOS and Android. Note: - This control is a non-visual and should be added to `page.services` list before it can be used. + This control is a non-visual and should be added + to [`Page.services`][flet.Page.services] list before it can be used. """ on = False @@ -21,11 +31,12 @@ class Flashlight(ft.Service): Whether the flashlight is currently turned on. """ - on_error: ft.OptionalControlEventHandler["Flashlight"] = None + on_error: Optional[ft.ControlEventHandler["Flashlight"]] = None """ Fires when an error occurs. - - The `data` property of the event handler argument contains information on the error. + + The [`data`][flet.Event.data] property of the event handler argument + contains information on the error. """ async def turn_on_async(self): diff --git a/src/flutter/flet_flashlight/pubspec.yaml b/src/flutter/flet_flashlight/pubspec.yaml index f6ecdb7..7c8c1c2 100644 --- a/src/flutter/flet_flashlight/pubspec.yaml +++ b/src/flutter/flet_flashlight/pubspec.yaml @@ -27,4 +27,4 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.0 \ No newline at end of file + flutter_lints: ^3.0.0 \ No newline at end of file From a92400757395af6ef0f1c31ec09a9c35f665a190 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Sun, 27 Jul 2025 17:33:56 +0200 Subject: [PATCH 2/5] remove mdformat from pre-commit --- .pre-commit-config.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0997bef..8f2d1ab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,13 +8,6 @@ repos: # Run the formatter. - id: ruff-format - - repo: https://github.com/executablebooks/mdformat - rev: 0.7.22 - hooks: - - id: mdformat - additional_dependencies: - - mdformat-ruff - - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: From 2b15a681a15abb1c538169c458b951e764c10261 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Sun, 27 Jul 2025 20:18:51 +0200 Subject: [PATCH 3/5] update mkdocs watch items | unshow `Event.get_event_field_type` --- mkdocs.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index f532e28..6cf29dd 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -99,7 +99,10 @@ validation: # Watch watch: - docs - - src + - src/flet_flashlight + - CHANGELOG.md + - LICENSE + - README.md # Plugins plugins: @@ -136,6 +139,7 @@ plugins: preload_modules: [ flet ] filters: - "!^_" # Exclude private members starting with only one underscore + - "!get_event_field_type" extensions: - griffe_modernized_annotations - griffe_warnings_deprecated From 7174c8af024ed66b03271ff1ea49c768ae1b52e8 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Sun, 27 Jul 2025 21:29:03 +0200 Subject: [PATCH 4/5] fixes --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 845e7c0..74f17f0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -53,7 +53,7 @@ jobs: - name: Install dependencies run: | uv pip install -e . - uv pip install --group docs + uv pip install --group all - name: Deploy to GitHub Pages run: uv run mkdocs gh-deploy --force From e1d2368db4f6b8a90bc10db5e077b994cd52b7d9 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Sun, 27 Jul 2025 21:51:37 +0200 Subject: [PATCH 5/5] lint dependency group --- .github/workflows/docs.yml | 2 +- pyproject.toml | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 74f17f0..b0732cc 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -53,7 +53,7 @@ jobs: - name: Install dependencies run: | uv pip install -e . - uv pip install --group all + uv pip install --group docs --group lint - name: Deploy to GitHub Pages run: uv run mkdocs gh-deploy --force diff --git a/pyproject.toml b/pyproject.toml index 4ece3d1..f40ab0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,9 +23,12 @@ Issues = "https://github.com/flet-dev/flet-flashlight/issues" test = [ "pytest >=7.2.0", ] +lint = [ + "ruff >=0.11.7", +] dev = [ "pre-commit >=4.2.0", - "ruff >=0.11.7", + { include-group = 'lint' }, { include-group = 'test' }, ] docs-coverage = [