Spaces:
Running on Zero
Running on Zero
Download mapanything/utils/warnings.py from prithivMLmods/Map-Anything-v1: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/prithivMLmods/Map-Anything-v1/resolve/3e919c0e2a36944af65df7b12a54b39602a23b30/mapanything/utils/warnings.py
- Command line
-
hf download hf://spaces/prithivMLmods/Map-Anything-v1@3e919c0e2a36944af65df7b12a54b39602a23b30/mapanything/utils/warnings.py
-
curl -L -o warnings.py https://huggingface.co/spaces/prithivMLmods/Map-Anything-v1/resolve/3e919c0e2a36944af65df7b12a54b39602a23b30/mapanything/utils/warnings.py
1.31 kB
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| # | |
| # This source code is licensed under the Apache License, Version 2.0 | |
| # found in the LICENSE file in the root directory of this source tree. | |
| """ | |
| Wrapper utilities for warnings. | |
| """ | |
| import warnings | |
| from functools import wraps | |
| def suppress_traceback(fn): | |
| def wrapper(*args, **kwargs): | |
| try: | |
| return fn(*args, **kwargs) | |
| except Exception as e: | |
| e.__traceback__ = e.__traceback__.tb_next.tb_next | |
| raise | |
| return wrapper | |
| class no_warnings: | |
| def __init__(self, action: str = "ignore", **kwargs): | |
| self.action = action | |
| self.filter_kwargs = kwargs | |
| def __call__(self, fn): | |
| def wrapper(*args, **kwargs): | |
| with warnings.catch_warnings(): | |
| warnings.simplefilter(self.action, **self.filter_kwargs) | |
| return fn(*args, **kwargs) | |
| return wrapper | |
| def __enter__(self): | |
| self.warnings_manager = warnings.catch_warnings() | |
| self.warnings_manager.__enter__() | |
| warnings.simplefilter(self.action, **self.filter_kwargs) | |
| def __exit__(self, exc_type, exc_val, exc_tb): | |
| self.warnings_manager.__exit__(exc_type, exc_val, exc_tb) | |