Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use typed_kwargs for Dependency #12057

Open
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

dcbaker
Copy link
Member

@dcbaker dcbaker commented Jul 31, 2023

This is a rather length series (though I've tried to structure it in such a way that we can land small pieces at a time), that converts the dependency() function to use typed_kwargs, and makes some cleanups along the way.

I've made a deviation from the way we handle TypedDict elsewhere, and that is that I've used the total=False argument. What I found when I tried not doing that, is that there is such a tight coupling between build.Dependency() and the Interpreter layer is that any internal Dependency instantiation became very verbose. A followup that might be able to solve this is to to switch Dependency to use all named arguments, such that reasonable defaults are always available. As such we still have to use a great deal of kwargs.get(), but it does allow for better type checking.

I've also converted the dependency cache to use a distinct class for the key, as I found the old approach to give different results when a keyword argument was undefined vs defined to it's default value, which shouldn't be true.

This also gets the interpreter/dependencyfallbacks.py module very close to being type safe.

I've opened this as a draft because I'm sure there are still failing tests, but cursory reviews are still welcome.

@dcbaker dcbaker force-pushed the submit/typed-kwargs-dependency branch from 0e8c1f7 to 4c57557 Compare July 31, 2023 21:32
mesonbuild/dependencies/base.py Outdated Show resolved Hide resolved
mesonbuild/build.py Show resolved Hide resolved
mesonbuild/interpreter/mesonmain.py Outdated Show resolved Hide resolved
mesonbuild/dependencies/cmake.py Show resolved Hide resolved
mesonbuild/interpreter/interpreter.py Outdated Show resolved Hide resolved
mesonbuild/dependencies/cmake.py Outdated Show resolved Hide resolved
@tristan957 tristan957 added this to the 1.3.0 milestone Aug 7, 2023
@tristan957
Copy link
Contributor

Looks like this needs a rebase on master

@xclaesse xclaesse modified the milestones: 1.3.0, 1.4.0 Oct 17, 2023
@dcbaker dcbaker force-pushed the submit/typed-kwargs-dependency branch 10 times, most recently from 7de47e7 to 016f303 Compare December 5, 2023 18:03
@dcbaker dcbaker marked this pull request as ready for review December 5, 2023 18:54
@tristan957
Copy link
Contributor

Ready for another review?

@dcbaker
Copy link
Member Author

dcbaker commented Dec 5, 2023

Yes please

Copy link
Contributor

@tristan957 tristan957 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was pretty easy to follow. Just left a few comments. For what it's worth, I ran this over postgres and saw no regressions!

mesonbuild/dependencies/base.py Outdated Show resolved Hide resolved
mesonbuild/build.py Show resolved Hide resolved
mesonbuild/dependencies/detect.py Outdated Show resolved Hide resolved
mesonbuild/dependencies/detect.py Show resolved Hide resolved
mesonbuild/interpreter/interpreter.py Outdated Show resolved Hide resolved
mesonbuild/interpreter/type_checking.py Show resolved Hide resolved
mesonbuild/dependencies/base.py Show resolved Hide resolved
@dcbaker dcbaker force-pushed the submit/typed-kwargs-dependency branch from 016f303 to be4a5cc Compare December 6, 2023 20:22
@dcbaker
Copy link
Member Author

dcbaker commented Dec 6, 2023

I know I didn't get to all of your comments @tristan957, but I think I hit the majority of them

@tristan957
Copy link
Contributor

Works for me. This is gonna be a great addition to the codebase!

@dcbaker dcbaker force-pushed the submit/typed-kwargs-dependency branch 4 times, most recently from d323faa to f724dc7 Compare December 6, 2023 21:13
This also allows simplifying the DependencyFallbacksHolder.set_fallback
a little, since we now know for sure we'll have a list of 0, 1, or 2
elements. It also fixes an incorrect FeatureNew, which said that the
single element array/string value was since 0.53; it's actually since
0.54
I'm not sure what validation to do where. Which methods a particular
dependency allows are dependency specific, but there are a set of valid
ones, and a set of totally deprecated ones/new ones added that it would
be good to emit featurechecks for.
I've made native required, not optional. This is required to ensure that
sub-dependencies have the same machine target as the parent.
So we can get proper since warnings
We do some injection of values in some cases that we don't allow from
the command line, this adds them and allows us to get rid of the rest of
our type: ignore comments
Which gets us super close to having this all type safe
We have several values that are deprecated or added, that are currently
not handled due to needing access to the Environment. This can be easily
fixed by handling them in the interpreter
Since type checkers now view MisingCompiler as a Compiler, and it
provides a method to determine that it is missing (language ==
'missing'), we don't need to expose it anywhere, it's just an
implementation detail of the dependencies.base module.
@dcbaker dcbaker force-pushed the submit/typed-kwargs-dependency branch from 46eb3e7 to bde51f3 Compare December 21, 2023 21:17
@tristan957
Copy link
Contributor

If you rebase this, I can give it one more review and approval. Sorry it fell off my radar.

@bruchar1 bruchar1 removed this from the 1.4.0 milestone May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants