summaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase.py
AgeCommit message (Collapse)Author
2021-06-11interpreter: Move interpreterbase.py into a new packageDaniel Mensinger
2021-06-08intperperterbase: Add a convertor keyword argumentDylan Baker
This is meant to allow simple type conversions to happen before the interpreter function is called. This should simplify some cases like the "native" keyword arugment that are booleans in the Meson DSL, but an Enum in the implementation
2021-06-08interpreterbase: Add validator keyword argument to typed_kwargsDylan Baker
This attribute is a callable that returns a string if the value is invalid, otherwise None. This intended for cases like the `install_*` function's `install_mode` paramater, which is either an int or the string "preserve", which allows us to do nice things like: ```python class Kwargs(TypedDict): install_mode: T.Union[int, T.Literal['preserve']] @typed_kwargs( 'foo', KwargInfo('install_mode', ..., validator=lambda x: None if isinstance(x, int) or x == 'preserve' else 'must be the literal "preserve"), ) def install_data(self, node, args, kwargs: 'Kwargs'): ... ``` In this case mypy *knows* that the string is preserve, as do we, and we can simply do tests like: ```python if kwargs['install_mode'] == 'preserve': ... else: # this is an int ```
2021-06-08make all arguments to KwargInfo except name and type keyword onlyDylan Baker
To make them easier to understand in practice
2021-06-04interpreterbase: Allow safely using mutable default values with typed_kwargsDylan Baker
It's really inconvenient to want a thing that is always a list, but not be able to provide a default value of a list because of mutation. To that end the typed_kwargs method now makes a shallow copy of the default when using a `ContainerTypeInfo` as the type. This mean that using a default of `[]` is perfectly safe.
2021-06-04interpreterbase: fix type annotations for typed_pos_argsDylan Baker
It takes a tuple of any length, for optargs and varargs, not a tuple of length 1
2021-06-01typed_kwargs: Add since and deprecated annotationsXavier Claessens
2021-05-30interpreterbase: Add a function for type checking keyword argumentsDylan Baker
2021-05-28modules: Remove snippet methodsXavier Claessens
The only advantage they have is they have the interpreter in arguments, but it's already available as self.interpreter. We should discourage usage of the interpreter API and rely on ModuleState object instead in the future. This also lift the restriction that a module method cannot add build targets, but that was not enforced for snippet methods anyway (and some modules were doing it) and it's really loose restriction as it should check for many other things if we wanted to make it consistent.
2021-03-16Add range() functionXavier Claessens
Fixes: #5026.
2021-03-16typed_pos_args: Fix typoXavier Claessens
2021-03-10Some documentation language adjustments & improved error messagesLaurin-Luis Lehning
2021-03-10Add tentative FeatureNew guardLaurin-Luis Lehning
2021-03-10Add failing test cases & release snippetLaurin-Luis Lehning
2021-03-10Use interpreter exceptions instead of MesonExceptionLaurin-Luis Lehning
2021-03-10Switch fstring syntax to @..@ & limit fstring captures to int, str, float ↵Laurin-Luis Lehning
and bool
2021-03-10Add support for basic format stringsLaurin-Luis Lehning
2021-03-09Add str.replace() methodTristan Partin
2021-03-04mass rewrite of string formatting to use f-strings everywhereEli Schwartz
performed by running "pyupgrade --py36-plus" and committing the results
2021-02-25interpreterbase: fix ObjectHolderDylan Baker
There are two problems: 1. It doesn't take the generic type as a parameter 2. it sets subpproject to None, but expects to always get a string
2021-02-06clarify some things in typed_pos_argsDylan Baker
This uses some variables to simplify some logic, and updates the docstring to be more useful.
2021-02-06interpreterbase: Add support for optional arguments to typed_pos_argsDylan Baker
This allows representing functions like assert(), which take optional positional arguments, which are not variadic. More importnatly you can represent a function like (* means optional, but possitional): ```txt func(str, *int, *str) ``` typed_pos_args will check that all of your types are correct, and if not provide None, which allow simplifying a number of implementation details
2021-02-06interpreterbase: Add support for variadic arguments to typed_pos_argsDylan Baker
This allows functions like `files()` to be decorated.
2021-02-06interpreterbase: Add a helper method for typing positional argumentsDylan Baker
We don't do a very good job of type checking in the interpreter, sometimes we leave it to the mid layers of backends to do that (layering violations) and sometimes we just don't check them at all. When we do check them it's a ton of boilerplate and complicates the code. This should help quite a bit.
2021-01-13Fix misspellsAntonin Décimo
Signed-off-by: Antonin Décimo <antonin.decimo@gmail.com>
2020-11-15stabilize iteration order for dictionariesPaolo Bonzini
The order of keys in dictionaries cannot be relied upon, because the hash values are randomized by Python. Whenever we iterate on dictionaries and meson.build generates a list during the iteration, the different iteration orders may cause random changes in the command line and cause ninja to rebuild a lot of files unnecessarily.
2020-09-28Add meson.project_build/source_root() methodsXavier Claessens
2020-09-08typing: get rid of most T.castDaniel Mensinger
2020-09-08typing: fully annotate mparser.pyDaniel Mensinger
2020-09-08typing: fully annotate mesonlib.pyDaniel Mensinger
2020-09-08typing: completely type interpreterbaseDaniel Mensinger
2020-09-08typing: refactor dict handlingDaniel Mensinger
2020-09-02interpreterbase: Fix typing annotationXavier Claessens
Co-authored-by: Daniel Mensinger <daniel@mensinger-ka.de>
2020-09-02Special case meson.version().version_compare() statementXavier Claessens
when that statement gets evaluated, the interpreter remembers the version target and if it was part of the evaluation of a `if` condition then the target meson version is temporally overriden within that if-block. Fixes: #7590
2020-08-18prevent disabler() object from overwriting arrays (#7484)Elliot
* prevent disabler object from overwriting arrays fixes #7107 * fix failing test forgot that func() != func(void) in c
2020-07-28Fix typoZbigniew Jędrzejewski-Szmek
2020-07-20string: add substring methodStéphane Cerveau
This method aims to offer a simple way to 'substring' an existing string with start and end values.
2020-05-14use FeatureNew.single_useDylan Baker
This is just slightly cleaner looking
2020-05-14interpreterbase: Proxy extra_message through to feature_check_classDylan Baker
2020-05-14interpreterbase: Add a oneline helper method for Feature(New|Deprecated)Dylan Baker
This allows us to replace FeatureNew(..).use() with just FeatureNew.single_use(...). It's a lttle cleaner and hides some of the smell.
2020-05-14interpreterbase: Allow passing an extra message in feature/deprecation warningsDylan Baker
The intended use it to tell people the new thing to do.
2020-05-12interpreterbase: Fix version checking for deprecationDylan Baker
Currently deprecation features use the same logic as new features, but that doesn't work correctly. FeatureNew wants to warn about cases where you claim to support >= 0.40, but use a feature from 0.42; deprecation wants to warn when you claim to support >= 0.50, but use a feature that was replaced in 0.45. To make this work we need to invert the version check in the deprecation function, so that if the deprecation is 0.45, and the supported version is >= 0.50, we get a true not a false.
2020-05-12interpreter: Don't assign duplication and new feature warning to the same ↵Dylan Baker
variable Currently The Deprecated and New features checkers share an attribute through a base class that should be per class. We need to duplicate this and move it into each of the sublcasses Fixes #7080
2020-04-30Allow get_variable to still function when the fallback is a disabler.James Hilliard
2020-03-19interpreterbase: Add warning when built-in object method has no kwargsXavier Claessens
2020-03-15fix conversion of hasattr to getattrDylan Baker
getattr() requires a default (return if missing) value or it raises an AttributeError. In a few cases I changed hasattr to getattr and didn't set a default value, so those cases could except. This corrects that.
2020-03-05mesonbuild/mesonlib: Add type annotationsDylan Baker
2020-03-02types: Remove redundant __init__() -> None annotationDaniel Mensinger
2020-03-02types: Use import typing as TDaniel Mensinger
2020-03-02review: Initial fixupDaniel Mensinger