| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,9 +18,7 @@ async def _run() -> None: | |||
| 18 | 18 | start = time.perf_counter() | |
| 19 | 19 | await _create_destroy(iterations) | |
| 20 | 20 | duration = time.perf_counter() - start | |
| 21 | - print( | ||
| 22 | - f"Creating and destroying {iterations} Zeroconf instances took {duration} seconds" | ||
| 23 | - ) | ||
| 21 | + print(f"Creating and destroying {iterations} Zeroconf instances took {duration} seconds") | ||
| 24 | 22 | ||
| 25 | 23 | ||
| 26 | 24 | asyncio.run(_run()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,7 +178,7 @@ def generate_packets() -> List[bytes]: | |||
| 178 | 178 | ||
| 179 | 179 | def parse_incoming_message() -> None: | |
| 180 | 180 | for packet in packets: | |
| 181 | - DNSIncoming(packet).answers | ||
| 181 | + DNSIncoming(packet).answers # noqa: B018 | ||
| 182 | 182 | break | |
| 183 | 183 | ||
| 184 | 184 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | 15 | def process_properties() -> None: | |
| 16 | 16 | info._properties = None | |
| 17 | - info.properties | ||
| 17 | + info.properties # noqa: B018 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | 20 | count = 100000 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,16 +1,19 @@ | |||
| 1 | 1 | """Build optional cython modules.""" | |
| 2 | 2 | ||
| 3 | + import logging | ||
| 3 | 4 | import os | |
| 4 | 5 | from distutils.command.build_ext import build_ext | |
| 5 | 6 | from typing import Any | |
| 6 | 7 | ||
| 8 | + _LOGGER = logging.getLogger(__name__) | ||
| 9 | + | ||
| 7 | 10 | ||
| 8 | 11 | class BuildExt(build_ext): | |
| 9 | 12 | def build_extensions(self) -> None: | |
| 10 | 13 | try: | |
| 11 | 14 | super().build_extensions() | |
| 12 | 15 | except Exception: | |
| 13 | - pass | ||
| 16 | + _LOGGER.info("Failed to build cython extensions") | ||
| 14 | 17 | ||
| 15 | 18 | ||
| 16 | 19 | def build(setup_kwargs: Any) -> None: | |
@@ -20,8 +23,8 @@ def build(setup_kwargs: Any) -> None: | |||
| 20 | 23 | from Cython.Build import cythonize | |
| 21 | 24 | ||
| 22 | 25 | setup_kwargs.update( | |
| 23 | - dict( | ||
| 24 | - ext_modules=cythonize( | ||
| 26 | + { | ||
| 27 | + "ext_modules": cythonize( | ||
| 25 | 28 | [ | |
| 26 | 29 | "src/zeroconf/_dns.py", | |
| 27 | 30 | "src/zeroconf/_cache.py", | |
@@ -44,12 +47,10 @@ def build(setup_kwargs: Any) -> None: | |||
| 44 | 47 | ], | |
| 45 | 48 | compiler_directives={"language_level": "3"}, # Python 3 | |
| 46 | 49 | ), | |
| 47 | - cmdclass=dict(build_ext=BuildExt), | ||
| 48 | - ) | ||
| 50 | + "cmdclass": {"build_ext": BuildExt}, | ||
| 51 | + } | ||
| 49 | 52 | ) | |
| 50 | - setup_kwargs["exclude_package_data"] = { | ||
| 51 | - pkg: ["*.c"] for pkg in setup_kwargs["packages"] | ||
| 52 | - } | ||
| 53 | + setup_kwargs["exclude_package_data"] = {pkg: ["*.c"] for pkg in setup_kwargs["packages"]} | ||
| 53 | 54 | except Exception: | |
| 54 | 55 | if os.environ.get("REQUIRE_CYTHON"): | |
| 55 | 56 | raise | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,8 @@ | |||
| 32 | 32 | ||
| 33 | 33 | log = logging.getLogger(__name__) | |
| 34 | 34 | ||
| 35 | + _PENDING_TASKS: set[asyncio.Task] = set() | ||
| 36 | + | ||
| 35 | 37 | ||
| 36 | 38 | def async_on_service_state_change( | |
| 37 | 39 | zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange | |
@@ -41,23 +43,21 @@ def async_on_service_state_change( | |||
| 41 | 43 | return | |
| 42 | 44 | base_name = name[: -len(service_type) - 1] | |
| 43 | 45 | device_name = f"{base_name}.{DEVICE_INFO_SERVICE}" | |
| 44 | - asyncio.ensure_future(_async_show_service_info(zeroconf, service_type, name)) | ||
| 46 | + task = asyncio.ensure_future(_async_show_service_info(zeroconf, service_type, name)) | ||
| 47 | + _PENDING_TASKS.add(task) | ||
| 48 | + task.add_done_callback(_PENDING_TASKS.discard) | ||
| 45 | 49 | # Also probe for device info | |
| 46 | - asyncio.ensure_future( | ||
| 47 | - _async_show_service_info(zeroconf, DEVICE_INFO_SERVICE, device_name) | ||
| 48 | - ) | ||
| 50 | + task = asyncio.ensure_future(_async_show_service_info(zeroconf, DEVICE_INFO_SERVICE, device_name)) | ||
| 51 | + _PENDING_TASKS.add(task) | ||
| 52 | + task.add_done_callback(_PENDING_TASKS.discard) | ||
| 49 | 53 | ||
| 50 | 54 | ||
| 51 | - async def _async_show_service_info( | ||
| 52 | - zeroconf: Zeroconf, service_type: str, name: str | ||
| 53 | - ) -> None: | ||
| 55 | + async def _async_show_service_info(zeroconf: Zeroconf, service_type: str, name: str) -> None: | ||
| 54 | 56 | info = AsyncServiceInfo(service_type, name) | |
| 55 | 57 | await info.async_request(zeroconf, 3000, question_type=DNSQuestionType.QU) | |
| 56 | 58 | print("Info from zeroconf.get_service_info: %r" % (info)) | |
| 57 | 59 | if info: | |
| 58 | - addresses = [ | ||
| 59 | - "%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_addresses() | ||
| 60 | - ] | ||
| 60 | + addresses = ["%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_addresses()] | ||
| 61 | 61 | print(" Name: %s" % name) | |
| 62 | 62 | print(" Addresses: %s" % ", ".join(addresses)) | |
| 63 | 63 | print(" Weight: %d, priority: %d" % (info.weight, info.priority)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,27 +18,26 @@ | |||
| 18 | 18 | AsyncZeroconfServiceTypes, | |
| 19 | 19 | ) | |
| 20 | 20 | ||
| 21 | + _PENDING_TASKS: set[asyncio.Task] = set() | ||
| 22 | + | ||
| 21 | 23 | ||
| 22 | 24 | def async_on_service_state_change( | |
| 23 | 25 | zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange | |
| 24 | 26 | ) -> None: | |
| 25 | 27 | print(f"Service {name} of type {service_type} state changed: {state_change}") | |
| 26 | 28 | if state_change is not ServiceStateChange.Added: | |
| 27 | 29 | return | |
| 28 | - asyncio.ensure_future(async_display_service_info(zeroconf, service_type, name)) | ||
| 30 | + task = asyncio.ensure_future(async_display_service_info(zeroconf, service_type, name)) | ||
| 31 | + _PENDING_TASKS.add(task) | ||
| 32 | + task.add_done_callback(_PENDING_TASKS.discard) | ||
| 29 | 33 | ||
| 30 | 34 | ||
| 31 | - async def async_display_service_info( | ||
| 32 | - zeroconf: Zeroconf, service_type: str, name: str | ||
| 33 | - ) -> None: | ||
| 35 | + async def async_display_service_info(zeroconf: Zeroconf, service_type: str, name: str) -> None: | ||
| 34 | 36 | info = AsyncServiceInfo(service_type, name) | |
| 35 | 37 | await info.async_request(zeroconf, 3000) | |
| 36 | 38 | print("Info from zeroconf.get_service_info: %r" % (info)) | |
| 37 | 39 | if info: | |
| 38 | - addresses = [ | ||
| 39 | - "%s:%d" % (addr, cast(int, info.port)) | ||
| 40 | - for addr in info.parsed_scoped_addresses() | ||
| 41 | - ] | ||
| 40 | + addresses = ["%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_scoped_addresses()] | ||
| 42 | 41 | print(" Name: %s" % name) | |
| 43 | 42 | print(" Addresses: %s" % ", ".join(addresses)) | |
| 44 | 43 | print(" Weight: %d, priority: %d" % (info.weight, info.priority)) | |
@@ -66,9 +65,7 @@ async def async_run(self) -> None: | |||
| 66 | 65 | services = ["_http._tcp.local.", "_hap._tcp.local."] | |
| 67 | 66 | if self.args.find: | |
| 68 | 67 | services = list( | |
| 69 | - await AsyncZeroconfServiceTypes.async_find( | ||
| 70 | - aiozc=self.aiozc, ip_version=ip_version | ||
| 71 | - ) | ||
| 68 | + await AsyncZeroconfServiceTypes.async_find(aiozc=self.aiozc, ip_version=ip_version) | ||
| 72 | 69 | ) | |
| 73 | 70 | ||
| 74 | 71 | print("\nBrowsing %s service(s), press Ctrl-C to exit...\n" % services) | |
@@ -90,9 +87,7 @@ async def async_close(self) -> None: | |||
| 90 | 87 | ||
| 91 | 88 | parser = argparse.ArgumentParser() | |
| 92 | 89 | parser.add_argument("--debug", action="store_true") | |
| 93 | - parser.add_argument( | ||
| 94 | - "--find", action="store_true", help="Browse all available services" | ||
| 95 | - ) | ||
| 90 | + parser.add_argument("--find", action="store_true", help="Browse all available services") | ||
| 96 | 91 | version_group = parser.add_mutually_exclusive_group() | |
| 97 | 92 | version_group.add_argument("--v6", action="store_true") | |
| 98 | 93 | version_group.add_argument("--v6-only", action="store_true") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,10 +31,7 @@ async def async_watch_services(aiozc: AsyncZeroconf) -> None: | |||
| 31 | 31 | for info in infos: | |
| 32 | 32 | print("Info for %s" % (info.name)) | |
| 33 | 33 | if info: | |
| 34 | - addresses = [ | ||
| 35 | - "%s:%d" % (addr, cast(int, info.port)) | ||
| 36 | - for addr in info.parsed_addresses() | ||
| 37 | - ] | ||
| 34 | + addresses = ["%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_addresses()] | ||
| 38 | 35 | print(" Addresses: %s" % ", ".join(addresses)) | |
| 39 | 36 | print(" Weight: %d, priority: %d" % (info.weight, info.priority)) | |
| 40 | 37 | print(f" Server: {info.server}") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,10 +29,7 @@ def on_service_state_change( | |||
| 29 | 29 | print("Info from zeroconf.get_service_info: %r" % (info)) | |
| 30 | 30 | ||
| 31 | 31 | if info: | |
| 32 | - addresses = [ | ||
| 33 | - "%s:%d" % (addr, cast(int, info.port)) | ||
| 34 | - for addr in info.parsed_scoped_addresses() | ||
| 35 | - ] | ||
| 32 | + addresses = ["%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_scoped_addresses()] | ||
| 36 | 33 | print(" Addresses: %s" % ", ".join(addresses)) | |
| 37 | 34 | print(" Weight: %d, priority: %d" % (info.weight, info.priority)) | |
| 38 | 35 | print(f" Server: {info.server}") | |
@@ -52,9 +49,7 @@ def on_service_state_change( | |||
| 52 | 49 | ||
| 53 | 50 | parser = argparse.ArgumentParser() | |
| 54 | 51 | parser.add_argument("--debug", action="store_true") | |
| 55 | - parser.add_argument( | ||
| 56 | - "--find", action="store_true", help="Browse all available services" | ||
| 57 | - ) | ||
| 52 | + parser.add_argument("--find", action="store_true", help="Browse all available services") | ||
| 58 | 53 | version_group = parser.add_mutually_exclusive_group() | |
| 59 | 54 | version_group.add_argument("--v6-only", action="store_true") | |
| 60 | 55 | version_group.add_argument("--v4-only", action="store_true") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,15 +34,10 @@ | |||
| 34 | 34 | r.register_service(info) | |
| 35 | 35 | print(" Registration done.") | |
| 36 | 36 | print("2. Testing query of service information...") | |
| 37 | - print( | ||
| 38 | - " Getting ZOE service: %s" | ||
| 39 | - % (r.get_service_info("_http._tcp.local.", "ZOE._http._tcp.local.")) | ||
| 40 | - ) | ||
| 37 | + print(" Getting ZOE service: %s" % (r.get_service_info("_http._tcp.local.", "ZOE._http._tcp.local."))) | ||
| 41 | 38 | print(" Query done.") | |
| 42 | 39 | print("3. Testing query of own service...") | |
| 43 | - queried_info = r.get_service_info( | ||
| 44 | - "_http._tcp.local.", "My Service Name._http._tcp.local." | ||
| 45 | - ) | ||
| 40 | + queried_info = r.get_service_info("_http._tcp.local.", "My Service Name._http._tcp.local.") | ||
| 46 | 41 | assert queried_info | |
| 47 | 42 | assert set(queried_info.parsed_addresses()) == expected | |
| 48 | 43 | print(f" Getting self: {queried_info}") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,10 +63,28 @@ cython = "^3.0.5" | |||
| 63 | 63 | setuptools = "^65.6.3" | |
| 64 | 64 | pytest-timeout = "^2.1.0" | |
| 65 | 65 | ||
| 66 | - [tool.black] | ||
| 66 | + [tool.ruff] | ||
| 67 | + target-version = "py38" | ||
| 67 | 68 | line-length = 110 | |
| 68 | - target_version = ['py37', 'py38', 'py39', 'py310', 'py311'] | ||
| 69 | - skip_string_normalization = true | ||
| 69 | + | ||
| 70 | + [tool.ruff.lint] | ||
| 71 | + ignore = [ | ||
| 72 | + "S101", # use of assert | ||
| 73 | + "S104", # S104 Possible binding to all interfaces | ||
| 74 | + "UP031", # UP031 use f-strings -- too many to fix right now | ||
| 75 | + ] | ||
| 76 | + select = [ | ||
| 77 | + "B", # flake8-bugbear | ||
| 78 | + "C4", # flake8-comprehensions | ||
| 79 | + "S", # flake8-bandit | ||
| 80 | + "F", # pyflake | ||
| 81 | + "E", # pycodestyle | ||
| 82 | + "W", # pycodestyle | ||
| 83 | + "UP", # pyupgrade | ||
| 84 | + "I", # isort | ||
| 85 | + "RUF", # ruff specific | ||
| 86 | + ] | ||
| 87 | + | ||
| 70 | 88 | ||
| 71 | 89 | [tool.pylint.BASIC] | |
| 72 | 90 | class-const-naming-style = "any" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments