Skip to content

Commit 0c68d71

Browse files
authored
chore: fix to ruff for lint and format (#1382)
1 parent 9d8dd27 commit 0c68d71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4442
-2502
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,18 @@ repos:
3838
hooks:
3939
- id: pyupgrade
4040
args: [--py37-plus]
41-
- repo: https://github.com/PyCQA/isort
42-
rev: 5.12.0
41+
- repo: https://github.com/astral-sh/ruff-pre-commit
42+
rev: v0.5.0
4343
hooks:
44-
- id: isort
45-
- repo: https://github.com/psf/black
46-
rev: 22.8.0
47-
hooks:
48-
- id: black
44+
- id: ruff
45+
args: [--fix, --exit-non-zero-on-fix]
46+
- id: ruff-format
4947
# - repo: https://github.com/codespell-project/codespell
5048
# rev: v2.2.1
5149
# hooks:
5250
# - id: codespell
5351
- repo: https://github.com/PyCQA/flake8
54-
rev: 5.0.4
52+
rev: 7.1.0
5553
hooks:
5654
- id: flake8
5755
- repo: https://github.com/pre-commit/mirrors-mypy

bench/create_destory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Benchmark for AsyncZeroconf."""
2+
23
import asyncio
34
import time
45

@@ -17,7 +18,9 @@ async def _run() -> None:
1718
start = time.perf_counter()
1819
await _create_destroy(iterations)
1920
duration = time.perf_counter() - start
20-
print(f"Creating and destroying {iterations} Zeroconf instances took {duration} seconds")
21+
print(
22+
f"Creating and destroying {iterations} Zeroconf instances took {duration} seconds"
23+
)
2124

2225

2326
asyncio.run(_run())

bench/incoming.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Benchmark for DNSIncoming."""
2+
23
import socket
34
import timeit
45
from typing import List
@@ -121,8 +122,8 @@ def generate_packets() -> List[bytes]:
121122
const._TYPE_TXT,
122123
const._CLASS_IN | const._CLASS_UNIQUE,
123124
const._DNS_OTHER_TTL,
124-
b'\x13md=HASS Bridge W9DN\x06pv=1.0\x14id=11:8E:DB:5B:5C:C5\x05c#=12\x04s#=1'
125-
b'\x04ff=0\x04ci=2\x04sf=0\x0bsh=6fLM5A==',
125+
b"\x13md=HASS Bridge W9DN\x06pv=1.0\x14id=11:8E:DB:5B:5C:C5\x05c#=12\x04s#=1"
126+
b"\x04ff=0\x04ci=2\x04sf=0\x0bsh=6fLM5A==",
126127
),
127128
0,
128129
)

