I am trying to move a large project to using Bazel, and I am starting small. I have found a small wrapper around pydantic in our project, and I am trying to "bazelify" that first.
The initial structure of the package was something like this:
pydantic_utils
+- __init__.py
+- some_module.py
+- some_other_module.py
+- subdir
+- one.py
+- tests
+- __init__.py
+- test_some_module.py
I added BUILD.bazel files to this structure and everything worked fine, my tests ran and passed. But then I thought, I'd put the tests into the root dir of our wrapper lib. So I moved the test_some_module one level up, moved the py_test target to the BUILD.bazel file in the root dir, modified the srcs of both targets not to include the other target's files:
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@my_pip_install//:requirements.bzl", "requirement")
py_library(
name = "pydantic_utils",
srcs = glob(
["*.py"],
exclude = ["test_*.py"],
),
visibility = ["//visibility:public"],
deps = [
"//pydantic_utils/subdir",
requirement("pydantic"),
],
)
py_test(
name = "test_pydantic_utils_dp",
srcs = glob([
"test_*.py",
]),
main = "test_some_module.py",
deps = [
"//pydantic_utils",
requirement("pytest"),
],
)
But now I get an error, that pydantic cannot import TYPE_CHECKING for some reason.
...pydantic_utils/test_some_module.py", line 2, in <module>
from typing import Any
...
File "pydantic/__init__.py", line 2, in init pydantic.__init__
from .models import (
File "pydantic/dataclasses.py", line 1, in init pydantic.dataclasses
import re
ImportError: cannot import name TYPE_CHECKING
It is a very vague question, but I have no idea how to begin to diagnose it. Can anyone help me?
Please upgrade your python to the latest version if you are using the old one. It has support upto 3.10 and above. Thats a general error log from Python implementation. Reach out if you are still seeing the error after the upgrade.