'How do I track where a pip dependency came from with Bazel?
I'm using bazel to manage a Python project, and there is currently an issue with the typing package:
File "<excluded>/pypi__typing/typing.py", line 1007, in __new__
self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'
After some investigation on Google, this appears to have come from the old typing
package that used to be installed via pip, and is now part of the Python standard library. This package no longer works, and so the recommended solution is to remove it and use the standard library one.
I can't do the recommended solution because I'm not using this package directly, and in a bazel environment I can't just run pip uninstall typing
. I need to find out how the package is getting included, and remove it from the source.
How can I track down where the package is being imported?
Solution 1:[1]
Turns out you can just use bazel query
to discover this.
Suppose your WORKSPACE file has this to import the dependencies:
pip_install(
name = "my_project_deps",
python_interpreter = "/usr/bin/python3",
requirements = "//my_project:requirements.txt",
)
You would then run the query:
bazel query 'allpaths(//my_project, @my_project_deps//pypi__typing)'
This gives me a result like this:
//my_project:target
//some/other:library
@my_project_deps//pypi__expiringdict:pypi__expiringdict
@my_project_deps//pypi__typing:pypi__typing
Seems like it's being pulled in by the expiringdict
package.
How you actually remove the dependency is another question; if they don't have a newer version then you may have to fork the package and fix it yourself. In this case since typing is now part of the standard library, it is probably just a matter of removing it from that package's list of dependencies.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | robbrit |