22# SPDX-License-Identifier: Apache-2.0
33"""Version utils for testing."""
44
5+ # pylint: disable=import-outside-toplevel
56from __future__ import annotations
67
78import packaging .version
89
910
1011def onnx_older_than (version : str ) -> bool :
1112 """Returns True if the ONNX version is older than the given version."""
12- import onnx # pylint: disable=import-outside-toplevel
13+ import onnx # noqa: TID251
1314
1415 return (
1516 packaging .version .parse (onnx .__version__ ).release
@@ -19,50 +20,17 @@ def onnx_older_than(version: str) -> bool:
1920
2021def torch_older_than (version : str ) -> bool :
2122 """Returns True if the torch version is older than the given version."""
22- import torch # pylint: disable=import-outside-toplevel
23+ import torch
2324
2425 return (
2526 packaging .version .parse (torch .__version__ ).release
2627 < packaging .version .parse (version ).release
2728 )
2829
2930
30- def transformers_older_than (version : str ) -> bool | None :
31- """Returns True if the transformers version is older than the given version."""
32- try :
33- import transformers # pylint: disable=import-outside-toplevel
34- except ImportError :
35- return None
36-
37- return (
38- packaging .version .parse (transformers .__version__ ).release
39- < packaging .version .parse (version ).release
40- )
41-
42-
43- def is_onnxruntime_training () -> bool :
44- """Returns True if the onnxruntime is onnxruntime-training."""
45- try :
46- from onnxruntime import training # pylint: disable=import-outside-toplevel
47-
48- assert training
49- except ImportError :
50- # onnxruntime not training
51- return False
52-
53- try :
54- from onnxruntime .capi .onnxruntime_pybind11_state import ( # pylint: disable=import-outside-toplevel
55- OrtValueVector ,
56- )
57- except ImportError :
58- return False
59-
60- return hasattr (OrtValueVector , "push_back_batch" )
61-
62-
6331def onnxruntime_older_than (version : str ) -> bool :
6432 """Returns True if the onnxruntime version is older than the given version."""
65- import onnxruntime # pylint: disable=import-outside-toplevel
33+ import onnxruntime
6634
6735 return (
6836 packaging .version .parse (onnxruntime .__version__ ).release
@@ -72,20 +40,9 @@ def onnxruntime_older_than(version: str) -> bool:
7240
7341def numpy_older_than (version : str ) -> bool :
7442 """Returns True if the numpy version is older than the given version."""
75- import numpy # pylint: disable=import-outside-toplevel
43+ import numpy
7644
7745 return (
7846 packaging .version .parse (numpy .__version__ ).release
7947 < packaging .version .parse (version ).release
8048 )
81-
82-
83- def has_transformers ():
84- """Tells if transformers is installed."""
85- try :
86- import transformers # pylint: disable=import-outside-toplevel
87-
88- assert transformers
89- return True # noqa
90- except ImportError :
91- return False
0 commit comments