summaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase/decorators.py
AgeCommit message (Collapse)Author
2025-12-17interpreterbase: Add a new field to KwargInfo for extra typesDylan Baker
We have some cases where we want to have an extra set of validators that run on specific types, and give detailed answers. However, we don't want those types to show up in the list of accepted types. This new keyword allows for that.
2025-10-29replace "in d.keys()" with "in d"Paolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-15Revert "typed_kwargs: Remove feature_validator as it's not currently used"Dylan Baker
This reverts commit 93c11f249495c4af4a88206cebefef3ecf0f3228. We're going to use it again in the next commit
2025-05-07interpreterbase: allow any return type for convertorsPaolo Bonzini
A convertor will *accept* something that is definitely a TYPE_var; but the output can be any Python object that the evaluation function desires. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-10-01interpreterbase/decorators: delete now unused stringArgsDylan Baker
2024-08-30Feature checks: fall back to reporting insufficiently portable featuresEli Schwartz
When projects do not specify a minimum meson version, we used to avoid giving them the benefit of the Feature checks framework. Instead: - warn for features that were added after the most recent semver bump, since they aren't portable to the range of versions people might use these days - warn for features that were deprecated before the upcoming semver bump, i.e. all deprecated features, since they aren't portable to upcoming semver-compatible versions people might be imminently upgrading to
2023-12-13Use SPDX-License-Identifier consistentlyDylan Baker
This replaces all of the Apache blurbs at the start of each file with an `# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing uses to be consistent in capitalization, and to be placed above any copyright notices. This removes nearly 3000 lines of boilerplate from the project (only python files), which no developer cares to look at. SPDX is in common use, particularly in the Linux kernel, and is the recommended format for Meson's own `project(license: )` field
2023-10-04Remove unused code in interpreterbaseTristan Partin
2023-08-11remove useless type annotationsEli Schwartz
These annotations all had a default initializer of the correct type, or a parent class annotation.
2023-07-24force interpreter functions to actually receive tuple from typed posargsEli Schwartz
We always expect the args parameter in the wrapped function to eventually receive a tuple due to reasons. But in one specific optargs condition we passed it along without any fixup at all.
2023-07-19fix implicit_reexport issues and enforce them going forwardEli Schwartz
This detects cases where module A imports a function from B, and C imports that same function from A instead of B. It's not part of the API contract of A, and causes innocent refactoring to break things.
2023-06-14remove unnecessary typing commentsEli Schwartz
Although they could be moved to annotations, the truth is that they are unneeded because they get inherited from the parent class.
2023-06-14add new FeatureBroken check class for annotating features that are really brokenEli Schwartz
This is useful for totally terrible stuff that we really dislike, but for some reason we are afraid to just use `mlog.deprecation()` and unconditionally tell people so. Apparently this is because it is totally absolutely vital that, when telling people something is so broken they should never ever ever use it no matter what, ever... we can't actually tell them that unless they bump the minimum version of Meson, because that's our standard way of introducing a **version number** to tell them when we first started warning about this. Sigh. We really want to warn people if they are doing totally broken stuff no matter what version of Meson they support, because it's not like fixing the thing that never worked is going to suddenly break old versions of meson. So. Here's some new functionality that always warns you, but also tells you when we started warning.
2023-04-11fix various spelling issuesJosh Soref
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-03-09re-deduplicate feature warnings printed at the end of setupEli Schwartz
In commit eaf365cb3ef4f1c2ba66e07237d86a44089aff4f we explicitly sorted them for neatness, with the rationale that we were restoring intentional behavior and we only need a set for stylistic purposes. This actually wasn't true, because we never sorted them to begin with (we did sort the version numbers), but sorting them is fine. The bigger issue is that we actually used a set to avoid printing the same feature type multiple times. Now we do print them multiple times -- because each registered feature includes the unique node. Fix this by using both sorted and a set. Fix tests that should in retrospect have flagged this as an issue, but were added later on in the same series to check something else entirely, happen to cover this too, and were presumably copied directly from stdout as-is...
2023-03-04typed_kwargs: Remove feature_validator as it's not currently usedXavier Claessens
2023-03-04typed_kwargs: Extend since_values and deprecated_values for typesXavier Claessens
2023-01-20decorators: don't unsort sorted values for printingDylan Baker
Currently in our deprecated/new feature printing we carefully sort all of the values, then put them in a set to print them. Which unsorts them. I'm assuming this was done because a set looks nice when printed (which is true). Let's keep the formatting, but print them in a stable order.
2022-12-05interpreter: add a feature_validator to KwargInfoDylan Baker
Because sometimes we simply need to open code FeatureNew and FeatureDeprecated checks, but in a re-usable way.
2022-10-24add option to typed_kwargs that allows unknown kwargs throughEli Schwartz
Some functions cannot be fully type checked, because our API allows fully arbitrary kwargs and treats them as data to pass through to the underlying feature. For example, hotdoc command line arguments. This change allows us to type check some kwargs with known types and possibly required status, and make their values consistent(ly defaultable), while preserving the optional nature of the additional kwargs.
2022-08-18interpreterbase: fix type annotations for KwargInfo::since_valuesDylan Baker
These are now allowed to be `Dict[_T | Type[list] | Type[dict], str]`, but the type annotations weren't updated
2022-06-17typed_kwargs: support dict/list as "new since" typesEli Schwartz
Given a kwarg value that is itself a dict/list, we would only check if the since_values was present within that container. If the since_values is itself the dict or list type, then we aren't looking for recursive structures, we just want to know when the function began to accept that type. This is relevant in cases where a function accepted a dict, and at one point began accepting a list (of strings in the form 'key=value'), or vice versa.
2022-05-19Reword message in warningZbigniew Jędrzejewski-Szmek
"targetting" is verb-derived adjective, which sort-of-works here, but makes the whole sentence awkward, because there's no verb. Let's just use present simple.
2022-05-19Reword misleading warningZbigniew Jędrzejewski-Szmek
"tried to use" implies that the attempt was not successful, i.e. that meson ignored the feature. But that is not what happens, apart from the warning the feature works just fine. The new message is also shorter ;)
2022-03-07move a bunch of imports into TYPE_CHECKING blocksEli Schwartz
These are only used for type checking, so don't bother importing them at runtime. Generally add future annotations at the same time, to make sure that existing uses of these imports don't need to be quoted.
2022-03-07treewide: string-quote the first argument to T.castEli Schwartz
Using future annotations, type annotations become strings at runtime and don't impact performance. This is not possible to do with T.cast though, because it is a function argument instead of an annotation. Quote the type argument everywhere in order to have the same effect as future annotations. This also allows linters to better detect in some cases that a given import is typing-only.
2022-03-07merge various TYPE_CHECKING blocks into oneEli Schwartz
A bunch of files have several T.TYPE_CHECKING blocks that each do some things which could just as well be done once, with a single `if` statement. Make them do so.
2022-03-01clean up FeatureCheck signature to move location to use timeEli Schwartz
The point of a .use() function is because we don't always have the information we need to use a feature check, so we allow creating the feature and then storing it for later use. When implementing location checks, although it is optional, actually using it violated that design. Move the location out of the init method for FeatureCheck itself. It remains compatible with all cases of .single_use(), but fix the rest up.
2022-03-01remove useless kwarg that was never usedEli Schwartz
I am not sure why it ever got added. It looks superficially similar to FeatureCheck itself, but doesn't need to.
2022-02-14FeatureNew: add mypy type annotations for subproject argEli Schwartz
Use a derived type when passing `subproject` around, so that mypy knows it's actually a SubProject, not a str. This means that passing anything other than a handle to the interpreter state's subproject attribute becomes a type violation, specifically when the order of the *four* different str arguments is typoed.
2022-01-10first pass at migrating to dataclassesEli Schwartz
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 Baker
2021-12-06add message option to since_values and deprecated_valuesDylan Baker
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 Baker
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 Baker
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 Schwartz
2021-12-05clean up function signatures in preparation for dataclassesEli Schwartz
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 Baker
Python uses this syntax now, as does typescript and other languages
2021-11-22typed_kwargs: provide better error messages for wrong container typesDylan Baker
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 Baker
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 Schwartz
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 Schwartz
2021-11-20add location support to feature checksEli Schwartz
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-01migrate python 3.5 compatible superclass variable annotations to 3.6Eli Schwartz
As we now require python 3.6, we can declare their types without initializing them.
2021-10-27fix various flake8 whitespace errorsEli Schwartz
2021-10-10Fix typos discovered by codespellChristian Clauss
2021-10-09typed_kwargs: Fix when ContainerTypeInfo is used in a tupleXavier Claessens
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-04fix extra whitespaceEli Schwartz
discovered via flake8 --select E303
2021-09-30interpreterbase/decorators: KwargIfno validator must take an relaxed typeDylan Baker
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 Mensinger