@@ -162,6 +162,45 @@ def _execute_checked_stdout(mrctx, *, python, srcs, **kwargs):
162162 ** _execute_prep (mrctx , python = python , srcs = srcs , ** kwargs )
163163 )
164164
165+ def _run_toml2json (mrctx , toml_label , attr , logger = None ):
166+ """Parses a TOML file into a dictionary using toml2json tool.
167+
168+ Args:
169+ mrctx: The module_ctx or repository_ctx object.
170+ toml_label: Label pointing to the TOML file.
171+ attr: Attributes struct (e.g. from a repository rule). Must contain
172+ `_tool_python_interpreter` and `_toml2json`.
173+ logger: Optional logger instance for informational messages.
174+
175+ Returns:
176+ A dictionary representation of the TOML file content.
177+ """
178+ if not toml_label :
179+ fail ("toml_label cannot be None" )
180+
181+ python_interpreter = _resolve_python_interpreter (
182+ mrctx ,
183+ python_interpreter_target = attr ._tool_python_interpreter ,
184+ )
185+
186+ toml_path = mrctx .path (toml_label )
187+ if not toml_path .exists :
188+ fail ("toml file does not exist: {} (from label {})" .format (toml_path , toml_label ))
189+
190+ # Use the shared toml2json tool
191+ toml2json_tool = mrctx .path (ctx .attr ._toml2json )
192+
193+ stdout = _execute_checked_stdout (
194+ mrctx ,
195+ logger = logger ,
196+ op = "Toml2Json: {}" .format (toml_label ),
197+ python = python_interpreter ,
198+ arguments = [str (toml2json_tool ), str (toml_path )],
199+ srcs = [toml2json_tool , toml_path ],
200+ )
201+
202+ return json .decode (stdout )
203+
165204def _find_namespace_package_files (rctx , install_dir ):
166205 """Finds all `__init__.py` files that belong to namespace packages.
167206
@@ -202,4 +241,5 @@ pypi_repo_utils = struct(
202241 execute_checked_stdout = _execute_checked_stdout ,
203242 find_namespace_package_files = _find_namespace_package_files ,
204243 resolve_python_interpreter = _resolve_python_interpreter ,
244+ run_toml2json = _run_toml2json ,
205245)
0 commit comments