Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
name: Check style formatting
steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v1"
- uses: "astral-sh/ruff-action@v3"
with:
python-version: "3.13"
allow-prereleases: true
- run: python3 -m pip install black
- run: black .
args: "check --output-format=github"
- uses: "astral-sh/ruff-action@v3"
with:
args: "format --check --diff"

pytest:
runs-on: "ubuntu-latest"
Expand Down
33 changes: 5 additions & 28 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 25.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.14
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((custom_components|tests)/.+)?[^/]+\.py$
- id: ruff-check
args: [--fix, --show-fixes]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
Expand All @@ -16,27 +14,6 @@ repos:
- --skip="./.*,*.csv,*.json"
- --quiet-level=2
exclude_types: [csv, json]
- repo: https://github.com/pycqa/flake8
rev: 7.3.0
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings==1.6.0
- pydocstyle==6.1.1
files: ^(custom_components|tests)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.8.6
hooks:
- id: bandit
args:
- --quiet
- --format=custom
- --configfile=tests/bandit.yaml
files: ^(custom_components|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 6.0.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
Expand Down
1 change: 0 additions & 1 deletion custom_components/pyscript/jupyter_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ async def shell_handler(self, shell_socket, wire_msg):
await self.send(self.iopub_socket, "status", content, parent_header=msg["header"])

if msg["header"]["msg_type"] == "execute_request":

content = {
"execution_count": self.execution_count,
"code": msg["content"]["code"],
Expand Down
5 changes: 3 additions & 2 deletions custom_components/pyscript/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,6 @@ async def trigger_watch(self):
"""Task that runs for each trigger, waiting for the next trigger and calling the function."""

try:

if self.state_trigger is not None:
self.state_trig_ident = set()
if self.state_user_watch:
Expand Down Expand Up @@ -1084,7 +1083,9 @@ async def trigger_watch(self):
Event.notify_add(self.event_trigger[0], self.notify_q)
if self.mqtt_trigger is not None:
_LOGGER.debug("trigger %s adding mqtt_trigger %s", self.name, self.mqtt_trigger[0])
await Mqtt.notify_add(self.mqtt_trigger[0], self.notify_q, encoding=self.mqtt_trigger_encoding)
await Mqtt.notify_add(
self.mqtt_trigger[0], self.notify_q, encoding=self.mqtt_trigger_encoding
)
if self.webhook_trigger is not None:
_LOGGER.debug("trigger %s adding webhook_trigger %s", self.name, self.webhook_trigger[0])
Webhook.notify_add(
Expand Down
17 changes: 14 additions & 3 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ good-names=id,i,j,k,ex,Run,_,fp,T

[MESSAGES CONTROL]
# Reasons disabled:
# format - handled by black
# locally-disabled - it spams too much
# duplicate-code - unavoidable
# cyclic-import - doesn't test if both import on load
Expand All @@ -25,7 +24,6 @@ good-names=id,i,j,k,ex,Run,_,fp,T
# too-many-ancestors - it's too strict.
# wrong-import-order - isort guards this
disable=
format,
abstract-method,
broad-except,
cyclic-import,
Expand Down Expand Up @@ -53,7 +51,20 @@ disable=
no-value-for-parameter,
unsubscriptable-object,
wrong-import-order,
unidiomatic-typecheck
unidiomatic-typecheck,
# Covered by Ruff
format,
unused-import,
unused-variable,
undefined-variable,
used-before-assignment,
redefined-outer-name,
wildcard-import,
unused-wildcard-import,
missing-module-docstring,
missing-class-docstring,
missing-function-docstring,
empty-docstring
enable=
use-symbolic-message-instead

Expand Down
75 changes: 75 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,78 @@ line-length = 109
#[tool.pytest.ini_options]
#asyncio_mode = "auto"
#asyncio_default_fixture_loop_scope = "function"

[tool.ruff]
target-version = "py314"
line-length = 109
src = ["custom_components", "tests"]
include = ["custom_components/**/*.py", "tests/**/*.py"]

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint.flake8-annotations]
ignore-fully-untyped = true

[tool.ruff.lint.isort]
force-sort-within-sections = true
known-first-party = ["homeassistant", "tests", "custom_components.pyscript"]
combine-as-imports = true

[tool.ruff.lint]
select = [
"ANN", # flake8-annotations
"B", # flake8-bugbear
"D", # pydocstyle
"E", # pycodestyle
"F", # pyflakes
"FIX", # flake8-fixme
"G", # flake8-logging-format
"I", # isort
"PLC", #pylint convention
"RUF", # ruff-specific rules
"S", # flake8-bandit
"UP", # pyupgrade
"W", # pycodestyle
]
ignore = [
"ANN003", # missing-type-kwargs
"ANN401", # any-type
"D202", # blank-line-after-function
"D203", # incorrect-blank-line-before-class
"D212", # multi-line-summary-first-line
"E501", # line-too-long
"UP037", # quoted-annotation
#pylint covered
"B012", # jump-statement-in-finally
"B904", # raise-without-from-inside-except
"PLC0415", # import-outside-top-level
"S102", # exec-builtin
]


[tool.ruff.lint.per-file-ignores]
"eval.py" = [
"B007", # unused-loop-control-variable
"B009", # get-attr-with-constant
"B905", # zip-without-explicit-strict
"S506", # unsafe-yaml-load
"RUF005", #collection-literal-concatenation
]
"pyscript_builtins.py" = [
"ANN", # flake8-annotations
"B", # flake8-bugbear
"D", # pydocstyle
]
"tests/*.py" = [
"S101", # assert
"B011"# assert-false
]
#temporary
"__init__.py" = ["B007"]
"config_flow.py" = ["B007", "UP006", "UP035", "RUF013"]
"event.py" = ["RUF012"]
"jupyter_kernel.py" = ["RUF006", "S104"]
"mqtt.py" = ["RUF012"]
"trigger.py" = ["RUF012", "UP041"]
"webhook.py" = ["RUF012"]
37 changes: 0 additions & 37 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,6 @@ addopts =
--strict-markers
--asyncio-mode=auto

[flake8]
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build
doctests = True
# To work with Black
max-line-length = 109
# E501: line too long
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# D202 No blank lines allowed after function docstring
# W504 line break after binary operator
# E231 missing whitespace after ':'
ignore =
E501,
W503,
E203,
D202,
W504
E231

[isort]
# https://github.com/timothycrosley/isort
# https://github.com/timothycrosley/isort/wiki/isort-Settings
# splits long import on multiple lines indented by 4 spaces
multi_line_output = 3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=109
indent = " "
# will group `import x` and `from x import` of the same module.
force_sort_within_sections = true
sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section = THIRDPARTY
known_first_party = homeassistant,tests
forced_separate = tests
combine_as_imports = true

[mypy]
python_version = 3.13
ignore_errors = true
Expand Down
26 changes: 11 additions & 15 deletions tests/test_apps_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,17 @@ def glob_side_effect(path, recursive=None, root_dir=None, dir_fd=None, include_h
return result

conf = {"apps": {"world": {}}}
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
"custom_components.pyscript.glob.iglob"
) as mock_glob, patch("custom_components.pyscript.global_ctx.open", mock_open), patch(
"custom_components.pyscript.open", mock_open
), patch(
"homeassistant.config.load_yaml_config_file", return_value={"pyscript": conf}
), patch(
"custom_components.pyscript.watchdog_start", return_value=None
), patch(
"custom_components.pyscript.os.path.getmtime", return_value=1000
), patch(
"custom_components.pyscript.global_ctx.os.path.getmtime", return_value=1000
), patch(
"custom_components.pyscript.os.path.isfile"
) as mock_isfile:
with (
patch("custom_components.pyscript.os.path.isdir", return_value=True),
patch("custom_components.pyscript.glob.iglob") as mock_glob,
patch("custom_components.pyscript.global_ctx.open", mock_open),
patch("custom_components.pyscript.open", mock_open),
patch("homeassistant.config.load_yaml_config_file", return_value={"pyscript": conf}),
patch("custom_components.pyscript.watchdog_start", return_value=None),
patch("custom_components.pyscript.os.path.getmtime", return_value=1000),
patch("custom_components.pyscript.global_ctx.os.path.getmtime", return_value=1000),
patch("custom_components.pyscript.os.path.isfile") as mock_isfile,
):
mock_isfile.side_effect = isfile_side_effect
mock_glob.side_effect = glob_side_effect
assert await async_setup_component(hass, "pyscript", {DOMAIN: conf})
Expand Down
5 changes: 3 additions & 2 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ async def test_options_flow_user_no_change(hass, pyscript_bypass_setup):
@pytest.mark.asyncio
async def test_config_entry_reload(hass):
"""Test that config entry reload does not duplicate listeners."""
with patch("homeassistant.config.load_yaml_config_file", return_value={}), patch(
"custom_components.pyscript.watchdog_start", return_value=None
with (
patch("homeassistant.config.load_yaml_config_file", return_value={}),
patch("custom_components.pyscript.watchdog_start", return_value=None),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
Expand Down
31 changes: 14 additions & 17 deletions tests/test_decorator_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,20 @@ async def setup_script(hass, notify_q, now, source):

Function.hass = None

with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
"custom_components.pyscript.glob.iglob", return_value=scripts
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source)), patch(
"custom_components.pyscript.trigger.dt_now", return_value=now
), patch(
"homeassistant.config.load_yaml_config_file", return_value={}
), patch(
"custom_components.pyscript.open", mock_open(read_data=source)
), patch(
"custom_components.pyscript.watchdog_start", return_value=None
), patch(
"custom_components.pyscript.os.path.getmtime", return_value=1000
), patch(
"custom_components.pyscript.global_ctx.os.path.getmtime", return_value=1000
), patch(
"custom_components.pyscript.install_requirements",
return_value=None,
with (
patch("custom_components.pyscript.os.path.isdir", return_value=True),
patch("custom_components.pyscript.glob.iglob", return_value=scripts),
patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source)),
patch("custom_components.pyscript.trigger.dt_now", return_value=now),
patch("homeassistant.config.load_yaml_config_file", return_value={}),
patch("custom_components.pyscript.open", mock_open(read_data=source)),
patch("custom_components.pyscript.watchdog_start", return_value=None),
patch("custom_components.pyscript.os.path.getmtime", return_value=1000),
patch("custom_components.pyscript.global_ctx.os.path.getmtime", return_value=1000),
patch(
"custom_components.pyscript.install_requirements",
return_value=None,
),
):
assert await async_setup_component(hass, "pyscript", {DOMAIN: {}})

Expand Down
31 changes: 14 additions & 17 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,20 @@ async def setup_script(hass, notify_q, now, source):

Function.hass = None

with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
"custom_components.pyscript.glob.iglob", return_value=scripts
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source)), patch(
"custom_components.pyscript.trigger.dt_now", return_value=now
), patch(
"homeassistant.config.load_yaml_config_file", return_value={}
), patch(
"custom_components.pyscript.open", mock_open(read_data=source)
), patch(
"custom_components.pyscript.watchdog_start", return_value=None
), patch(
"custom_components.pyscript.os.path.getmtime", return_value=1000
), patch(
"custom_components.pyscript.global_ctx.os.path.getmtime", return_value=1000
), patch(
"custom_components.pyscript.install_requirements",
return_value=None,
with (
patch("custom_components.pyscript.os.path.isdir", return_value=True),
patch("custom_components.pyscript.glob.iglob", return_value=scripts),
patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source)),
patch("custom_components.pyscript.trigger.dt_now", return_value=now),
patch("homeassistant.config.load_yaml_config_file", return_value={}),
patch("custom_components.pyscript.open", mock_open(read_data=source)),
patch("custom_components.pyscript.watchdog_start", return_value=None),
patch("custom_components.pyscript.os.path.getmtime", return_value=1000),
patch("custom_components.pyscript.global_ctx.os.path.getmtime", return_value=1000),
patch(
"custom_components.pyscript.install_requirements",
return_value=None,
),
):
assert await async_setup_component(hass, "pyscript", {DOMAIN: {}})

Expand Down
Loading
Loading