Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[TESTS] Fix ONNX serialization test failures: setuptools bump + converter bug fix (#36854)

Maxim Vafin4bdc268b69dd
diff --git a/cmake/developer_package/check_python_requirements.py b/cmake/developer_package/check_python_requirements.py
index 8db944ee6e4..ee41bcfb882 100644
--- a/cmake/developer_package/check_python_requirements.py
+++ b/cmake/developer_package/check_python_requirements.py
@@ -1,7 +1,12 @@
-import pkg_resources
+# Copyright (C) 2018-2026 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
import re
import os
+from importlib.metadata import PackageNotFoundError, version as _installed_version
+from packaging.requirements import Requirement
+
def check_python_requirements(requirements_path: str) -> None:
"""
@@ -29,6 +34,10 @@ def check_python_requirements(requirements_path: str) -> None:
if line.startswith("#") or line=="\n":
continue
line = line.replace("\n", "")
+ # drop inline comments (e.g. "numpy>=1.16.6,<2.6.0 # frontends")
+ line = line.split("#", 1)[0].strip()
+ if not line or line.startswith("-"):
+ continue
package, delimiter, constraint = re.split("(~|=|<|>|;)", line, maxsplit=1)
if constraints.get(package) is None:
constraints[package] = [delimiter + constraint]
@@ -37,16 +46,37 @@ def check_python_requirements(requirements_path: str) -> None:
for line in raw_requirements:
if line.startswith(("#", "-c")):
continue
- line = line.replace("\n", "")
- if re.search("\W", line):
- requirements.append(line)
+ line = line.split("#", 1)[0].strip()
+ if not line:
+ continue
+ req = Requirement(line)
+ # If the requirement pins no version of its own, apply the version
+ # bound(s) from constraints.txt, preserving any environment marker.
+ if not req.specifier:
+ marker = f"; {req.marker}" if req.marker is not None else ""
+ for constraint in constraints.get(req.name) or [""]:
+ requirements.append(req.name + constraint + marker)
else:
- constraint = constraints.get(line)
- if constraint:
- for marker in constraint:
- requirements.append(line+marker)
- else:
- requirements.append(line)
+ requirements.append(line)
else:
requirements = raw_requirements
- pkg_resources.require(requirements)
+
+ # Validate each requirement against the installed distributions. Uses
+ # importlib.metadata + packaging instead of the removed pkg_resources API
+ # (dropped in setuptools>=82), so the check keeps working with modern
+ # setuptools. Raises to signal an unsatisfied requirement to the caller.
+ for raw in requirements:
+ raw = raw.strip()
+ if not raw or raw.startswith(("#", "-")):
+ continue
+ req = Requirement(raw)
+ # Skip requirements whose environment markers don't apply here.
+ if req.marker is not None and not req.marker.evaluate():
+ continue
+ try:
+ installed = _installed_version(req.name)
+ except PackageNotFoundError:
+ raise RuntimeError(f"Required package '{req.name}' is not installed")
+ if req.specifier and installed not in req.specifier:
+ raise RuntimeError(
+ f"Installed '{req.name}=={installed}' does not satisfy requirement '{raw}'")
diff --git a/src/bindings/python/constraints.txt b/src/bindings/python/constraints.txt
index 5c9dacfb5af..456aa4afef2 100644
--- a/src/bindings/python/constraints.txt
+++ b/src/bindings/python/constraints.txt
@@ -10,7 +10,7 @@ pytest-timeout==2.4.0
# Python bindings
build<1.6
pygments>=2.8.1
-setuptools>=77,<80.10
+setuptools>=77,<84
sympy>=1.10
wheel>=0.38.1
patchelf<=0.17.2.4
diff --git a/src/frontends/onnx/tests/onnx_prototxt_converter.py b/src/frontends/onnx/tests/onnx_prototxt_converter.py
index e8e205be84e..586cf747ddb 100644
--- a/src/frontends/onnx/tests/onnx_prototxt_converter.py
+++ b/src/frontends/onnx/tests/onnx_prototxt_converter.py
@@ -58,7 +58,7 @@ def _get_output_file_path(path, extension):
def save_model(proto, f, format=None, save_as_external_data=False, all_tensors_to_one_file=True, location=None, size_threshold=1024, convert_attribute=False):
if isinstance(proto, bytes):
- proto = onnx.serialization.registry.get("protobuf").serialize_proto(proto, onnx.ModelProto())
+ proto = onnx.serialization.registry.get("protobuf").deserialize_proto(proto, onnx.ModelProto())
if save_as_external_data:
convert_model_to_external_data(proto, all_tensors_to_one_file, location, size_threshold, convert_attribute)
diff --git a/src/frontends/paddle/tests/paddle_pip_check.py b/src/frontends/paddle/tests/paddle_pip_check.py
index db6d31e2c03..9f7ebca18b0 100644
--- a/src/frontends/paddle/tests/paddle_pip_check.py
+++ b/src/frontends/paddle/tests/paddle_pip_check.py
@@ -1,8 +1,13 @@
-import pkg_resources
+# Copyright (C) 2018-2026 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
import re
import sys
import os
+from importlib.metadata import PackageNotFoundError, version as _installed_version
+from packaging.requirements import Requirement
+
req_file=sys.argv[1]
constraints = {}
@@ -25,6 +30,10 @@ if constraints_path:
if line.startswith("#") or line=="\n":
continue
line = line.replace("\n", "")
+ # drop inline comments (e.g. "numpy>=1.16.6,<2.6.0 # frontends")
+ line = line.split("#", 1)[0].strip()
+ if not line:
+ continue
package, delimiter, constraint = re.split("(~|=|<|>|;)", line, maxsplit=1)
if constraints.get(package) is None:
constraints[package] = [delimiter + constraint]
@@ -46,19 +55,24 @@ if constraints_path:
else:
requirements = raw_requirements
-try:
- pkg_resources.require(requirements)
-except Exception as inst:
- pattern = re.compile(
- r"protobuf .*, Requirement.parse\('protobuf<=3\.20\.0,>=3\.1\.0'\), {'paddlepaddle'}"
- )
- result = pattern.findall(str(inst))
- if len(result) == 0:
- raise inst
- else:
- env = pkg_resources.Environment()
- env['protobuf'].clear()
- env.add(pkg_resources.DistInfoDistribution(project_name="protobuf", version="3.20.0"))
- ws = pkg_resources.working_set
- reqs = pkg_resources.parse_requirements(open(req_file, mode='r'))
- dists = ws.resolve(reqs, env, replace_conflicting=True)
+# Validate each requirement against the installed distributions. Uses
+# importlib.metadata + packaging instead of the removed pkg_resources API
+# (dropped in setuptools>=82), so the check keeps working with modern
+# setuptools. Only the directly-listed requirements are checked (transitive
+# dependencies are not walked), which sidesteps the paddlepaddle -> protobuf
+# transitive conflict the old pkg_resources.require() path had to special-case.
+for raw in requirements:
+ raw = raw.strip()
+ if not raw or raw.startswith(("#", "-")):
+ continue
+ req = Requirement(raw)
+ # Skip requirements whose environment markers don't apply here.
+ if req.marker is not None and not req.marker.evaluate():
+ continue
+ try:
+ installed = _installed_version(req.name)
+ except PackageNotFoundError:
+ raise RuntimeError(f"Required package '{req.name}' is not installed")
+ if req.specifier and installed not in req.specifier:
+ raise RuntimeError(
+ f"Installed '{req.name}=={installed}' does not satisfy requirement '{raw}'")