Repository: kyan001/ping3

Issue:
Packaging
This should be a proper package. Toplevel "errors" and "enums" modules make no sense whatsoever.

Comments:

Patch:
diff --git a/UPDATES.md b/UPDATES.md
index f51a2bf..71722b1 100644
--- a/UPDATES.md
+++ b/UPDATES.md
@@ -1,4 +1,6 @@
 # UPDATES
+* 2.9.2:
+    * Converted to a proper package
 * 2.9.1:
     * Bug Fix: macOS is not treated as Linux now.
 * 2.9.0:
diff --git a/ping3.py b/ping3/__init__.py
similarity index 98%
rename from ping3.py
rename to ping3/__init__.py
index 95cb529..1b15ba9 100644
--- a/ping3.py
+++ b/ping3/__init__.py
@@ -12,8 +12,8 @@ import logging
 import functools
 import errno
 
-import errors
-from enums import ICMP_DEFAULT_CODE, IcmpType, IcmpTimeExceededCode, IcmpDestinationUnreachableCode
+from . import errors
+from .enums import ICMP_DEFAULT_CODE, IcmpType, IcmpTimeExceededCode, IcmpDestinationUnreachableCode
 
 __version__ = "2.9.1"
 DEBUG = False  # DEBUG: Show debug info for developers. (default False)
