From ff6a0ccddd22ff34c8d07c8c32d599f8e1948c51 Mon Sep 17 00:00:00 2001 From: itay-goldraich <116950155+itay-goldraich@users.noreply.github.com> Date: Tue, 23 Jul 2024 18:43:38 +0300 Subject: [PATCH] feat: -m pysnooper flag Signed-off-by: itay-goldraich <116950155+itay-goldraich@users.noreply.github.com> --- pysnooper/__main__.py | 19 +++++++++++++ pysnooper/wrapper.py | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 pysnooper/__main__.py create mode 100644 pysnooper/wrapper.py diff --git a/pysnooper/__main__.py b/pysnooper/__main__.py new file mode 100644 index 0000000..72a41bb --- /dev/null +++ b/pysnooper/__main__.py @@ -0,0 +1,19 @@ +# Copyright 2019 Ram Rachum and collaborators. +# This program is distributed under the MIT license. + +from wrapper import snoop_wrapper +import sys + +def main(): + #TODO: Add flags for different options + if sys.argv[1] == "-m": #python3 -m pysnooper + snoop_wrapper() + if sys.argv[1] =='h': + print("Usage: python3 -m pysnooper ") + sys.exit(1) + +if __name__ == '__main__': + #TODO: Add flags for different options + #TODO: Assertions + + main() diff --git a/pysnooper/wrapper.py b/pysnooper/wrapper.py new file mode 100644 index 0000000..e09b64c --- /dev/null +++ b/pysnooper/wrapper.py @@ -0,0 +1,62 @@ +# Copyright 2019 Ram Rachum and collaborators. +# This program is distributed under the MIT license. + +import sys +import os +import subprocess + +#TODO: Pass the arguments to the file_snoop + +# Define the snoop code to be prepended to the original code +snoop_code = """import pysnooper +pysnooper.snoop().__enter__() +""" + +def assertions(): + assert len(sys.argv) >1, "Usage: python