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

Cleanup the python module #8992

Merged

Conversation

dcbaker
Copy link
Member

@dcbaker dcbaker commented Jul 13, 2021

I wanted to get us down to one set of python dependency classes, but that's still not achieved here. What is achieved is a complete set of type annotations for the python module (there's still some places where things fail because we need more typing in the interpreter), the use of the typed_* decorators where applicable, and the conversion of the mega PythonDependency to a dependency factory. The use of a factory allows us to drop a bunch of legacy cruft that had been mostly purged, but was sitll around because of this one dependency.

@xclaesse I dropped the test that checked the pkg_config.pcdep test, but I'm not sure if you were specifically trying to test .pcdep or if that was just the method you used to test the module itself. If the latter I can rewrite the test instead.

@dcbaker dcbaker added dependencies modules:python Issues specific to the python module labels Jul 13, 2021
@codecov
Copy link

codecov bot commented Jul 13, 2021

Codecov Report

Merging #8992 (3bfc105) into master (762c073) will decrease coverage by 3.13%.
The diff coverage is n/a.

❗ Current head 3bfc105 differs from pull request most recent head b4e826b. Consider uploading reports for the commit b4e826b to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8992      +/-   ##
==========================================
- Coverage   66.42%   63.29%   -3.14%     
==========================================
  Files         374      187     -187     
  Lines       84329    41945   -42384     
  Branches    17557     8737    -8820     
==========================================
- Hits        56018    26548   -29470     
+ Misses      23387    12990   -10397     
+ Partials     4924     2407    -2517     
Impacted Files Coverage Δ
dependencies/misc.py 46.48% <0.00%> (-2.69%) ⬇️
dependencies/coarrays.py 62.50% <0.00%> (-2.62%) ⬇️
dependencies/framework.py 20.00% <0.00%> (-1.92%) ⬇️
dependencies/dev.py 58.33% <0.00%> (-1.44%) ⬇️
dependencies/dub.py 12.02% <0.00%> (-1.02%) ⬇️
dependencies/configtool.py 82.00% <0.00%> (-0.53%) ⬇️
dependencies/base.py 83.13% <0.00%> (-0.50%) ⬇️
modules/pkgconfig.py 82.23% <0.00%> (-0.43%) ⬇️
dependencies/pkgconfig.py 59.72% <0.00%> (-0.42%) ⬇️
dependencies/cmake.py 80.95% <0.00%> (-0.14%) ⬇️
... and 177 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 762c073...b4e826b. Read the comment docs.

@dcbaker dcbaker force-pushed the submit/modernize-python-module-dependency branch from c416642 to 74ad9b6 Compare July 13, 2021 22:39
There's still a number of things that don't properly type check, that's
expected though as the input is often unvalidated and assumed good.
And note that the way that find_installation works is completely broken
in regards to machine files
Including not calling back into `Interpreter.func_*`, which is not a
good idea both from a type saftey and perforamance point of view.
Instead there's now a shared _impl method
This removes the odd 'pkgdep' attribute thing, and makes it behave more
like a proper dependency
Nothing uses this anymore, so don't check for it.
Both of these are artifacts of the time before Dependency Factories,
when a dependency that could be discovered multiple ways did ugly stuff
like finding a specific dependency, then replacing it's own attributes
with that dependency's attributes. We don't have cases of that left in
the tree, so let's get rid of this code too
These were spotted by mypy and pyright. One is a string where a Path is
expected, another other is a possibly unbound variable, and the third is
bound but unused variables.
@dcbaker dcbaker force-pushed the submit/modernize-python-module-dependency branch from 74ad9b6 to b4e826b Compare July 13, 2021 23:47
@dcbaker
Copy link
Member Author

dcbaker commented Jul 21, 2021

Anyone object to merging this? I have a series to use type checking in the pkg-config module that depends on this (and getting rid of the .pc_dep stuff)

Copy link
Member

@mensinda mensinda left a comment

Choose a reason for hiding this comment

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

Is there a specific reason why we still need class DependencyMethods(Enum) in base.py or can we get rid of it completely?

I really can't comment on the pcdep stuff since I have no idea what it is/was used for...

Comment on lines +56 to +61
if T.TYPE_CHECKING:
_Base = ExternalDependency
else:
_Base = object

class _PythonDependencyBase(_Base):
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason for doing this (cyclic imports?) or is this just for improving imports?

Copy link
Member Author

Choose a reason for hiding this comment

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

It helps mypy, which doesn't understand these kind of mixing classes at all. So we get two choices, forward declare a bunch of methods and attributes in the mixing class and try to keep them in sync, or this, which has mypy understand this as an ExternalProgram, but at runtime avoids the two bases problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

I use the same trick in the compilers class.

@jpakkane jpakkane merged commit 4703f4c into mesonbuild:master Jul 21, 2021
@dcbaker dcbaker deleted the submit/modernize-python-module-dependency branch July 21, 2021 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies modules:python Issues specific to the python module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants