13
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
# See the License for the specific language governing permissions
15
15
# and limitations under the License.
16
- from pathlib import Path
16
+ import os
17
+ from importlib .util import module_from_spec , spec_from_file_location
17
18
from typing import List
18
19
19
20
from setuptools import find_packages , setup
20
21
21
22
23
+ def load_module (name : str = "anomalib/__init__.py" ):
24
+ """Load Python Module.
25
+
26
+ Args:
27
+ name (str, optional): Name of the module to load.
28
+ Defaults to "anomalib/__init__.py".
29
+
30
+ Returns:
31
+ _type_: _description_
32
+ """
33
+ location = os .path .join (os .path .dirname (__file__ ), name )
34
+ spec = spec_from_file_location (name = name , location = location )
35
+ module = module_from_spec (spec ) # type: ignore
36
+ spec .loader .exec_module (module ) # type: ignore
37
+ return module
38
+
39
+
22
40
def get_version () -> str :
23
41
"""Get version from `anomalib.__init__`.
24
42
@@ -28,21 +46,15 @@ def get_version() -> str:
28
46
the value assigned to it.
29
47
30
48
Example:
31
- >>> # Assume that __version__ = "0.2.1 "
49
+ >>> # Assume that __version__ = "0.2.6 "
32
50
>>> get_version()
33
- "0.2.1 "
51
+ "0.2.6 "
34
52
35
53
Returns:
36
- str: Version number of `anomalib` package .
54
+ str: `anomalib` version .
37
55
"""
38
-
39
- with open (Path .cwd () / "anomalib" / "__init__.py" , "r" , encoding = "utf8" ) as file :
40
- lines = file .readlines ()
41
- for line in lines :
42
- line = line .strip ()
43
- if line .startswith ("__version__" ):
44
- version = line .replace ("__version__ = " , "" )
45
-
56
+ anomalib = load_module (name = "anomalib/__init__.py" )
57
+ version = anomalib .__version__
46
58
return version
47
59
48
60
@@ -85,8 +97,7 @@ def get_required_packages(requirement_files: List[str]) -> List[str]:
85
97
86
98
setup (
87
99
name = "anomalib" ,
88
- # TODO: https://github.com/openvinotoolkit/anomalib/issues/36
89
- version = "0.2.6" ,
100
+ version = get_version (),
90
101
author = "Intel OpenVINO" ,
91
102
92
103
description = "anomalib - Anomaly Detection Library" ,
0 commit comments