From fa928e803bc41f1e49051bb0cb738acbd8c6f2ec Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Thu, 13 Feb 2020 19:05:29 +0000 Subject: Remove unused MesonException.get_msg_with_context() After that, the only remaining user of get_error_location_string() is mlog, so move that there. --- mesonbuild/mlog.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'mesonbuild/mlog.py') diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index b28eca1..9387cb3 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -221,9 +221,18 @@ def log_once(*args: T.Union[str, AnsiDecorator], is_error: bool = False, _logged_once.add(t) log(*args, is_error=is_error, **kwargs) +# This isn't strictly correct. What we really want here is something like: +# class StringProtocol(typing_extensions.Protocol): +# +# def __str__(self) -> str: ... +# +# This would more accurately embody what this funcitonc an handle, but we +# don't have that yet, so instead we'll do some casting to work around it +def get_error_location_string(fname: str, lineno: str) -> str: + return '{}:{}:'.format(fname, lineno) + def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], once: bool = False, **kwargs: T.Any) -> None: - from .mesonlib import get_error_location_string from .environment import build_filename from .mesonlib import MesonException -- cgit v1.1 From 4895830c28dda6f009aeaec0663b5bba88b3d1b3 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Fri, 14 Feb 2020 02:47:13 +0000 Subject: Fix typos in comments about type annotations --- mesonbuild/mlog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mesonbuild/mlog.py') diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 9387cb3..c5ebbbf 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -226,7 +226,7 @@ def log_once(*args: T.Union[str, AnsiDecorator], is_error: bool = False, # # def __str__(self) -> str: ... # -# This would more accurately embody what this funcitonc an handle, but we +# This would more accurately embody what this function can handle, but we # don't have that yet, so instead we'll do some casting to work around it def get_error_location_string(fname: str, lineno: str) -> str: return '{}:{}:'.format(fname, lineno) @@ -236,7 +236,7 @@ def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], from .environment import build_filename from .mesonlib import MesonException - # The tping requirements here are non-obvious. Lists are invariant, + # The typing requirements here are non-obvious. Lists are invariant, # therefore T.List[A] and T.List[T.Union[A, B]] are not able to be joined if severity == 'warning': label = [yellow('WARNING:')] # type: T.List[T.Union[str, AnsiDecorator]] -- cgit v1.1 From 346b5c4be71bb1f502507d92ffdb1ded4c3bd85d Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Fri, 14 Feb 2020 02:58:37 +0000 Subject: Store filename in node location Warnings have a location node object (with subdir and lineno attributes), which is passed as a location: kwarg to mlog.warning() and formatted in _log_error(). Re-purpose the subdir attribute (path relative to the source root dir, with an implied filename of 'meson.build'), which is stored into the node by parser(), to contain a pathname. (Properly I should rename 'subdir' -> 'file' everywhere, but that's a lot of churn just to see if this works) Notes: The warning location node may also have a colno attribute, which is currently ignored by _log_error(). We can't currently issue warnings with locations in meson_options.txt because the filename isn't part of the location (as it's assumed to be 'meson.build). --- mesonbuild/mlog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mesonbuild/mlog.py') diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index c5ebbbf..b563e41 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -251,7 +251,7 @@ def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], location = kwargs.pop('location', None) if location is not None: - location_file = os.path.join(location.subdir, build_filename) + location_file = location.subdir location_str = get_error_location_string(location_file, location.lineno) # Unions are frankly awful, and we have to T.cast here to get mypy # to understand that the list concatenation is safe -- cgit v1.1 From c3163040aec7eb1486989369041b8a7d549cd9db Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Fri, 14 Feb 2020 13:29:31 +0000 Subject: Display filename cwd relative in warning location Format the filename relative to cwd in a warning location. --- mesonbuild/mlog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mesonbuild/mlog.py') diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index b563e41..3f33240 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -234,7 +234,7 @@ def get_error_location_string(fname: str, lineno: str) -> str: def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], once: bool = False, **kwargs: T.Any) -> None: from .environment import build_filename - from .mesonlib import MesonException + from .mesonlib import MesonException, relpath # The typing requirements here are non-obvious. Lists are invariant, # therefore T.List[A] and T.List[T.Union[A, B]] are not able to be joined @@ -251,7 +251,7 @@ def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], location = kwargs.pop('location', None) if location is not None: - location_file = location.subdir + location_file = relpath(location.subdir, os.getcwd()) location_str = get_error_location_string(location_file, location.lineno) # Unions are frankly awful, and we have to T.cast here to get mypy # to understand that the list concatenation is safe -- cgit v1.1 From c8f8d58273a40d94c820dccab54a7ae2d948cb8a Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Thu, 20 Feb 2020 18:50:24 +0000 Subject: Rename 'subdir' -> 'filename' in location objects --- mesonbuild/mlog.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mesonbuild/mlog.py') diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 3f33240..440ce8b 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -233,7 +233,6 @@ def get_error_location_string(fname: str, lineno: str) -> str: def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], once: bool = False, **kwargs: T.Any) -> None: - from .environment import build_filename from .mesonlib import MesonException, relpath # The typing requirements here are non-obvious. Lists are invariant, @@ -251,7 +250,7 @@ def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator], location = kwargs.pop('location', None) if location is not None: - location_file = relpath(location.subdir, os.getcwd()) + location_file = relpath(location.filename, os.getcwd()) location_str = get_error_location_string(location_file, location.lineno) # Unions are frankly awful, and we have to T.cast here to get mypy # to understand that the list concatenation is safe -- cgit v1.1