Skip to content

Commit

Permalink
Add Python version to version check (#3567)
Browse files Browse the repository at this point in the history
* Add Python to version checks

* Use dict for system info
  • Loading branch information
jrbourbeau committed Mar 17, 2020
1 parent f2f82c6 commit 511427b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
17 changes: 17 additions & 0 deletions distributed/tests/test_versions.py
@@ -1,4 +1,5 @@
import re
import uuid

import pytest

Expand Down Expand Up @@ -117,3 +118,19 @@ async def test_version_warning_in_cluster(s, a, b):
assert any(
"0.0.0" in line.message and a.address in line.message for line in w.logs
)


@gen_cluster()
async def test_python_version_mismatch_warning(s, a, b):
# Set random Python version for one worker
random_version = uuid.uuid4().hex
orig = s.workers[a.address].versions["host"]["python"] = random_version

with pytest.warns(None) as record:
async with Client(s.address, asynchronous=True) as client:
pass

assert record
assert any("python" in str(r.message) for r in record)
assert any(random_version in str(r.message) for r in record)
assert any(a.address in str(r.message) for r in record)
26 changes: 14 additions & 12 deletions distributed/versions.py
Expand Up @@ -51,17 +51,17 @@ def get_versions(packages=None):

def get_system_info():
(sysname, nodename, release, version, machine, processor) = platform.uname()
host = [
("python", "%d.%d.%d.%s.%s" % sys.version_info[:]),
("python-bits", struct.calcsize("P") * 8),
("OS", "%s" % sysname),
("OS-release", "%s" % release),
("machine", "%s" % machine),
("processor", "%s" % processor),
("byteorder", "%s" % sys.byteorder),
("LC_ALL", "%s" % os.environ.get("LC_ALL", "None")),
("LANG", "%s" % os.environ.get("LANG", "None")),
]
host = {
"python": "%d.%d.%d.%s.%s" % sys.version_info[:],
"python-bits": struct.calcsize("P") * 8,
"OS": "%s" % sysname,
"OS-release": "%s" % release,
"machine": "%s" % machine,
"processor": "%s" % processor,
"byteorder": "%s" % sys.byteorder,
"LC_ALL": "%s" % os.environ.get("LC_ALL", "None"),
"LANG": "%s" % os.environ.get("LANG", "None"),
}

return host

Expand Down Expand Up @@ -113,7 +113,6 @@ def error_message(scheduler, workers, client, client_name="client"):

# Collect all package versions
packages = set()

for node, info in nodes.items():
if info is None or not (isinstance(info, dict)) or "packages" not in info:
node_packages[node] = defaultdict(lambda: "UNKNOWN")
Expand All @@ -122,6 +121,9 @@ def error_message(scheduler, workers, client, client_name="client"):
for pkg, version in info["packages"].items():
node_packages[node][pkg] = version
packages.add(pkg)
# Collect Python version for each node
node_packages[node]["python"] = info["host"]["python"]
packages.add("python")

errs = []
for pkg in sorted(packages):
Expand Down

0 comments on commit 511427b

Please sign in to comment.