提交 bc7420de authored 作者: Frederic's avatar Frederic

Better short_platform

上级 c64c967c
...@@ -66,7 +66,7 @@ compiledir_format_dict = { ...@@ -66,7 +66,7 @@ compiledir_format_dict = {
} }
def short_platform(): def short_platform(r=None, p=None):
"""Return a safe shorter version of platform.platform(). """Return a safe shorter version of platform.platform().
The old default Theano compiledir used platform.platform in The old default Theano compiledir used platform.platform in
...@@ -103,24 +103,42 @@ def short_platform(): ...@@ -103,24 +103,42 @@ def short_platform():
compiledir_Linux-2.6.32-220.7.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6 compiledir_Linux-2.6.32-220.7.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.4.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6 compiledir_Linux-2.6.32-220.4.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
We suppose the version are ``X.Y[.*]-(digit)*(anything)*``. We
keep ``X.Y`` and don't keep less important digit in the part
before ``-`` and we remove the leading digit after the first
``-``.
If the information don't fit that pattern, we do not modify
platform.
""" """
if r is None:
r = platform.release() r = platform.release()
if p is None:
p = platform.platform()
sp = r.split('-') sp = r.split('-')
if len(sp) != 2: if len(sp) < 2:
return r return p
# For the split before the first -, we remove all learning digit:
kernel_version = sp[0].split('.') kernel_version = sp[0].split('.')
if len(kernel_version) <= 2: if len(kernel_version) <= 2:
return r # kernel version should always have at least 3 number.
# If not, it use another semantic, so don't change it.
return p
sp[0] = '.'.join(kernel_version[:2]) sp[0] = '.'.join(kernel_version[:2])
# For the split after the first -, we remove leading non-digit value.
rest = sp[1].split('.') rest = sp[1].split('.')
while len(rest) > 2: while len(rest):
if rest[0].isdigit(): if rest[0].isdigit():
del rest[0] del rest[0]
else: else:
break break
sp[1] = '.'.join(rest) sp[1] = '.'.join(rest)
# For sp[2:], we don't change anything.
sr = '-'.join(sp) sr = '-'.join(sp)
p = platform.platform()
p = p.replace(r, sr) p = p.replace(r, sr)
return p return p
......
from theano.gof.compiledir import short_platform
def test_short_platform():
for r, p, a in [ # (release, platform, answer)
('3.2.0-70-generic',
'Linux-3.2.0-70-generic-x86_64-with-debian-wheezy-sid',
"Linux-3.2--generic-x86_64-with-debian-wheezy-sid"),
('3.2.0-70.1-generic',
'Linux-3.2.0-70.1-generic-x86_64-with-debian-wheezy-sid',
"Linux-3.2--generic-x86_64-with-debian-wheezy-sid"),
('3.2.0-70.1.2-generic',
'Linux-3.2.0-70.1.2-generic-x86_64-with-debian-wheezy-sid',
"Linux-3.2--generic-x86_64-with-debian-wheezy-sid"),
('2.6.35.14-106.fc14.x86_64',
'Linux-2.6.35.14-106.fc14.x86_64-x86_64-with-fedora-14-Laughlin',
'Linux-2.6-fc14.x86_64-x86_64-with-fedora-14-Laughlin'),
]:
o = short_platform(r, p)
assert o == a, (o, a)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论