@@ -349,7 +349,3 @@ def verbose_ping(dest_addr: str, count: int = 4, interval: float = 0, *args, **k
             print("{value}{unit}".format(value=int(delay), unit=unit))
         i += 1
 
-
-if __name__ == "__main__":
-    import command_line_ping3
-    command_line_ping3.main()
diff --git a/command_line_ping3.py b/ping3/command_line.py
similarity index 98%
rename from command_line_ping3.py
rename to ping3/command_line.py
index e48bba6..8243653 100644
--- a/command_line_ping3.py
+++ b/ping3/command_line.py
@@ -30,3 +30,6 @@ def main(assigned_args: list = None):
 
     for addr in args.dest_addr:
         ping3.verbose_ping(addr, count=args.count, ttl=args.ttl, timeout=args.timeout, size=args.size, interval=args.interval, interface=args.interface)
+
+if __name__ == "__main__":
+    main()
diff --git a/enums.py b/ping3/enums.py
similarity index 100%
rename from enums.py
rename to ping3/enums.py
diff --git a/errors.py b/ping3/errors.py
similarity index 100%
rename from errors.py
rename to ping3/errors.py
diff --git a/setup.py b/setup.py
index f50f621..03c6aae 100644
--- a/setup.py
+++ b/setup.py
@@ -21,8 +21,7 @@ setuptools.setup(
         'Programming Language :: Python :: 3',
     ],
     keywords='python3 ping icmp socket tool',
-    packages=setuptools.find_packages(exclude=['contrib', 'docs', 'tests']),
-    py_modules=["ping3", "command_line_ping3", "errors", "enums"],
+    packages=["ping3"],
     python_requires='>=3',
     install_requires=[],
     extras_require={
@@ -31,6 +30,6 @@ setuptools.setup(
     package_data={},
     data_files=[],
     entry_points={
-        'console_scripts': ['ping3=command_line_ping3:main'],
+        'console_scripts': ['ping3=ping3.command_line:main'],
     },
 )


Test patch:
diff --git a/tests/test_command_line_ping3.py b/tests/test_command_line.py
similarity index 76%
rename from tests/test_command_line_ping3.py
rename to tests/test_command_line.py
index 267d0d6..48bd53c 100644
--- a/tests/test_command_line_ping3.py
+++ b/tests/test_command_line.py
@@ -7,8 +7,8 @@ import socket
 from unittest.mock import patch
 
 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-import command_line_ping3  # noqa: linter (pycodestyle) should not lint this line.
-import errors  # noqa: linter (pycodestyle) should not lint this line.
+from ping3 import command_line  # noqa: linter (pycodestyle) should not lint this line.
+from ping3 import errors  # noqa: linter (pycodestyle) should not lint this line.
 
 
 class test_ping3(unittest.TestCase):
@@ -22,46 +22,46 @@ class test_ping3(unittest.TestCase):
 
     def test_dest_addr_0(self):
         with patch("sys.stdout", new=io.StringIO()) as fake_out:
-            command_line_ping3.main()
+            command_line.main()
             self.assertRegex(fake_out.getvalue(), r".*[0-9]+ms.*")
 
     def test_dest_addr_1(self):
         with patch("sys.stdout", new=io.StringIO()) as fake_out:
-            command_line_ping3.main(["127.0.0.1"])
+            command_line.main(["127.0.0.1"])
             self.assertTrue("127.0.0.1" in fake_out.getvalue())
 
     def test_dest_addr_2(self):
         with patch("sys.stdout", new=io.StringIO()) as fake_out:
-            command_line_ping3.main(["127.0.0.1", "8.8.8.8"])
+            command_line.main(["127.0.0.1", "8.8.8.8"])
             self.assertTrue("127.0.0.1" in fake_out.getvalue())
             self.assertTrue("8.8.8.8" in fake_out.getvalue())
 
     def test_count(self):
         with patch("sys.stdout", new=io.StringIO()) as fake_out:
-            command_line_ping3.main(['-c', '1', 'example.com'])
+            command_line.main(['-c', '1', 'example.com'])
             self.assertEqual(fake_out.getvalue().count("\n"), 1)
 
     def test_timeout(self):
         with patch("sys.stdout", new=io.StringIO()) as fake_out:
-            command_line_ping3.main(['-w', '0.0001', 'example.com'])
+            command_line.main(['-w', '0.0001', 'example.com'])
             self.assertRegex(fake_out.getvalue(), r".*Timeout \> [0-9\.]+s.*")
 
     def test_ttl(self):
         with patch("sys.stdout", new=io.StringIO()) as fake_out:
-            command_line_ping3.main(['-t', '1', 'example.com'])
+            command_line.main(['-t', '1', 'example.com'])
             self.assertRegex(fake_out.getvalue(), r".*Timeout.*")
 
     def test_size(self):
         with patch("sys.stdout", new=io.StringIO()) as fake_out:
-            command_line_ping3.main(['-l', '100', 'example.com'])
+            command_line.main(['-l', '100', 'example.com'])
             self.assertRegex(fake_out.getvalue(), r".*[0-9]+ms.*")
             with self.assertRaises(OSError):
-                command_line_ping3.main(['-l', '99999', 'example.com'])
+                command_line.main(['-l', '99999', 'example.com'])
 
     def test_interval(self):
         with patch("sys.stdout", new=io.StringIO()) as fake_out:
             start_time = time.time()
-            command_line_ping3.main(['-i', '1.7', 'example.com'])
+            command_line.main(['-i', '1.7', 'example.com'])
             end_time = time.time()
             self.assertTrue((end_time - start_time) >= 5.1)  # time_expect = (count - 1) * interval
             self.assertFalse('Timeout' in fake_out.getvalue())
@@ -79,18 +79,18 @@ class test_ping3(unittest.TestCase):
                 socket.if_nametoindex(my_interface)  # test if the interface exists.
             except OSError:
                 self.fail('Interface Name Error: {}'.format(my_interface))
-            command_line_ping3.main(['-I', my_interface, 'example.com'])
+            command_line.main(['-I', my_interface, 'example.com'])
             self.assertRegex(fake_out.getvalue(), r".*[0-9]+ms.*")
 
     def test_debug(self):
         with patch("sys.stdout", new=io.StringIO()), patch("sys.stderr", new=io.StringIO()) as fake_err:
-            command_line_ping3.main(['--debug', '-c', '1', 'example.com'])
+            command_line.main(['--debug', '-c', '1', 'example.com'])
             self.assertIn("[DEBUG]", fake_err.getvalue())
 
     def test_exceptions(self):
         with patch("sys.stdout", new=io.StringIO()) as fake_out:
             with self.assertRaises(errors.Timeout):
-                command_line_ping3.main(['--exceptions', '-w', '0.0001', 'example.com'])
+                command_line.main(['--exceptions', '-w', '0.0001', 'example.com'])
 
 
 if __name__ == "__main__":
diff --git a/tests/test_ping3.py b/tests/test_ping3.py
index a1cfed4..b9f648c 100644
--- a/tests/test_ping3.py
+++ b/tests/test_ping3.py
@@ -8,7 +8,7 @@ import socket
 
 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 import ping3  # noqa: linter (pycodestyle) should not lint this line.
-import errors  # noqa: linter (pycodestyle) should not lint this line.
+from ping3 import errors  # noqa: linter (pycodestyle) should not lint this line.
 
 
 class test_ping3(unittest.TestCase):