changeset 164:a813094ae4f5

Move PY2 from cutils.util.constants into cutils.util
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 09 Jan 2025 13:48:57 +0100
parents fa7dd54e9715
children b32b41297893
files cutils/shasum.py cutils/util/__init__.py cutils/util/constants.py cutils/util/digest.py cutils/util/walk.py
diffstat 5 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/cutils/shasum.py	Thu Jan 09 13:40:33 2025 +0100
+++ b/cutils/shasum.py	Thu Jan 09 13:48:57 2025 +0100
@@ -24,7 +24,6 @@
 
 from . import (__version__, __revision__)
 from . import util
-from .util import constants
 from .util import digest
 
 
@@ -174,7 +173,7 @@
                         opts.base64)
     else:
         if not opts.files or (len(opts.files) == 1 and opts.files[0] == '-'):
-            if constants.PY2:
+            if util.PY2:
                 if sys.platform == "win32":
                     import msvcrt   # noqa: E401
                     msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
@@ -243,7 +242,7 @@
     dest = opts.dest or sys.stdout
     exit_code = 0
     if not opts.files or (len(opts.files) == 1 and opts.files[0] == '-'):
-        if constants.PY2:
+        if util.PY2:
             if sys.platform == "win32":
                 import os, msvcrt   # noqa: E401
                 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
--- a/cutils/util/__init__.py	Thu Jan 09 13:40:33 2025 +0100
+++ b/cutils/util/__init__.py	Thu Jan 09 13:48:57 2025 +0100
@@ -7,7 +7,8 @@
 
 """
 
-__all__ = ["normalize_filename",
+__all__ = ["PY2",
+           "normalize_filename",
            "argv2algo",
            "algotag2algotype",
            "get_blake2b",
@@ -20,6 +21,10 @@
 import argparse
 import hashlib
 import os
+import sys
+
+
+PY2 = sys.version_info[0] < 3
 
 
 def get_blake2b():
--- a/cutils/util/constants.py	Thu Jan 09 13:40:33 2025 +0100
+++ b/cutils/util/constants.py	Thu Jan 09 13:48:57 2025 +0100
@@ -7,22 +7,20 @@
 
 """
 
-__all__ = ["PY2",
-           "PATH_TYPES",
+__all__ = ["PATH_TYPES",
            "READ_CHUNK_SIZE",
            "MAX_AUTO_MAP_SIZE",
            "MAP_WINDOW_SIZE"
            ]
 
 
-import sys
 try:
     import pathlib
 except ImportError:
     pathlib = None
 
+from . import PY2
 
-PY2 = sys.version_info[0] < 3
 
 if PY2:
     PATH_TYPES = (unicode, str)    # noqa: F821 (undefined name 'unicode')
--- a/cutils/util/digest.py	Thu Jan 09 13:40:33 2025 +0100
+++ b/cutils/util/digest.py	Thu Jan 09 13:48:57 2025 +0100
@@ -19,6 +19,7 @@
     mmap = None
 import stat
 
+from . import PY2
 from . import constants
 
 
@@ -79,7 +80,7 @@
             fadvise = getattr(os, "posix_fadvise", None)
             if fadvise:
                 fadvise(fd, 0, 0, os.POSIX_FADV_SEQUENTIAL)
-            if not constants.PY2:
+            if not PY2:
                 fileobj = io.FileIO(fd, mode="r", closefd=False)
                 buf = bytearray(constants.READ_CHUNK_SIZE)
                 with memoryview(buf) as full_view:
--- a/cutils/util/walk.py	Thu Jan 09 13:40:33 2025 +0100
+++ b/cutils/util/walk.py	Thu Jan 09 13:48:57 2025 +0100
@@ -19,8 +19,8 @@
     except ImportError:
         scandir = None
 
+from . import PY2
 from .cm import nullcontext
-from .constants import PY2
 
 
 class WalkDirEntry(object):