1
1
import sys
2
2
import shutil
3
- import toml
4
3
import subprocess
4
+ import tomllib
5
5
from pathlib import Path
6
6
import logging
7
7
from typing import Optional , List
8
- from packaging .version import Version , InvalidVersion
9
8
10
9
LOG = logging .getLogger (__name__ )
11
10
@@ -15,16 +14,16 @@ def get_version_from_dependency(tool: str) -> Optional[str]:
15
14
pyproject_path = Path (__file__ ).parent .parent / "pyproject.toml"
16
15
if not pyproject_path .exists ():
17
16
return None
18
- data = toml .load (pyproject_path )
17
+ data = tomllib .load (pyproject_path )
19
18
dependencies = data .get ("project" , {}).get ("dependencies" , [])
20
19
for dep in dependencies :
21
20
if dep .startswith (f"{ tool } ==" ):
22
21
return dep .split ("==" )[1 ]
23
22
return None
24
23
25
24
26
- DEFAULT_CLANG_FORMAT_VERSION = get_version_from_dependency ("clang-format" ) or "20.1.7"
27
- DEFAULT_CLANG_TIDY_VERSION = get_version_from_dependency ("clang-tidy" ) or "20.1.0"
25
+ DEFAULT_CLANG_FORMAT_VERSION = get_version_from_dependency ("clang-format" )
26
+ DEFAULT_CLANG_TIDY_VERSION = get_version_from_dependency ("clang-tidy" )
28
27
29
28
30
29
CLANG_FORMAT_VERSIONS = [
@@ -112,25 +111,15 @@ def _resolve_version(versions: List[str], user_input: Optional[str]) -> Optional
112
111
"""Resolve the version based on user input and available versions."""
113
112
if user_input is None :
114
113
return None
114
+ if user_input in versions :
115
+ return user_input
115
116
try :
116
- user_ver = Version (user_input )
117
- except InvalidVersion :
117
+ # Check if the user input is a valid version
118
+ return next (v for v in versions if v .startswith (user_input ) or v == user_input )
119
+ except StopIteration :
120
+ LOG .warning ("Version %s not found in available versions" , user_input )
118
121
return None
119
122
120
- candidates = [Version (v ) for v in versions ]
121
- if user_input .count ("." ) == 0 :
122
- matches = [v for v in candidates if v .major == user_ver .major ]
123
- elif user_input .count ("." ) == 1 :
124
- matches = [
125
- v
126
- for v in candidates
127
- if f"{ v .major } .{ v .minor } " == f"{ user_ver .major } .{ user_ver .minor } "
128
- ]
129
- else :
130
- return str (user_ver ) if user_ver in candidates else None
131
-
132
- return str (max (matches )) if matches else None
133
-
134
123
135
124
def _get_runtime_version (tool : str ) -> Optional [str ]:
136
125
"""Get the runtime version of a tool."""
0 commit comments