Commit 4f19879 1 parent 936407e commit 4f19879 Copy full SHA for 4f19879
File tree 3 files changed +26
-6
lines changed
3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ Bug Fixes
41
41
Misc.
42
42
+++++
43
43
- (:pr: `342 `) Update some docs settings and requirements for newer tools.
44
+ - (:pr: `353 `) copied in pkg_resources.safe_version code as follow-up to Eric switch to packaging as both nwchem and gamess were now working.
45
+ the try_harder_safe_version might be even bettter
44
46
45
47
46
48
0.28.0 / 2024-06-21
Original file line number Diff line number Diff line change @@ -154,6 +154,14 @@ def test_parse_version():
154
154
assert str (v ) == "5.3.1"
155
155
156
156
157
- def test_safe_version ():
158
- v = qcel .util .safe_version ("5.3.1" )
159
- assert v == "5.3.1"
157
+ @pytest .mark .parametrize (
158
+ "inp,out" ,
159
+ [
160
+ ("5.3.1" , "5.3.1" ),
161
+ ("30 SEP 2023 (R2)" , "30.SEP.2023.-R2-" ),
162
+ ("7.0.0+N/A" , "7.0.0-N-A" ),
163
+ ],
164
+ )
165
+ def test_safe_version (inp , out ):
166
+ v = qcel .util .safe_version (inp )
167
+ assert v == out
Original file line number Diff line number Diff line change 1
1
import os
2
+ import re
2
3
import shutil
3
4
import sys
4
5
from typing import TYPE_CHECKING , List , Union
@@ -132,14 +133,23 @@ def which(
132
133
133
134
def safe_version (version ) -> str :
134
135
"""
135
- Package resources is a very slow load
136
+ Convert an arbitrary string to a standard version string by pkg_resources definition.
136
137
"""
137
- return str (parse_version (version ))
138
+ # from https://github.com/pypa/setuptools/blob/main/pkg_resources/__init__.py
139
+ # original function deprecated and never one-to-one replaced
140
+ from packaging .version import InvalidVersion , Version
141
+
142
+ try :
143
+ # normalize the version
144
+ return str (Version (version ))
145
+ except InvalidVersion :
146
+ version = version .replace (" " , "." )
147
+ return re .sub ("[^A-Za-z0-9.]+" , "-" , version )
138
148
139
149
140
150
def parse_version (version ) -> "Version" :
141
151
"""
142
- Package resources is a very slow load
152
+ Legitimate version
143
153
"""
144
154
from packaging .version import parse
145
155
You can’t perform that action at this time.
0 commit comments