mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Enable T20 (flake8-print) to ban use of print statements (#86525)
* Enable T20 (flake8-print) to ban use of print statements * Make compatible with flake8 config
This commit is contained in:
parent
c9499f6574
commit
73c4ac53d2
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
10
setup.cfg
10
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
|
||||
|
@ -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"] == {
|
||||
|
@ -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
|
||||
|
@ -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", {}
|
||||
)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user