From fd86b3e40216e0212cca6d575d0f73dd70a33108 Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Thu, 18 Jul 2024 12:38:04 +0200 Subject: [PATCH] Version cleanup --- asyncping3/__init__.py | 1 - asyncping3/_main.py | 43 -------------------------------------- asyncping3/command_line.py | 1 - pyproject.toml | 7 +++---- tests/test_benchmark.py | 4 +--- tests/test_command_line.py | 2 +- tests/test_multi.py | 1 - tests/test_ping3.py | 3 --- 8 files changed, 5 insertions(+), 57 deletions(-) delete mode 100644 asyncping3/_main.py diff --git a/asyncping3/__init__.py b/asyncping3/__init__.py index 5f6224c..a489610 100644 --- a/asyncping3/__init__.py +++ b/asyncping3/__init__.py @@ -17,7 +17,6 @@ from . import errors from .enums import ICMP_DEFAULT_CODE, IcmpType, IcmpTimeExceededCode, IcmpDestinationUnreachableCode -__version__ = "4.0.8" DEBUG = False # DEBUG: Show debug info for developers. (default False) EXCEPTIONS = False # EXCEPTIONS: Raise exception when delay is not available. LOGGER = None # LOGGER: Record logs into console or file. Logger object should have .debug() method. diff --git a/asyncping3/_main.py b/asyncping3/_main.py deleted file mode 100644 index 32fd4f0..0000000 --- a/asyncping3/_main.py +++ /dev/null @@ -1,43 +0,0 @@ -import argparse -import functools - -import anyio - -import asyncping3 - -def main(assigned_args = None) -> None: - """ - Parse and execute the call from command-line. - - Args: - assigned_args (list[str] | None): List of strings to parse. The default is taken from sys.argv. - - Returns: - Formatted ping results printed. - """ - parser = argparse.ArgumentParser(prog="pping", description="A pure python3 version of ICMP ping implementation using raw socket.", epilog="!!Note: ICMP messages can only be sent from processes running as root.") - parser.add_argument("-v", "--version", action="version", version=asyncping3.__version__) - parser.add_argument(dest="dest_addr", metavar="DEST_ADDR", nargs="*", default=("example.com", "8.8.8.8"), help="The destination address, can be an IP address or a domain name. Ex. 192.168.1.1/example.com.") - parser.add_argument("-c", "--count", dest="count", metavar="COUNT", type=int, default=4, help="How many pings should be sent. Default is 4.") - parser.add_argument("-t", "--timeout", dest="timeout", metavar="TIMEOUT", type=float, default=4, help="Time to wait for a response, in seconds. Default is 4.") - parser.add_argument("-i", "--interval", dest="interval", metavar="INTERVAL", type=float, default=0, help="Time to wait between each packet, in seconds. Default is 0.") - parser.add_argument("-I", "--interface", dest="interface", metavar="INTERFACE", default="", help="LINUX ONLY. The gateway network interface to ping from. Default is None.") - parser.add_argument("-S", "--src", dest="src_addr", metavar="SRC_ADDR", default="", help="The IP address to ping from. This is for multiple network interfaces. Default is None") - parser.add_argument("-T", "--ttl", dest="ttl", metavar="TTL", type=int, default=64, help="The Time-To-Live of the outgoing packet. Default is 64.") - parser.add_argument("-s", "--size", dest="size", metavar="SIZE", type=int, default=56, help="The ICMP packet payload size in bytes. Default is 56.") - parser.add_argument("-D", "--debug", action="store_true", dest="debug", help="Turn on DEBUG mode.") - parser.add_argument("-E", "--exceptions", action="store_true", dest="exceptions", help="Turn on EXCEPTIONS mode.") - args = parser.parse_args(assigned_args) - asyncping3.DEBUG = args.debug - asyncping3.EXCEPTIONS = args.exceptions - proc = functools.partial(asyncping3.verbose_ping, count=args.count, ttl=args.ttl, timeout=args.timeout, size=args.size, interval=args.interval, interface=args.interface, src_addr=args.src_addr) - - async def _main(): - async with anyio.create_task_group() as tg: - for addr in args.dest_addr: - tg.start_soon(proc, addr) - - anyio.run(_main, backend="trio") - -if __name__ == "__main__": - main() diff --git a/asyncping3/command_line.py b/asyncping3/command_line.py index 32fd4f0..41b7b09 100644 --- a/asyncping3/command_line.py +++ b/asyncping3/command_line.py @@ -16,7 +16,6 @@ def main(assigned_args = None) -> None: Formatted ping results printed. """ parser = argparse.ArgumentParser(prog="pping", description="A pure python3 version of ICMP ping implementation using raw socket.", epilog="!!Note: ICMP messages can only be sent from processes running as root.") - parser.add_argument("-v", "--version", action="version", version=asyncping3.__version__) parser.add_argument(dest="dest_addr", metavar="DEST_ADDR", nargs="*", default=("example.com", "8.8.8.8"), help="The destination address, can be an IP address or a domain name. Ex. 192.168.1.1/example.com.") parser.add_argument("-c", "--count", dest="count", metavar="COUNT", type=int, default=4, help="How many pings should be sent. Default is 4.") parser.add_argument("-t", "--timeout", dest="timeout", metavar="TIMEOUT", type=float, default=4, help="Time to wait for a response, in seconds. Default is 4.") diff --git a/pyproject.toml b/pyproject.toml index 78c0448..f7b3b02 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=61.0.0", "wheel"] +requires = ["setuptools>=61.0.0", "wheel", "setuptools-scm"] build-backend = "setuptools.build_meta" [project] @@ -40,8 +40,7 @@ ping3 = "asyncping3.command_line:main" [tool.setuptools] py-modules = ["asyncping3"] -[tool.setuptools.dynamic] -version = {attr = "asyncping3.__version__"} - [tool.setuptools.packages.find] exclude = ["contrib", "docs", "tests"] + +[tool.setuptools_scm] diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index fd5666f..30ce548 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -9,9 +9,7 @@ stmt = "anyio.run(ping3.ping,'127.0.0.1')" if __name__ == "__main__": - print(ping3.__version__) - - setup = "import anyio, sys; sys.path.insert(0, '{}'); import asyncping3 as ping3; print('ping3 version:', ping3.__version__)".format(dev_dir) + setup = f"import anyio, sys; sys.path.insert(0, {dev_dir !r}); import asyncping3 as ping3" for count in (1, 10, 100, 1000, 5000): print("Testing `{stmt}` {num} times...".format(stmt=stmt, num=count)) duration = timeit.timeit(stmt, setup=setup, number=count) diff --git a/tests/test_command_line.py b/tests/test_command_line.py index 754d2f6..5712820 100644 --- a/tests/test_command_line.py +++ b/tests/test_command_line.py @@ -7,7 +7,7 @@ from unittest.mock import patch sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from asyncping3 import _main as command_line # noqa: linter (pycodestyle) should not lint this line. +from asyncping3 import command_line # noqa: linter (pycodestyle) should not lint this line. from asyncping3 import errors # noqa: linter (pycodestyle) should not lint this line. import asyncping3 as ping3 diff --git a/tests/test_multi.py b/tests/test_multi.py index cb05dba..1eb2875 100644 --- a/tests/test_multi.py +++ b/tests/test_multi.py @@ -6,7 +6,6 @@ import asyncping3 as ping3 # noqa: linter (pycodestyle) should not lint this line. -# print("ping3=", ping3.__version__) # ping3.DEBUG = True HOSTS = ['baidu.com', 'example.com', '8.8.8.8', '1.1.1.1', '9.9.9.9', '127.0.0.1'] diff --git a/tests/test_ping3.py b/tests/test_ping3.py index ff6d92f..e37fd38 100644 --- a/tests/test_ping3.py +++ b/tests/test_ping3.py @@ -16,9 +16,6 @@ class TestPing3: """ping3 unittest""" - def test_version(self): - self.assertIsInstance(ping3.__version__, str) - @pytest.mark.anyio async def test_ping_normal(self): delay = await ping3.ping(DEST_DOMAIN)