Skip to content

Commit af26784

Browse files
authored
Merge pull request #1140 from IntelPython/fix/cmake_version_format
Fix cmake version convertion
2 parents 339be1c + 8cc5b77 commit af26784

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

setup.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6+
import re
67
import sys
78

89
from setuptools import find_packages
@@ -35,12 +36,17 @@
3536
"""
3637

3738

38-
def to_cmake_format(version):
39+
def to_cmake_format(version: str):
3940
"""Convert pep440 version string into a cmake compatible string."""
40-
version = version.strip()
41-
parts = version.split("+")
42-
tag, dist = parts[0], parts[1].split(".")[0]
43-
return tag + "." + dist
41+
# cmake version just support up to 4 numbers separated by dot.
42+
# https://peps.python.org/pep-0440/
43+
# https://cmake.org/cmake/help/latest/command/project.html
44+
45+
match = re.search(r"^\d+(?:\.\d+(?:\.\d+(?:\.\d+)?)?)?", version)
46+
if not match:
47+
raise Exception("Unsupported version")
48+
49+
return match.group(0)
4450

4551

4652
# Set is_install and is_develop flags

0 commit comments

Comments
 (0)