diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2021-12-26 16:01:23 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2021-12-26 16:27:05 -0500 |
commit | 2540fef72bc680a0ed92a94d73bf01cdd30044fa (patch) | |
tree | 42204f08b1d290e79972419f3235018a92586b74 | |
parent | 13cc63b105794ad7d014212036a0c1474546c9a4 (diff) | |
download | wheel-git-python-logging.tar.gz |
Replace bespoke logger with Python logging logger, restoring info/debug/warning levels to logged messages. Fixed missing f-string for 'wheelfile_path'.python-logging
-rw-r--r-- | src/wheel/bdist_wheel.py | 13 | ||||
-rw-r--r-- | src/wheel/util.py | 15 | ||||
-rw-r--r-- | src/wheel/wheelfile.py | 4 |
3 files changed, 11 insertions, 21 deletions
diff --git a/src/wheel/bdist_wheel.py b/src/wheel/bdist_wheel.py index da81611..eabadf8 100644 --- a/src/wheel/bdist_wheel.py +++ b/src/wheel/bdist_wheel.py @@ -236,9 +236,8 @@ class bdist_wheel(Command): wheel = self.distribution.get_option_dict("wheel") if "universal" in wheel: # please don't define this in your global configs - log( + log.warning( "The [wheel] section is deprecated. Use [bdist_wheel] instead.", - error=True, ) val = wheel["universal"][1].strip() if val.lower() in ("1", "true", "yes"): @@ -354,7 +353,7 @@ class bdist_wheel(Command): basedir_observed, ) - log(f"installing to {self.bdist_dir}") + log.info(f"installing to {self.bdist_dir}") self.run_command("install") @@ -395,7 +394,7 @@ class bdist_wheel(Command): ) if not self.keep_temp: - log(f"removing {self.bdist_dir}") + log.info(f"removing {self.bdist_dir}") if not self.dry_run: rmtree(self.bdist_dir, onerror=remove_readonly) @@ -419,7 +418,7 @@ class bdist_wheel(Command): msg["Tag"] = "-".join((impl, abi, plat)) wheelfile_path = os.path.join(wheelfile_base, "WHEEL") - log("creating {wheelfile_path}") + log.info(f"creating {wheelfile_path}") buffer = BytesIO() BytesGenerator(buffer, maxheaderlen=0).flatten(msg) with open(wheelfile_path, "wb") as f: @@ -454,11 +453,11 @@ class bdist_wheel(Command): for pattern in patterns: for path in iglob(pattern): if path.endswith("~"): - log(f'ignoring license file "{path}" as it looks like a backup') + log.debug(f'ignoring license file "{path}" as it looks like a backup') continue if path not in files and os.path.isfile(path): - log(f'adding license file "{path}" (matched pattern "{pattern}")') + log.info(f'adding license file "{path}" (matched pattern "{pattern}")') files.add(path) return files diff --git a/src/wheel/util.py b/src/wheel/util.py index f4d8149..af470b5 100644 --- a/src/wheel/util.py +++ b/src/wheel/util.py @@ -1,7 +1,9 @@ from __future__ import annotations import base64 -import sys +import logging + +log = logging.getLogger('wheel') def urlsafe_b64encode(data: bytes) -> bytes: @@ -13,14 +15,3 @@ def urlsafe_b64decode(data: bytes) -> bytes: """urlsafe_b64decode without padding""" pad = b"=" * (4 - (len(data) & 3)) return base64.urlsafe_b64decode(data + pad) - - -def log(msg: str, *, error: bool = False) -> None: - stream = sys.stderr if error else sys.stdout - try: - print(msg, file=stream, flush=True) - except UnicodeEncodeError: - # emulate backslashreplace error handler - encoding = stream.encoding - msg = msg.encode(encoding, "backslashreplace").decode(encoding) - print(msg, file=stream, flush=True) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index fdf4ac4..41e8382 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -115,7 +115,7 @@ class WheelFile(ZipFile): return ef def write_files(self, base_dir): - log(f"creating '{self.filename}' and adding '{base_dir}' to it") + log.info(f"creating '{self.filename}' and adding '{base_dir}' to it") deferred = [] for root, dirnames, filenames in os.walk(base_dir): # Sort the directory names so that `os.walk` will walk them in a @@ -158,7 +158,7 @@ class WheelFile(ZipFile): if isinstance(zinfo_or_arcname, ZipInfo) else zinfo_or_arcname ) - log(f"adding '{fname}'") + log.info(f"adding '{fname}'") if fname != self.record_path: hash_ = self._default_algorithm(data) self._file_hashes[fname] = ( |