From b4c8c16ed9c3cda1b4dbfb2cb4410a60124476a6 Mon Sep 17 00:00:00 2001 From: pikez Date: Tue, 18 Jun 2019 22:23:00 +0800 Subject: [PATCH] remove setup function and description --- README.md | 17 +---------------- pysnooper/pycompat.py | 5 ----- pysnooper/tracer.py | 16 ++++------------ tests/test_pysnooper.py | 36 ------------------------------------ 4 files changed, 5 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 5e17161..fae65a3 100644 --- a/README.md +++ b/README.md @@ -207,22 +207,7 @@ Exclude specific keys/attributes/indices with the `exclude` parameter, e.g. `Att Add a slice after `Indices` to only see the values within that slice, e.g. `Indices('z')[-3:]`. -`PYSNOOPER_DISABLED` as an environment variable, can be used to activate or deactivate pysnooner. Pysnooper is deactived by setting the parameter to a non-empty value , and actived by default. - -You can use `snoop.setup()` method to configure and get a new snoop object, then use it globally or in scope. Any parameters passing to `setup()` method should be supported by snoop. -```python -import pysnooper.snoop - -# use my_snoop to debug. my_snoop will always be enabled, stderr will redirect output to a file -my_snoop = snoop.setup(output='/my/log/file.log', disable=False) - -@my_snoop() -def foo(): - x = 5 - y = 10 - return x + y -``` -Notice that `PYSNOOPER_DISABLED` will be invalid if `disable` parameter is specified in `setup()` +`PYSNOOPER_DISABLED` as an environment variable, can be used to activate or deactivate pysnooner. Pysnooper is deactivated by setting the parameter to a non-empty value, and active by default. # Contribute # diff --git a/pysnooper/pycompat.py b/pysnooper/pycompat.py index c12441b..de0a472 100644 --- a/pysnooper/pycompat.py +++ b/pysnooper/pycompat.py @@ -47,11 +47,6 @@ try: except AttributeError: iscoroutinefunction = lambda whatever: False # Lolz -try: - getfullargspec = inspect.getfullargspec -except AttributeError: - getfullargspec = inspect.getargspec - if PY3: string_types = (str,) diff --git a/pysnooper/tracer.py b/pysnooper/tracer.py index 0f86fa2..f9b6544 100644 --- a/pysnooper/tracer.py +++ b/pysnooper/tracer.py @@ -140,7 +140,7 @@ class FileWriter(object): thread_global = threading.local() - +DISABLED = os.getenv("PYSNOOPER_DISABLED", "") class Tracer: ''' @@ -195,7 +195,6 @@ class Tracer: overwrite=False, thread_info=False, custom_repr=(), - disable=None, ): self._write = get_write_function(output, overwrite) @@ -216,10 +215,9 @@ class Tracer: self.target_frames = set() self.thread_local = threading.local() self.custom_repr = custom_repr - self.disable = os.getenv("PYSNOOPER_DISABLED", "") if disable is None else disable def __call__(self, function): - if self.disable: + if DISABLED: return function self.target_codes.add(function.__code__) @@ -256,7 +254,7 @@ class Tracer: self._write(s) def __enter__(self): - if self.disable: + if DISABLED: return calling_frame = inspect.currentframe().f_back if not self._is_internal_frame(calling_frame): @@ -268,7 +266,7 @@ class Tracer: sys.settrace(self.trace) def __exit__(self, exc_type, exc_value, exc_traceback): - if self.disable: + if DISABLED: return stack = self.thread_local.original_trace_functions sys.settrace(stack.pop()) @@ -408,9 +406,3 @@ class Tracer: format(**locals())) return self.trace - - @classmethod - def setup(cls, **kwargs): - if not (set(pycompat.getfullargspec(cls.__init__).args) > set(kwargs.keys())): - raise Exception('The parameters passed to setup contain non-snoop parameters') - return functools.partial(cls, **kwargs) diff --git a/tests/test_pysnooper.py b/tests/test_pysnooper.py index 88cf625..e451caf 100644 --- a/tests/test_pysnooper.py +++ b/tests/test_pysnooper.py @@ -1191,39 +1191,3 @@ def test_activate_deactivate_snoop(): os.environ['PYSNOOPER_DISABLED'] = '' test_string_io() - - -def test_setup_snoop_global(): - my_snoop = pysnooper.snoop.setup(disable=False) - os.environ['PYSNOOPER_DISABLED'] = '1' - - @my_snoop() - def my_function(foo): - x = 7 - y = 8 - return y + x - - with mini_toolbox.OutputCapturer(stdout=False, - stderr=True) as output_capturer: - result = my_function('baba') - output = output_capturer.string_io.getvalue() - assert_output( - output, - ( - VariableEntry('foo', value_regex="u?'baba'"), - CallEntry('def my_function(foo):'), - LineEntry('x = 7'), - VariableEntry('x', '7'), - LineEntry('y = 8'), - VariableEntry('y', '8'), - LineEntry('return y + x'), - ReturnEntry('return y + x'), - ReturnValueEntry('15'), - ) - ) - - -def test_mismatch_parameters_in_setup(): - with pytest.raises(Exception, match='contain non-snoop parameters') as excinfo: - my_snoop = pysnooper.snoop.setup(disabled=False) -