Skip to content

Commit 53d8037

Browse files
committed
Fix, fix not run format tool when not install toml pkg
1 parent aa5168a commit 53d8037

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

protobuf_to_pydantic/util.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ def get_pyproject_content(pyproject_file_path: str) -> str:
127127
# flake8: noqa: C901
128128
def format_content(content_str: str, pyproject_file_path: str = "") -> str:
129129
pyproject_dict: dict = {}
130+
toml = None # type: ignore
131+
130132
try:
131-
import tomllib as toml
133+
import tomllib as toml # type: ignore
132134
except ImportError:
133135
try:
134136
import toml # type: ignore
@@ -137,10 +139,11 @@ def format_content(content_str: str, pyproject_file_path: str = "") -> str:
137139
"The toml module is not installed and the configuration information cannot be obtained through"
138140
" pyproject.toml"
139141
)
140-
else:
141-
pyproject_content = get_pyproject_content(pyproject_file_path)
142-
if pyproject_content:
143-
pyproject_dict = toml.loads(pyproject_content)
142+
143+
if toml:
144+
pyproject_content = get_pyproject_content(pyproject_file_path)
145+
if pyproject_content:
146+
pyproject_dict = toml.loads(pyproject_content)
144147
try:
145148
p2p_format_dict: dict = pyproject_dict["tool"]["protobuf-to-pydantic"]["format"]
146149
except KeyError:

0 commit comments

Comments
 (0)