From 5b4ac2562925f4a1c4314f635c8eee131f3ca044 Mon Sep 17 00:00:00 2001 From: Ali Kuwajerwala Date: Sat, 7 Dec 2024 16:14:24 -0800 Subject: [PATCH 1/7] cleanup prints use logging instead of prints --- examples/test_extract.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/examples/test_extract.py b/examples/test_extract.py index 8bf0a23..792a9ce 100644 --- a/examples/test_extract.py +++ b/examples/test_extract.py @@ -1,9 +1,4 @@ -import krec -import argparse -from pathlib import Path - - -""" +"""Usage: # Just extract and view python examples/test_extract.py input.mkv -v @@ -11,22 +6,28 @@ python examples/test_extract.py input.mkv -o output.krec -v """ +import argparse +import logging +from pathlib import Path + +import krec + def main(args): - print(f"Extracting from: {args.input_file}") + logging.info(f"Extracting from: {args.input_file}") try: extracted_krec = krec.extract_from_video(args.input_file, verbose=args.verbose) - print("Extraction successful") - print(f"Extracted KRec has {len(extracted_krec)} frames") + logging.info("Extraction successful") + logging.info(f"Extracted KRec has {len(extracted_krec)} frames") if args.output_file: output_path = Path(args.output_file) extracted_krec.save(str(output_path)) - print(f"Saved to: {output_path}") + logging.info(f"Saved to: {output_path}") except Exception as e: - print(f"Error: {e}") + logging.error(f"Error: {e}") return 1 return 0 @@ -38,5 +39,7 @@ def main(args): parser.add_argument("-o", "--output-file", type=str, help="Output KRec file path (optional)") parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output") + logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + args = parser.parse_args() - exit(main(args)) + main(args) From aa464918d0c1b22ac4ee1e6ddd98d56f7400f58e Mon Sep 17 00:00:00 2001 From: Ali Kuwajerwala Date: Sat, 7 Dec 2024 16:16:36 -0800 Subject: [PATCH 2/7] remove return, not needed --- examples/test_extract.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/test_extract.py b/examples/test_extract.py index 792a9ce..65b8f09 100644 --- a/examples/test_extract.py +++ b/examples/test_extract.py @@ -28,9 +28,6 @@ def main(args): except Exception as e: logging.error(f"Error: {e}") - return 1 - - return 0 if __name__ == "__main__": From efe58a075d27a18423dc169f4602764c86c383f0 Mon Sep 17 00:00:00 2001 From: Ali K Date: Sun, 8 Dec 2024 19:33:14 -0800 Subject: [PATCH 3/7] add explainer at the top --- examples/test_extract.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/test_extract.py b/examples/test_extract.py index 65b8f09..4c8d9e6 100644 --- a/examples/test_extract.py +++ b/examples/test_extract.py @@ -1,4 +1,7 @@ -"""Usage: +""" +Extract KRec data from an MKV file and optionally save it to a new file. + +Usage: # Just extract and view python examples/test_extract.py input.mkv -v From d895fc1ffe8cdcb95f663481b8882b729e1d3228 Mon Sep 17 00:00:00 2001 From: Ali K Date: Sun, 8 Dec 2024 19:33:34 -0800 Subject: [PATCH 4/7] colorlogging and fix fstrings --- examples/test_extract.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/test_extract.py b/examples/test_extract.py index 4c8d9e6..7215e28 100644 --- a/examples/test_extract.py +++ b/examples/test_extract.py @@ -10,6 +10,7 @@ """ import argparse +import colorlogging import logging from pathlib import Path @@ -17,20 +18,20 @@ def main(args): - logging.info(f"Extracting from: {args.input_file}") + logging.info("Extracting from: %s", args.input_file) try: extracted_krec = krec.extract_from_video(args.input_file, verbose=args.verbose) logging.info("Extraction successful") - logging.info(f"Extracted KRec has {len(extracted_krec)} frames") + logging.info("Extracted KRec has %d frames", len(extracted_krec)) if args.output_file: output_path = Path(args.output_file) extracted_krec.save(str(output_path)) - logging.info(f"Saved to: {output_path}") + logging.info("Saved to: %s", output_path) except Exception as e: - logging.error(f"Error: {e}") + logging.error("Error: %s", e) if __name__ == "__main__": @@ -39,7 +40,7 @@ def main(args): parser.add_argument("-o", "--output-file", type=str, help="Output KRec file path (optional)") parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output") - logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + colorlogging.configure() args = parser.parse_args() main(args) From 9106312cd1b7cfba459eb03a2c0e7d6fed46496c Mon Sep 17 00:00:00 2001 From: Ali K Date: Sun, 8 Dec 2024 19:35:36 -0800 Subject: [PATCH 5/7] isort imports --- examples/test_extract.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/test_extract.py b/examples/test_extract.py index 7215e28..b206e6b 100644 --- a/examples/test_extract.py +++ b/examples/test_extract.py @@ -10,10 +10,11 @@ """ import argparse -import colorlogging import logging from pathlib import Path +import colorlogging + import krec From d3b39eb3ca5df8a3014c4bd8acd1bbe34846fbdf Mon Sep 17 00:00:00 2001 From: Ali K Date: Sun, 8 Dec 2024 19:39:45 -0800 Subject: [PATCH 6/7] add colorlogging as dependency --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 1f81654..062f18b 100644 --- a/setup.py +++ b/setup.py @@ -60,6 +60,7 @@ def run(self) -> None: ), ], setup_requires=["setuptools-rust"], + install_requires=["colorlogging"], zip_safe=False, long_description=long_description, long_description_content_type="text/markdown", From 425c6a8348069ce6328c0bd8bdb6bdc526c71dc8 Mon Sep 17 00:00:00 2001 From: Ali K Date: Mon, 9 Dec 2024 10:35:53 -0800 Subject: [PATCH 7/7] move colorlogging to requirements.txt --- requirements.txt | 1 + setup.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..27e2c9f --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +colorlogging \ No newline at end of file diff --git a/setup.py b/setup.py index 062f18b..1c452c1 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,9 @@ version: str = version_re.group(1) +with open("requirements.txt") as f: + requirements: list[str] = f.read().splitlines() + class RustBuildExt(build_ext): def run(self) -> None: # Generate the stub file @@ -60,7 +63,7 @@ def run(self) -> None: ), ], setup_requires=["setuptools-rust"], - install_requires=["colorlogging"], + install_requires=requirements, zip_safe=False, long_description=long_description, long_description_content_type="text/markdown",