diff --git a/homeassistant/config.py b/homeassistant/config.py index 0828084ce77..283f8726e2b 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -330,7 +330,7 @@ async def async_ensure_config_exists(hass: HomeAssistant) -> bool: if os.path.isfile(config_path): return True - print( + print( # noqa: T201 "Unable to find configuration. Creating default one in", hass.config.config_dir ) return await async_create_default_config(hass) @@ -384,7 +384,7 @@ def _write_default_config(config_dir: str) -> bool: return True except OSError: - print("Unable to create default configuration file", config_path) + print("Unable to create default configuration file", config_path) # noqa: T201 return False diff --git a/pyproject.toml b/pyproject.toml index c4542921155..4f41d1d2597 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -262,6 +262,7 @@ select = [ "D", # docstrings "E", # pycodestyle "F", # pyflakes/autoflake + "T20", # flake8-print "W", # pycodestyle "UP", # pyupgrade "PGH004", # Use specific rule codes when using noqa @@ -278,5 +279,10 @@ select = [ "homeassistant/components/mqtt/discovery.py" = ["C901"] "homeassistant/components/websocket_api/http.py" = ["C901"] +# Allow for main entry & scripts to write to stdout +"homeassistant/__main__.py" = ["T201"] +"homeassistant/scripts/*" = ["T201"] +"script/*" = ["T20"] + [tool.ruff.mccabe] max-complexity = 25 diff --git a/setup.cfg b/setup.cfg index 709b9e4286a..1193bbd44d8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,3 +21,13 @@ ignore = D202, W504 noqa-require-code = True + +# Ignores, that are currently caused by mismatching configurations +# between ruff and flake8 configurations. Once ruff becomes permanent flake8 +# will be removed, including these ignores below. +# In case we decide not to continue with ruff, we should remove these +# and probably need to clean up a couple of noqa comments. +per-file-ignores = + homeassistant/config.py:NQA102 + tests/components/tts/conftest.py:NQA102 + tests/helpers/test_icon.py:NQA102 diff --git a/tests/components/elkm1/test_config_flow.py b/tests/components/elkm1/test_config_flow.py index a58528b700a..9bd3f949d7f 100644 --- a/tests/components/elkm1/test_config_flow.py +++ b/tests/components/elkm1/test_config_flow.py @@ -1587,9 +1587,6 @@ async def test_multiple_instances_with_tls_v12(hass): ) await hass.async_block_till_done() - import pprint - - pprint.pprint(result2) assert result2["type"] == "create_entry" assert result2["title"] == "guest_house" assert result2["data"] == { diff --git a/tests/components/tts/conftest.py b/tests/components/tts/conftest.py index 6d995978391..a8b9b4cf5ce 100644 --- a/tests/components/tts/conftest.py +++ b/tests/components/tts/conftest.py @@ -55,9 +55,9 @@ def empty_cache_dir(tmp_path, mock_init_cache_dir, mock_get_cache_files, request return # Print contents of dir if failed - print("Content of dir for", request.node.nodeid) + print("Content of dir for", request.node.nodeid) # noqa: T201 for fil in tmp_path.iterdir(): - print(fil.relative_to(tmp_path)) + print(fil.relative_to(tmp_path)) # noqa: T201 # To show the log. assert False diff --git a/tests/helpers/test_discovery.py b/tests/helpers/test_discovery.py index 73376cb8580..3a2d0e7fbac 100644 --- a/tests/helpers/test_discovery.py +++ b/tests/helpers/test_discovery.py @@ -166,7 +166,6 @@ async def test_1st_discovers_2nd_component(hass): async def component1_setup(hass, config): """Set up mock component.""" - print("component1 setup") await discovery.async_discover( hass, "test_component2", {}, "test_component2", {} ) diff --git a/tests/helpers/test_icon.py b/tests/helpers/test_icon.py index 033a6cd6b69..12972f230e7 100644 --- a/tests/helpers/test_icon.py +++ b/tests/helpers/test_icon.py @@ -16,7 +16,7 @@ def test_battery_icon(): iconbase = "mdi:battery" for level in range(0, 100, 5): - print( + print( # noqa: T201 "Level: %d. icon: %s, charging: %s" % ( level, diff --git a/tests/helpers/test_sun.py b/tests/helpers/test_sun.py index 7d8dce1ad4b..1cad1b49bdc 100644 --- a/tests/helpers/test_sun.py +++ b/tests/helpers/test_sun.py @@ -183,12 +183,6 @@ def test_norway_in_june(hass): june = datetime(2016, 6, 1, tzinfo=dt_util.UTC) - print(sun.get_astral_event_date(hass, SUN_EVENT_SUNRISE, datetime(2017, 7, 25))) - print(sun.get_astral_event_date(hass, SUN_EVENT_SUNSET, datetime(2017, 7, 25))) - - print(sun.get_astral_event_date(hass, SUN_EVENT_SUNRISE, datetime(2017, 7, 26))) - print(sun.get_astral_event_date(hass, SUN_EVENT_SUNSET, datetime(2017, 7, 26))) - assert sun.get_astral_event_next(hass, SUN_EVENT_SUNRISE, june) == datetime( 2016, 7, 24, 22, 59, 45, 689645, tzinfo=dt_util.UTC ) diff --git a/tests/test_loader.py b/tests/test_loader.py index 4fa7a141319..b3ba5d29724 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -24,21 +24,13 @@ async def test_component_dependencies(hass): mock_integration(hass, MockModule("mod1", ["mod3"])) with pytest.raises(loader.CircularDependency): - print( - await loader._async_component_dependencies( - hass, "mod_3", mod_3, set(), set() - ) - ) + await loader._async_component_dependencies(hass, "mod_3", mod_3, set(), set()) # Depend on non-existing component mod_1 = mock_integration(hass, MockModule("mod1", ["nonexisting"])) with pytest.raises(loader.IntegrationNotFound): - print( - await loader._async_component_dependencies( - hass, "mod_1", mod_1, set(), set() - ) - ) + await loader._async_component_dependencies(hass, "mod_1", mod_1, set(), set()) # Having an after dependency 2 deps down that is circular mod_1 = mock_integration( @@ -46,11 +38,7 @@ async def test_component_dependencies(hass): ) with pytest.raises(loader.CircularDependency): - print( - await loader._async_component_dependencies( - hass, "mod_3", mod_3, set(), set() - ) - ) + await loader._async_component_dependencies(hass, "mod_3", mod_3, set(), set()) def test_component_loader(hass):