aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase/interpreterbase.py
AgeCommit message (Collapse)AuthorFilesLines
2023-09-11parser: simplify Assignment and PlusAssignment nodesCharles Brunet1-2/+2
2023-09-11parser: add ElseNodeCharles Brunet1-1/+1
2023-09-11parser: use IdNode for foreach varnamesCharles Brunet1-2/+2
2023-09-11parser: use IdNode for function name and assignment nameCharles Brunet1-5/+5
2023-09-11parser: preserve escape chars in stringsCharles Brunet1-11/+9
use separate Node for multiline strings
2023-09-11Add ParenthesizedNodeJCWasmx861-0/+2
2023-08-11treewide: automatic rewriting of all comment-style type annotationsEli Schwartz1-2/+2
Performed using https://github.com/ilevkivskyi/com2ann This has no actual effect on the codebase as type checkers (still) support both and negligible effect on runtime performance since __future__ annotations ameliorates that. Technically, the bytecode would be bigger for non function-local annotations, of which we have many either way. So if it doesn't really matter, why do a large-scale refactor? Simple: because people keep wanting to, but it's getting nickle-and-dimed. If we're going to do this we might as well do it consistently in one shot, using tooling that guarantees repeatability and correctness. Repeat with: ``` com2ann mesonbuild/ ```
2023-08-02Unify message(), format() and fstring formattingXavier Claessens1-6/+7
Share a common function to convert objects to display strings for consistency. While at it, also add support for formatting user options.
2023-07-19move various bits of type-checking only code to TYPE_CHECKING blocksEli Schwartz1-2/+1
Mostly detected with flake8-type-checking. Also quote T.cast() first arguments, since those are not affected by future annotations.
2023-07-19fix implicit_reexport issues and enforce them going forwardEli Schwartz1-8/+7
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-04-11fix various spelling issuesJosh Soref1-6/+6
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-04propagate the most accurate node to error messagesEli Schwartz1-3/+6
During evaluation of codeblocks, we start off with an iteration of nodes, and then while evaluating them we may update the global self.current_node context. When catching and formatting errors, we didn't take into account that the node might be updated from the original top-level iteration. Switch to formatting errors using self.current_node instead, to ensure we can point at the likely most-accurate actual cause of an error. Also update the current node in a few more places, so that function calls always see the function call as the current node, even if the most recently parsed node was an argument to the function call. Fixes #11643
2023-03-01handle meson_version after parsing but before invalid project() kwargsEli Schwartz1-0/+1
If we add new kwargs to a function invoked on the first line, we also need to validate the meson_version before erroring out due to unknown kwargs. Even if the AST was successfully built. Amusingly, we also get to improve the error message a bit. By passing the AST node instead of an interpreter node, we get not just line numbers, but also column offsets of the issueful meson_version. That broke the stdout of another failing test; adapt it.
2023-03-01handle meson_version even when the build file fails to parseEli Schwartz1-3/+10
If the meson.build file is sufficiently "broken", even attempting to lex and parse it will totally fail, and we error out without getting the opportunity to evalaute the project() function. This can fairly easily happen if we add new grammar to the syntax, which old versions of meson cannot understand. Setting a minimum meson_version doesn't help, because people with a too-old version of meson get parser errors instead of advice about upgrading meson. Examples of this include adding dict support to meson. There are two general approaches to solving this issue, one of which projects are empowered to do: - refactor the project to place too-new syntax in a subdir() loaded build file, so the root file can be interpreted - teach meson to catch errors in building the initial AST, and just load enough of the AST to check for meson_version advice This implements the latter, allowing to future-proof the build grammar.
2023-03-01interpreter: Add testcase..endtestcase clause supportXavier Claessens1-0/+13
This is currently only enabled when running unit tests to facilitate writing failing unit tests. Fixes: #11394
2023-02-27prevent unhandled exception for operations on NoneCharles Brunet1-9/+47
For instance, when writing `-subdir('a')` or `not subdir('a')`. Fixes #11225.
2023-02-01micro-optimize: define typing-only objects in TYPE_CHECKINGEli Schwartz1-20/+18
Union types that exist solely for use as annotations don't need to be created in normal runs.
2022-11-29pylint: enable useless-returnDylan Baker1-1/+0
2022-08-30fix obscure crash on unbound variableEli Schwartz1-4/+5
This can be triggered if someone tries to call a non-ID. The example reproducer was: ``` if (var = dependency(...)).found() ``` This produced a traceback ending in ``` raise InvalidArguments(f'Variable "{object_name}" is not callable.') UnboundLocalError: local variable 'object_name' referenced before assignment ``` After this commit, the error is reported as: ``` ERROR: AssignmentNode is not callable. ```
2022-05-01Add support for multiline f-stringsPeter Lesslie1-1/+8
+ Extend the parser to recognize the multiline f-strings, which the documentation already implies will work. The syntax is like: ``` x = 'hello' y = 'world' msg = f'''This is a multiline string. Sending a message: '@x@ @y@' ''' ``` which produces: ``` This is a multiline string. Sending a message: 'hello world' ``` + Added some f-string tests cases to "62 string arithmetic" to exercise the new behavior.
2022-03-07move a bunch of imports into TYPE_CHECKING blocksEli Schwartz1-3/+2
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-02-16flake8: use plain strings instead of f-strings when no variables usedEli Schwartz1-1/+1
2022-02-14FeatureNew: add mypy type annotations for subproject argEli Schwartz1-1/+3
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-27flake8: fix indentation styleEli Schwartz1-1/+1
2021-11-01various manual conversion of percent-formatted strings to f-stringsEli Schwartz1-5/+5
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-24interpreter: Fix missing featuer check (fixes #9425)Daniel Mensinger1-0/+6
2021-10-06interpreter: Holderify arrays and dictsDaniel Mensinger1-404/+103
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-09-25Remove helpers.check_stringlist()Daniel Mensinger1-4/+6
2021-09-25interpreter: Introduce StringHolderDaniel Mensinger1-120/+15
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 Mensinger1-62/+64
2021-09-01interpreter: Simplify Disabler logicDaniel Mensinger1-9/+3
2021-08-31interpreter: Add IntegerHolderDaniel Mensinger1-59/+41
2021-08-31interpreter: Introduce operators support for InterpreterObjectsDaniel Mensinger1-1/+41
2021-08-31interpreter: Make comparisons of different types a hard errorDaniel Mensinger1-4/+8
2021-08-31pylint: turn on superflous-parensDylan Baker1-10/+10
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-30Simplify get_callee_argsXavier Claessens1-6/+6
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-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-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 Mensinger1-1/+4
2021-06-29fix: Always explicitly set encoding for text files (fixes #8263)Daniel Mensinger1-1/+1
2021-06-26refactor: Refactor BothLibraries logicDaniel Mensinger1-1/+3
This commit introduces a new type of `HoldableObject`: The `SecondLevelHolder`. The primary purpose of this class is to handle cases where two (or more) `HoldableObject`s are stored at the same time (with one default object). The best (and currently only) example here is the `BothLibraries` class.
2021-06-20fix: dicts and list need _holderify for fallbackDaniel Mensinger1-2/+2
2021-06-20fix: Fix set_variable not holderifying (fixes #8904)Daniel Mensinger1-7/+20
2021-06-18holders: Ensure that InterpreterBase is the sole instance for (un)holderifyingDaniel Mensinger1-38/+111