forked from JPEWdev/shacl2code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
32 lines (26 loc) · 746 Bytes
/
Copy pathutil.py
File metadata and controls
32 lines (26 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env python3
#
# Copyright (c) 2026 Joshua Watt
#
# SPDX-License-Identifier: MIT
"""General utility functions"""
def convert_version_string(s):
"""
Converts a version string into a tuple. The version is split by the "."
character, and any part that can be converted to a base-10 positive integer
is converted, otherwise it is left as a string.
"""
if not s:
return tuple()
result = []
for part in s.split("."):
try:
if not part.startswith("+"):
i = int(part, 10)
if i >= 0:
result.append(i)
continue
except ValueError:
pass
result.append(part)
return tuple(result)