Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/serv-inc/sacred into serv…
Browse files Browse the repository at this point in the history
…-inc-master

Changed behavior to first try old way of getting CPU info and then fallback to py-cpuinfo, since the latter takes ~1sec.

# Conflicts:
#	requirements.txt
  • Loading branch information
Qwlouse committed May 6, 2018
2 parents 4edb636 + 4a31432 commit e347f6d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
3 changes: 2 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ numpy==1.11.3
pandas==0.19.2
pbr==1.10.0
py==1.4.32
py-cpuinfo==4.0
pymongo==3.4.0
pytest==3.0.5
python-dateutil==2.6.0
Expand All @@ -23,4 +24,4 @@ smmap2==2.0.1
SQLAlchemy==1.1.4
tinydb==3.2.1
tinydb-serialization==1.0.3
wrapt==1.10.8
wrapt==1.10.8
18 changes: 10 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
docopt==0.6.2
jsonpickle==0.9.3
mock==2.0.0
munch==2.0.4
pbr==1.10.0
py==1.4.32
pytest==3.0.5
wrapt==1.10.8
docopt>=0.6.2
jsonpickle>=0.9.3
mock>=2.0.0
munch>=2.0.4
pbr>=1.10.0
py>=1.4.32
py-cpuinfo>=4.0
pytest>=3.0.5
six>=1.10.0
wrapt>=1.10.8
16 changes: 2 additions & 14 deletions sacred/host_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import os
import platform
import re
import subprocess
import xml.etree.ElementTree as ET
import cpuinfo
from sacred.utils import optional_kwargs_decorator, FileNotFoundError
from sacred.settings import SETTINGS

Expand Down Expand Up @@ -90,19 +90,7 @@ def _python_version():

@host_info_getter(name='cpu')
def _cpu():
if platform.system() == "Windows":
return platform.processor().strip()
elif platform.system() == "Darwin":
os.environ['PATH'] += ':/usr/sbin'
command = ["sysctl", "-n", "machdep.cpu.brand_string"]
return subprocess.check_output(command).decode().strip()
elif platform.system() == "Linux":
command = ["cat", "/proc/cpuinfo"]
all_info = subprocess.check_output(command).decode()
model_pattern = re.compile("^\s*model name\s*:")
for line in all_info.split("\n"):
if model_pattern.match(line):
return model_pattern.sub("", line, 1).strip()
return cpuinfo.get_cpu_info()['brand']


@host_info_getter(name='gpus')
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
'docopt>=0.3, <1.0',
'jsonpickle>=0.7.2, <1.0',
'munch>=2.0.2, <3.0',
'wrapt>=1.0, <2.0'
'wrapt>=1.0, <2.0',
'py-cpuinfo>=4.0'
],
tests_require=[
'mock>=0.8, <3.0',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py27, py34, py35, flake8
envlist = py27, py35, py36, flake8
# py32 does not work because of the 'wrapt' dependency
# py33 is not supported by newer versions of numpy

Expand Down

0 comments on commit e347f6d

Please sign in to comment.