Skip to content

Commit

Permalink
restore warnings filter after compile_files
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Feb 19, 2025
1 parent e256c72 commit 4d64b86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 13 additions & 3 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import argparse
import functools
import json
import os
import sys
Expand All @@ -15,7 +16,7 @@
from vyper.compiler.settings import VYPER_TRACEBACK_LIMIT, OptimizationLevel, Settings
from vyper.typing import ContractPath, OutputFormats
from vyper.utils import uniq
from vyper.warnings import set_warnings_filter
from vyper.warnings import warnings_filter

format_options_help = """Format to print, one or more of (comma-separated):
bytecode (default) - Deployable bytecode
Expand Down Expand Up @@ -293,6 +294,17 @@ def get_search_paths(paths: list[str] = None, include_sys_path=True) -> list[Pat
return search_paths


def _apply_warnings_filter(func):
@functools.wraps(func)
def inner(*args, **kwargs):
warnings_control = args[-1]
with warnings_filter(warnings_control):
return func(*args, **kwargs)

return inner


@_apply_warnings_filter
def compile_files(
input_files: list[str],
output_formats: OutputFormats,
Expand All @@ -304,8 +316,6 @@ def compile_files(
no_bytecode_metadata: bool = False,
warnings_control: Optional[str] = None,
) -> dict:
set_warnings_filter(warnings_control)

search_paths = get_search_paths(paths, include_sys_path)
input_bundle = FilesystemInputBundle(search_paths)

Expand Down
8 changes: 8 additions & 0 deletions vyper/warnings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import warnings
from typing import Optional

Expand All @@ -15,6 +16,13 @@ def vyper_warn(warning: VyperWarning | str, node=None):
warnings.warn(warning, stacklevel=2)


@contextlib.contextmanager
def warnings_filter(warnings_control: Optional[str]):
with warnings.catch_warnings():
set_warnings_filter(warnings_control)
yield


def set_warnings_filter(warnings_control: Optional[str]):
if warnings_control == "error":
warnings_filter = "error"
Expand Down

0 comments on commit 4d64b86

Please sign in to comment.