Browse Source

made all constants and functions private (only console entry point should be called directly)

Fabian Peter Hammerle 2 years ago
parent
commit
a8a5ed4ed3
4 changed files with 17 additions and 11 deletions
  1. 4 0
      CHANGELOG.md
  2. 6 6
      free_disk/__init__.py
  3. 1 1
      setup.py
  4. 6 4
      tests/data_size_to_bytes_test.py

+ 4 - 0
CHANGELOG.md

@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 
 ## [Unreleased]
 ## [Unreleased]
+### Changed
+- made all constants and functions private
+  (only console entry point should be called directly)
+
 ### Removed
 ### Removed
 - support for `python3.4`
 - support for `python3.4`
 
 

+ 6 - 6
free_disk/__init__.py

@@ -11,7 +11,7 @@ import shutil
 import re
 import re
 
 
 # https://en.wikipedia.org/wiki/Template:Quantities_of_bytes
 # https://en.wikipedia.org/wiki/Template:Quantities_of_bytes
-DATA_SIZE_UNIT_BYTE_CONVERSION_FACTOR = {
+_DATA_SIZE_UNIT_BYTE_CONVERSION_FACTOR = {
     "B": 1,
     "B": 1,
     "kB": 10 ** 3,
     "kB": 10 ** 3,
     "KB": 10 ** 3,
     "KB": 10 ** 3,
@@ -25,14 +25,14 @@ DATA_SIZE_UNIT_BYTE_CONVERSION_FACTOR = {
 }
 }
 
 
 
 
-def data_size_to_bytes(size_with_unit: str) -> int:
+def _data_size_to_bytes(size_with_unit: str) -> int:
     match = re.match(r"^([\d\.]+)\s*([A-Za-z]+)?$", size_with_unit)
     match = re.match(r"^([\d\.]+)\s*([A-Za-z]+)?$", size_with_unit)
     if not match:
     if not match:
         raise ValueError("Unable to parse data size {!r}".format(size_with_unit))
         raise ValueError("Unable to parse data size {!r}".format(size_with_unit))
     unit_symbol = match.group(2)
     unit_symbol = match.group(2)
     if unit_symbol:
     if unit_symbol:
         try:
         try:
-            byte_conversion_factor = DATA_SIZE_UNIT_BYTE_CONVERSION_FACTOR[unit_symbol]
+            byte_conversion_factor = _DATA_SIZE_UNIT_BYTE_CONVERSION_FACTOR[unit_symbol]
         except KeyError as exc:
         except KeyError as exc:
             raise ValueError(
             raise ValueError(
                 "Unknown data size unit symbol {!r}".format(unit_symbol)
                 "Unknown data size unit symbol {!r}".format(unit_symbol)
@@ -43,12 +43,12 @@ def data_size_to_bytes(size_with_unit: str) -> int:
     return int(round(byte_size, 0))
     return int(round(byte_size, 0))
 
 
 
 
-def main():
+def _main():
     argparser = argparse.ArgumentParser(description=__doc__)
     argparser = argparse.ArgumentParser(description=__doc__)
     argparser.add_argument("-d", "--debug", action="store_true")
     argparser.add_argument("-d", "--debug", action="store_true")
     argparser.add_argument(
     argparser.add_argument(
         "--free-bytes",
         "--free-bytes",
-        type=data_size_to_bytes,
+        type=_data_size_to_bytes,
         required=True,
         required=True,
         help="examples: 1024, 1024B, 4KiB, 4KB, 2TB",
         help="examples: 1024, 1024B, 4KiB, 4KB, 2TB",
     )
     )
@@ -92,4 +92,4 @@ def main():
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
-    main()
+    _main()

+ 1 - 1
setup.py

@@ -40,7 +40,7 @@ setuptools.setup(
     packages=setuptools.find_packages(),
     packages=setuptools.find_packages(),
     entry_points={
     entry_points={
         "console_scripts": [
         "console_scripts": [
-            "free-disk = free_disk:main",
+            "free-disk = free_disk:_main",
         ],
         ],
     },
     },
     # pathlib.Path.read_text()
     # pathlib.Path.read_text()

+ 6 - 4
tests/data_size_to_bytes_test.py

@@ -2,6 +2,8 @@ import pytest
 
 
 import free_disk
 import free_disk
 
 
+# pylint: disable=protected-access; tests
+
 
 
 @pytest.mark.parametrize(
 @pytest.mark.parametrize(
     ("data_size_with_unit", "expected_bytes"),
     ("data_size_with_unit", "expected_bytes"),
@@ -28,11 +30,11 @@ import free_disk
         ("1  MiB", 1024 ** 2),
         ("1  MiB", 1024 ** 2),
     ],
     ],
 )
 )
-def test_data_size_to_bytes(data_size_with_unit, expected_bytes):
-    assert expected_bytes == free_disk.data_size_to_bytes(data_size_with_unit)
+def test__data_size_to_bytes(data_size_with_unit, expected_bytes):
+    assert expected_bytes == free_disk._data_size_to_bytes(data_size_with_unit)
 
 
 
 
 @pytest.mark.parametrize("data_size_with_unit", ["abcdef", "123G"])
 @pytest.mark.parametrize("data_size_with_unit", ["abcdef", "123G"])
-def test_data_size_to_bytes_fail(data_size_with_unit):
+def test__data_size_to_bytes_fail(data_size_with_unit):
     with pytest.raises(ValueError):
     with pytest.raises(ValueError):
-        free_disk.data_size_to_bytes(data_size_with_unit)
+        free_disk._data_size_to_bytes(data_size_with_unit)