aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase
AgeCommit message (Collapse)AuthorFilesLines
2022-01-10first pass at migrating to dataclassesEli Schwartz1-3/+5
In some cases, init variables that accept None as a sentinel and immediately overwrite with [], are migrated to dataclass field factories. \o/ Note: dataclasses by default cannot provide eq methods, as they then become unhashable. In the future we may wish to opt into declaring them frozen, instead/additionally.
2021-12-06decorators: fold some duplicated code into a closureDylan Baker1-26/+17
2021-12-06add message option to since_values and deprecated_valuesDylan Baker1-6/+15
This allows these two arguments to take a tuple of (version, message), where the message will be passed to Feature*'s message parameter
2021-12-06Add deprecated_message and since_message to KwargInfoDylan Baker1-6/+17
For passing an extra message to Feature* This allows providing a more detailed message.
2021-12-06interpreterbase/decorators: Fix types of deprecated_values and since_valuesDylan Baker1-2/+3
Which shouldn't be Dict[str, str], they should be Dict[_T, str], as nay value that can be passed to types is valid here.
2021-12-05fix stray typoEli Schwartz1-1/+1
2021-12-05clean up function signatures in preparation for dataclassesEli Schwartz1-4/+4
FeatureCheck always immediately sets extra_message to '' if it isn't explicitly passed, so there is really no point in using None as a sentinel that is never used. Names used in init functions are sometimes pointlessly different from the class instance attributes they are immediately assigned to. They would make more sense if defined properly.
2021-11-22typed_kwargs: use | for type unions, not ,Dylan Baker1-4/+4
Python uses this syntax now, as does typescript and other languages
2021-11-22typed_kwargs: provide better error messages for wrong container typesDylan Baker1-1/+13
Currently, if you pass a `[]string`, but the argument expects `[]number`, then you get a message like `expected list[str] but got list`. That isn't helpful. With this patch arrays and dictionaries will both print messages with the types provided.
2021-11-22typed_kwargs: move some closures around to increase code clarityDylan Baker1-21/+24
The inner closure of the typed_kwargs function is already complicated enough without defining closures in the middle of a loop. Let's just pass the types_tuple as an argument to both avoid redefining the function over and over, and also make the whole thing easier to read.
2021-11-20FeatureDeprecated: add a notice summary of future deprecationsEli Schwartz1-5/+30
Since these aren't warnings, per se, we don't note every single call site that has one. And we raise mlog.notice in non-fatal mode to avoid either: - being too threatening - making builds fail with --fatal-meson-warnings Nevertheless, it is useful to give people a heads-up that there is an upgrade opportunity, rather than waiting until they upgrade and then causing projects to begin printing fatal warnings.
2021-11-20Feature kwargs decorator: automatically report the nodes which trigger an issueEli Schwartz1-9/+11
2021-11-20add location support to feature checksEli Schwartz1-11/+14
mlog can already print location info, and we use this often -- including for custom feature warnings already. Make this work everywhere, so that it is feasible to move such custom warnings to globally tracked Features.
2021-11-01various manual conversion of percent-formatted strings to f-stringsEli Schwartz1-5/+5
2021-11-01migrate python 3.5 compatible superclass variable annotations to 3.6Eli Schwartz1-3/+1
As we now require python 3.6, we can declare their types without initializing them.
2021-10-27Revert "mark a couple of typing-only imports as noqa, to appease pyflakes"Eli Schwartz1-3/+1
This reverts commit 6cc1b8441c0cf7428e52bdf1cd541ea830a4eb83. The latest version of pyflakes learned to detect that correctly.
2021-10-27fix various flake8 whitespace errorsEli Schwartz2-2/+3
2021-10-24interpreter: Fix missing featuer check (fixes #9425)Daniel Mensinger1-0/+6
2021-10-10Fix typos discovered by codespellChristian Clauss3-7/+7
2021-10-09typed_kwargs: Fix when ContainerTypeInfo is used in a tupleXavier Claessens1-35/+52
info.types could be a tuple like (str, ContainerTypeInfo()). That means we have to check types one by one and only print error if none of them matched. Also fix the case when default value is None for a container type, it should leave the value to None to be able to distinguish between unset and empty list.
2021-10-06interpreter: Move RangeHolder out of interpreterbase to interpreterDaniel Mensinger2-25/+0
2021-10-06interpreter: Holderify arrays and dictsDaniel Mensinger4-419/+131
This is the final refactoring for extracting the bultin object logic out of Interpreterbase. I decided to do both arrays and dicts in one go since splitting it would have been a lot more confusing.
2021-10-04fix extra whitespaceEli Schwartz2-2/+0
discovered via flake8 --select E303
2021-09-30interpreterbase/decorators: KwargIfno validator must take an relaxed typeDylan Baker1-1/+1
I've used any because it needs to be infinitely recursive, something that we simply can't model. But basically until it goes into validator we have no way of knowing what's going on, since one can write code like: ```python KwargInfo[str]('arg', object, validator=_some_very_complex_logic_to_get_specific_string) ``` As such, we can't assume that validator is receiving a type _T, it could be anything.
2021-09-25Remove helpers.check_stringlist()Daniel Mensinger5-22/+24
2021-09-25interpreter: Introduce StringHolderDaniel Mensinger4-127/+19
Another commit in my quest to rid InterpreterBase from all higher level object processing logic. Additionally, there is a a logic change here, since `str.join` now uses varargs and can now accept more than one argument (and supports list flattening).
2021-09-14mark a couple of typing-only imports as noqa, to appease pyflakesEli Schwartz1-1/+3
Since it cannot resolve `import typing as T` in order to figure out that T.* is doing annotation-worthy stuff. Since T.cast('Foo') is not actually using Foo except in an annotation context (due to being a string) it requires extra work to resolve, and the only thing that would currently work is actually using 'typing.cast'. However, we have decided to not use it except as T... Since this import is only imported during mypy it's not so bad to noqa it.
2021-09-01interpreter: Introduce BooleanHolder for the bool primitiveDaniel Mensinger3-66/+68
2021-09-01interpreter: Simplify Disabler logicDaniel Mensinger2-16/+8
2021-09-01interpreter: Remove the AND and OR operator enumsDaniel Mensinger1-2/+0
These operators don't make sens to use in ObjectHolders, since this mechanism wouldn't allow for lazy evaluation.
2021-09-01interpreter: Remove permissive from _unholderDaniel Mensinger2-8/+6
2021-08-31interpreter: Add IntegerHolderDaniel Mensinger5-63/+58
2021-08-31interpreter: Introduce operators support for InterpreterObjectsDaniel Mensinger5-5/+202
2021-08-31interpreter: Make comparisons of different types a hard errorDaniel Mensinger1-4/+8
2021-08-31pylint: turn on superflous-parensDylan Baker2-11/+11
We have a lot of these. Some of them are harmless, if unidiomatic, such as `if (condition)`, others are potentially dangerous `assert(...)`, as `assert(condtion)` works as expected, but `assert(condition, message)` will result in an assertion that never triggers, as what you're actually asserting is `bool(tuple[2])`, which will always be true.
2021-08-30decorators: Make unknown kwarg fatalXavier Claessens1-10/+6
2021-08-30Simplify get_callee_argsXavier Claessens4-87/+34
2021-08-27interpreterbase: ensure that the default vaule to KwargInfo is a valid typeDylan Baker1-0/+4
Because currently you can write something like: ```python KwargInfo('capture', bool) ``` Which proclaims "this must be bool", but the default is then not valid.
2021-08-22use even more informative error message for invoking meson in a subdirEli Schwartz1-1/+4
Follow-up on commit 5a7b8d86d0c455680096d47cb87f0de08c0954ac Sometimes, we find a parent meson.build which is also malformed, and we shouldn't suggest that maybe the user meant to use that, if it isn't a valid project() either. Do a rough and dirty check to see if the very first line is a project() declaration, and if not, don't try to be clever and suggest using it. The "invalid source tree" error suffices here, since we're not absolutely sure meson can be successfully run in that parent directory and actually advising people about the wrong location is a lot more confusing than just saying "please figure this out yourself, here is what to look for". Granted, we miss cases where project() comes after blank lines and/or comments, but doing a full AST parse here is excessively overkill and probably too painful to do, and we don't need to be *that* clever. So let's be content with merely going above and beyond the call of duty.
2021-08-22use a more informative error message for invoking meson in a subdirEli Schwartz1-2/+14
Explicitly mention that the project definition is invalid, and clarify that project is `project()` -- a function. Also try to walk the directory tree upward, and if there are parent meson.build files, just say this isn't the project root, and "maybe you meant to run meson there instead?" This won't catch calls to subdir('foo/bar') but we can't be perfect, only better than before and catch the *majority* of such cases, and hopefully it's a lot more clear if meson protests that the project is "invalid, there is no project() function", where the user should look for a potential solution. Fixes #3426
2021-08-16interperterbase: help type checkers do better type deductionDylan Baker1-1/+5
This assert causes several type checkers (both mypy and pyright) to force `obj` to be a base `HoldableObject` instead of the specialized object. Since the check itself may still be valuable as we don't have fully type annotation coverage it's simply been removed when type checking to aid in type specialization.
2021-08-16interpreter: allow KwargInfo.evolve to change the name as wellDylan Baker1-1/+2
2021-08-16Add unset_variable()Tristan Partin1-1/+1
This should be useful for helping to control variable scope within Meson. CMake has something similar for controlling scope.
2021-08-09interpreter: Fix list contains for Holders (fixes #9020 #9047)Daniel Mensinger1-2/+2
2021-08-04interpreterbase/decorators: fix typed_kwargs return typeDylan Baker1-2/+4
Because of the convertor function we have no guarantee that what we're getting is in fact a `Dict[str, TYPE_var]`, it might well be anything in the values, so we need to do some casting and set the return type to object. This works out fine in practice as our declared `TypeDict` inputs in the actual function signatures will be used instead.
2021-07-21Fix meson.version().version_compare() regression in subprojectXavier Claessens1-1/+1
2021-07-10fix: Fix recursive _unholder permissive kwarg (fixes #8977)Daniel Mensinger1-2/+2
2021-07-05condense linesEli Schwartz1-6/+3
2021-07-05more f-strings too complex to be caught by pyupgradeEli Schwartz1-6/+6
2021-07-02fix: get_variable default variables are not ObjectHolders (fixes #8936)Daniel Mensinger4-6/+11