bench/outgoing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Benchmark for DNSOutgoing."""
2+
23
import socket
34
import timeit
45

@@ -113,8 +114,8 @@ def generate_packets() -> DNSOutgoing:
113114
const._TYPE_TXT,
114115
const._CLASS_IN | const._CLASS_UNIQUE,
115116
const._DNS_OTHER_TTL,
116-
b'\x13md=HASS Bridge W9DN\x06pv=1.0\x14id=11:8E:DB:5B:5C:C5\x05c#=12\x04s#=1'
117-
b'\x04ff=0\x04ci=2\x04sf=0\x0bsh=6fLM5A==',
117+
b"\x13md=HASS Bridge W9DN\x06pv=1.0\x14id=11:8E:DB:5B:5C:C5\x05c#=12\x04s#=1"
118+
b"\x04ff=0\x04ci=2\x04sf=0\x0bsh=6fLM5A==",
118119
),
119120
0,
120121
)

build_ext.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def build(setup_kwargs: Any) -> None:
4747
cmdclass=dict(build_ext=BuildExt),
4848
)
4949
)
50-
setup_kwargs["exclude_package_data"] = {pkg: ["*.c"] for pkg in setup_kwargs["packages"]}
50+
setup_kwargs["exclude_package_data"] = {
51+
pkg: ["*.c"] for pkg in setup_kwargs["packages"]
52+
}
5153
except Exception:
5254
if os.environ.get("REQUIRE_CYTHON"):
5355
raise

docs/conf.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323

2424
# Add any Sphinx extension module names here, as strings. They can be extensions
2525
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
26-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx']
26+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx"]
2727

2828
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
29+
templates_path = ["_templates"]
3030

3131
# The suffix of source filenames.
32-
source_suffix = '.rst'
32+
source_suffix = ".rst"
3333

3434
# The encoding of source files.
3535
# source_encoding = 'utf-8-sig'
3636

3737
# The master toctree document.
38-
master_doc = 'index'
38+
master_doc = "index"
3939

4040
# General information about the project.
41-
project = 'python-zeroconf'
42-
copyright = 'python-zeroconf authors'
41+
project = "python-zeroconf"
42+
copyright = "python-zeroconf authors"
4343

4444
# The version info for the project you're documenting, acts as replacement for
4545
# |version| and |release|, also used in various other places throughout the
@@ -62,7 +62,7 @@
6262

6363
# List of patterns, relative to source directory, that match files and
6464
# directories to ignore when looking for source files.
65-
exclude_patterns = ['_build']
65+
exclude_patterns = ["_build"]
6666

6767
# The reST default role (used for this markup: `text`) to use for all documents.
6868
# default_role = None
@@ -79,7 +79,7 @@
7979
# show_authors = False
8080

8181
# The name of the Pygments (syntax highlighting) style to use.
82-
pygments_style = 'sphinx'
82+
pygments_style = "sphinx"
8383

8484
# A list of ignored prefixes for module index sorting.
8585
# modindex_common_prefix = []
@@ -92,7 +92,7 @@
9292

9393
# The theme to use for HTML and HTML Help pages. See the documentation for
9494
# a list of builtin themes.
95-
html_theme = 'default'
95+
html_theme = "default"
9696

9797
# Theme options are theme-specific and customize the look and feel of a theme
9898
# further. For a list of options available for each theme, see the
@@ -121,7 +121,7 @@
121121
# Add any paths that contain custom static files (such as style sheets) here,
122122
# relative to this directory. They are copied after the builtin static files,
123123
# so a file named "default.css" will overwrite the builtin "default.css".
124-
html_static_path = ['_static']
124+
html_static_path = ["_static"]
125125

126126
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
127127
# using the given strftime format.
@@ -133,8 +133,8 @@
133133

134134
# Custom sidebar templates, maps document names to template names.
135135
html_sidebars = {
136-
'index': ('sidebar.html', 'sourcelink.html', 'searchbox.html'),
137-
'**': ('localtoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html'),
136+
"index": ("sidebar.html", "sourcelink.html", "searchbox.html"),
137+
"**": ("localtoc.html", "relations.html", "sourcelink.html", "searchbox.html"),
138138
}
139139

140140
# Additional templates that should be rendered to pages, maps page names to
@@ -168,7 +168,7 @@
168168
# html_file_suffix = None
169169

170170
# Output file base name for HTML help builder.
171-
htmlhelp_basename = 'zeroconfdoc'
171+
htmlhelp_basename = "zeroconfdoc"
172172

173173

174174
# -- Options for LaTeX output --------------------------------------------------
@@ -231,17 +231,17 @@
231231

232232

233233
# Example configuration for intersphinx: refer to the Python standard library.
234-
intersphinx_mapping = {'http://docs.python.org/': None}
234+
intersphinx_mapping = {"http://docs.python.org/": None}
235235

236236

237237
def setup(app): # type: ignore[no-untyped-def]
238-
app.connect('autodoc-skip-member', skip_member)
238+
app.connect("autodoc-skip-member", skip_member)
239239

240240

241241
def skip_member(app, what, name, obj, skip, options): # type: ignore[no-untyped-def]
242242
return (
243243
skip
244-
or getattr(obj, '__doc__', None) is None
245-
or getattr(obj, '__private__', False) is True
246-
or getattr(getattr(obj, '__func__', None), '__private__', False) is True
244+
or getattr(obj, "__doc__", None) is None
245+
or getattr(obj, "__private__", False) is True
246+
or getattr(getattr(obj, "__func__", None), "__private__", False) is True
247247
)

examples/async_apple_scanner.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
""" Scan for apple devices. """
3+
"""Scan for apple devices."""
44

55
import argparse
66
import asyncio
@@ -43,15 +43,21 @@ def async_on_service_state_change(
4343
device_name = f"{base_name}.{DEVICE_INFO_SERVICE}"
4444
asyncio.ensure_future(_async_show_service_info(zeroconf, service_type, name))
4545
# Also probe for device info
46-
asyncio.ensure_future(_async_show_service_info(zeroconf, DEVICE_INFO_SERVICE, device_name))
46+
asyncio.ensure_future(
47+
_async_show_service_info(zeroconf, DEVICE_INFO_SERVICE, device_name)
48+
)
4749

4850

49-
async def _async_show_service_info(zeroconf: Zeroconf, service_type: str, name: str) -> None:
51+
async def _async_show_service_info(
52+
zeroconf: Zeroconf, service_type: str, name: str
53+
) -> None:
5054
info = AsyncServiceInfo(service_type, name)
5155
await info.async_request(zeroconf, 3000, question_type=DNSQuestionType.QU)
5256
print("Info from zeroconf.get_service_info: %r" % (info))
5357
if info:
54-
addresses = ["%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_addresses()]
58+
addresses = [
59+
"%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_addresses()
60+
]
5561
print(" Name: %s" % name)
5662
print(" Addresses: %s" % ", ".join(addresses))
5763
print(" Weight: %d, priority: %d" % (info.weight, info.priority))
@@ -64,7 +70,7 @@ async def _async_show_service_info(zeroconf: Zeroconf, service_type: str, name:
6470
print(" No properties")
6571
else:
6672
print(" No info")
67-
print('\n')
73+
print("\n")
6874

6975

7076
class AsyncAppleScanner:
@@ -77,10 +83,17 @@ async def async_run(self) -> None:
7783
self.aiozc = AsyncZeroconf(ip_version=ip_version)
7884
await self.aiozc.zeroconf.async_wait_for_start()
7985
print("\nBrowsing %s service(s), press Ctrl-C to exit...\n" % ALL_SERVICES)
80-
kwargs = {'handlers': [async_on_service_state_change], 'question_type': DNSQuestionType.QU}
86+
kwargs = {
87+
"handlers": [async_on_service_state_change],
88+
"question_type": DNSQuestionType.QU,
89+
}
8190
if self.args.target:
8291
kwargs["addr"] = self.args.target
83-
self.aiobrowser = AsyncServiceBrowser(self.aiozc.zeroconf, ALL_SERVICES, **kwargs) # type: ignore
92+
self.aiobrowser = AsyncServiceBrowser(
93+
self.aiozc.zeroconf,
94+
ALL_SERVICES,
95+
**kwargs, # type: ignore[arg-type]
96+
)
8497
while True:
8598
await asyncio.sleep(1)
8699

@@ -91,19 +104,19 @@ async def async_close(self) -> None:
91104
await self.aiozc.async_close()
92105

93106

94-
if __name__ == '__main__':
107+
if __name__ == "__main__":
95108
logging.basicConfig(level=logging.DEBUG)
96109

97110
parser = argparse.ArgumentParser()
98-
parser.add_argument('--debug', action='store_true')
111+
parser.add_argument("--debug", action="store_true")
99112
version_group = parser.add_mutually_exclusive_group()
100-
version_group.add_argument('--target', help='Unicast target')
101-
version_group.add_argument('--v6', action='store_true')
102-
version_group.add_argument('--v6-only', action='store_true')
113+
version_group.add_argument("--target", help="Unicast target")
114+
version_group.add_argument("--v6", action="store_true")
115+
version_group.add_argument("--v6-only", action="store_true")
103116
args = parser.parse_args()
104117

105118
if args.debug:
106-
logging.getLogger('zeroconf').setLevel(logging.DEBUG)
119+
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
107120
if args.v6:
108121
ip_version = IPVersion.All
109122
elif args.v6_only:

examples/async_browser.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
""" Example of browsing for a service.
3+
"""Example of browsing for a service.
44
55
The default is HTTP and HAP; use --find to search for all available services in the network
66
"""
@@ -28,12 +28,17 @@ def async_on_service_state_change(
2828
asyncio.ensure_future(async_display_service_info(zeroconf, service_type, name))
2929

3030

31-
async def async_display_service_info(zeroconf: Zeroconf, service_type: str, name: str) -> None:
31+
async def async_display_service_info(
32+
zeroconf: Zeroconf, service_type: str, name: str
33+
) -> None:
3234
info = AsyncServiceInfo(service_type, name)
3335
await info.async_request(zeroconf, 3000)
3436
print("Info from zeroconf.get_service_info: %r" % (info))
3537
if info:
36-
addresses = ["%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_scoped_addresses()]
38+
addresses = [
39+
"%s:%d" % (addr, cast(int, info.port))
40+
for addr in info.parsed_scoped_addresses()
41+
]
3742
print(" Name: %s" % name)
3843
print(" Addresses: %s" % ", ".join(addresses))
3944
print(" Weight: %d, priority: %d" % (info.weight, info.priority))
@@ -46,7 +51,7 @@ async def async_display_service_info(zeroconf: Zeroconf, service_type: str, name
4651
print(" No properties")
4752
else:
4853
print(" No info")
49-
print('\n')
54+
print("\n")
5055

5156

5257
class AsyncRunner:
@@ -61,7 +66,9 @@ async def async_run(self) -> None:
6166
services = ["_http._tcp.local.", "_hap._tcp.local."]
6267
if self.args.find:
6368
services = list(
64-
await AsyncZeroconfServiceTypes.async_find(aiozc=self.aiozc, ip_version=ip_version)
69+
await AsyncZeroconfServiceTypes.async_find(
70+
aiozc=self.aiozc, ip_version=ip_version
71+
)
6572
)
6673

6774
print("\nBrowsing %s service(s), press Ctrl-C to exit...\n" % services)
@@ -78,19 +85,21 @@ async def async_close(self) -> None:
7885
await self.aiozc.async_close()
7986

8087

81-
if __name__ == '__main__':
88+
if __name__ == "__main__":
8289
logging.basicConfig(level=logging.DEBUG)
8390

8491
parser = argparse.ArgumentParser()
85-
parser.add_argument('--debug', action='store_true')
86-
parser.add_argument('--find', action='store_true', help='Browse all available services')
92+
parser.add_argument("--debug", action="store_true")
93+
parser.add_argument(
94+
"--find", action="store_true", help="Browse all available services"
95+
)
8796
version_group = parser.add_mutually_exclusive_group()
88-
version_group.add_argument('--v6', action='store_true')
89-
version_group.add_argument('--v6-only', action='store_true')
97+
version_group.add_argument("--v6", action="store_true")
98+
version_group.add_argument("--v6-only", action="store_true")
9099
args = parser.parse_args()
91100

92101
if args.debug:
93-
logging.getLogger('zeroconf').setLevel(logging.DEBUG)
102+
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
94103
if args.v6:
95104
ip_version = IPVersion.All
96105
elif args.v6_only:

examples/async_registration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ async def unregister_services(self, infos: List[AsyncServiceInfo]) -> None:
3333
await self.aiozc.async_close()
3434

3535

36-
if __name__ == '__main__':
36+
if __name__ == "__main__":
3737
logging.basicConfig(level=logging.DEBUG)
3838

3939
parser = argparse.ArgumentParser()
40-
parser.add_argument('--debug', action='store_true')
40+
parser.add_argument("--debug", action="store_true")
4141
version_group = parser.add_mutually_exclusive_group()
42-
version_group.add_argument('--v6', action='store_true')
43-
version_group.add_argument('--v6-only', action='store_true')
42+
version_group.add_argument("--v6", action="store_true")
43+
version_group.add_argument("--v6-only", action="store_true")
4444
args = parser.parse_args()
4545

4646
if args.debug:
47-
logging.getLogger('zeroconf').setLevel(logging.DEBUG)
47+
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
4848
if args.v6:
4949
ip_version = IPVersion.All
5050
elif args.v6_only:
@@ -60,7 +60,7 @@ async def unregister_services(self, infos: List[AsyncServiceInfo]) -> None:
6060
f"Paul's Test Web Site {i}._http._tcp.local.",
6161
addresses=[socket.inet_aton("127.0.0.1")],
6262
port=80,
63-
properties={'path': '/~paulsm/'},
63+
properties={"path": "/~paulsm/"},
6464
server=f"zcdemohost-{i}.local.",
6565
)
6666
)

0 commit comments

Comments
 (0)