From f0bfb4f282782d9a844bfe5dd50387de3f984645 Mon Sep 17 00:00:00 2001 From: Dmitry Duev Date: Thu, 10 Nov 2022 11:49:21 -0800 Subject: [PATCH 1/9] test(sdk): add tests for protobuf version compatibility --- .circleci/config.yml | 38 +++++++- requirements.txt | 3 +- tools/check_protobuf_version_compatibility.py | 86 +++++++++++++++++++ 3 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 tools/check_protobuf_version_compatibility.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 97c2e36d49d..eace2dbcafd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -363,6 +363,31 @@ jobs: ./wandb.pex -c "import wandb; wandb.init(mode='offline'); wandb.finish()" - save-test-results + protobuf-compatability: + parameters: + python_version_major: + type: integer + default: 3 + python_version_minor: + type: integer + default: 8 + docker: + - image: "python:<>.<>" + resource_class: small + working_directory: /mnt/ramdisk + steps: + - checkout + - run: + name: Install system deps + command: | + apt-get update && apt-get install -y libsndfile1 ffmpeg + - run: + name: Check protobuf version compatibility + command: | + python tools/check_protobuf_version_compatibility.py + no_output_timeout: 5m + - save-test-results + win: parameters: python_version_major: @@ -1290,6 +1315,16 @@ workflows: # - pex: name: "pex" + # + # protobuf compatibility tests + # + - protobuf-compatability: + matrix: + parameters: + python_version_major: [ 3 ] + python_version_minor: [ 7, 8, 9, 10 ] + name: "protobuf-compatability-py<><>" + # todo: needs love # manual_test: @@ -1387,8 +1422,7 @@ workflows: - pip_install_wandb: matrix: parameters: - # todo: replace 3.11-rc with 3.11 when it's released on 2022-10-24 - python_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11-rc"] + python_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] context: slack-secrets notify_on_failure: << pipeline.parameters.manual_nightly_slack_notify >> requires: diff --git a/requirements.txt b/requirements.txt index 8adb09f58e7..5021a0e9545 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,8 @@ psutil>=5.0.0 sentry-sdk>=1.0.0 six>=1.13.0 docker-pycreds>=0.4.0 -protobuf>=3.12.0,!=4.0.*,!=4.21.0,<5 +protobuf>=3.12.0,!=4.21.0,<5 +protobuf>=3.19.0,!=4.21.0,<5; sys_platform == 'darwin' and platform.machine == 'arm64' PyYAML pathtools # supports vendored version of watchdog 0.9.0 setproctitle diff --git a/tools/check_protobuf_version_compatibility.py b/tools/check_protobuf_version_compatibility.py new file mode 100644 index 00000000000..fccc868fdb3 --- /dev/null +++ b/tools/check_protobuf_version_compatibility.py @@ -0,0 +1,86 @@ +import pathlib +import subprocess +import sys +from typing import List, Tuple + +from pkg_resources import parse_version + + +def get_available_protobuf_versions() -> List[str]: + """Get a list of available protobuf versions.""" + try: + output = subprocess.check_output( + ["pip", "index", "versions", "protobuf"], + ).decode("utf-8") + versions = list({o for o in output.split() if o[0].isnumeric()}) + versions = [v if not v.endswith(",") else v[:-1] for v in versions] + return sorted(versions) + except subprocess.CalledProcessError: + return [] + + +def parse_protobuf_requirements() -> List[Tuple[str, str]]: + """Parse protobuf requirements from a requirements.txt file.""" + path_requirements = pathlib.Path(__file__).parent.parent / "requirements.txt" + with open(path_requirements) as f: + requirements = f.readlines() + + protobuf_reqs = [] + for line in requirements: + if line.startswith("protobuf"): + reqs = line.strip().split("protobuf")[1].split(",") + for req in reqs: + for i, char in enumerate(req): + if char.isnumeric(): + protobuf_reqs.append( + ( + req[:i].strip(), + req[i:].strip(), + ) + ) + break + + return protobuf_reqs + + +def get_matching_versions( + available_protobuf_vs: List[str], protobuf_reqs: List[Tuple[str, str]] +) -> List[str]: + matching_vs = [] + for v in available_protobuf_vs: + if all( + eval(f"parse_version('{v}') {rq[0]} parse_version('{rq[1]}')") + for rq in protobuf_reqs + ): + matching_vs.append(v) + + return sorted(list(set(matching_vs))) + + +def attempt_install_protobuf_version(version: str) -> bool: + try: + subprocess.check_call(["pip", "install", f"protobuf=={version}"]) + subprocess.check_call(["python", "-c", "import wandb"]) + return True + except subprocess.CalledProcessError: + return False + + +if __name__ == "__main__": + available_protobuf_versions = get_available_protobuf_versions() + protobuf_requirements = parse_protobuf_requirements() + matching_versions = get_matching_versions( + available_protobuf_versions, + protobuf_requirements, + ) + + version_compatibility = { + version: attempt_install_protobuf_version(version) + for version in matching_versions + } + + for version, compatible in version_compatibility.items(): + print(f"protobuf=={version}: {compatible}") + + if not all(version_compatibility.values()): + sys.exit(1) From 2a5382a7b1e7a26601fdc761d826ed77e71012aa Mon Sep 17 00:00:00 2001 From: Dmitry Duev Date: Thu, 10 Nov 2022 12:04:49 -0800 Subject: [PATCH 2/9] test(sdk): add tests for protobuf version compatibility --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5021a0e9545..0984d7e570f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ sentry-sdk>=1.0.0 six>=1.13.0 docker-pycreds>=0.4.0 protobuf>=3.12.0,!=4.21.0,<5 -protobuf>=3.19.0,!=4.21.0,<5; sys_platform == 'darwin' and platform.machine == 'arm64' PyYAML pathtools # supports vendored version of watchdog 0.9.0 setproctitle From 34fd1dfb35669affc6c93a5ed98476ef3d90120a Mon Sep 17 00:00:00 2001 From: Dmitry Duev Date: Thu, 10 Nov 2022 12:07:03 -0800 Subject: [PATCH 3/9] test(sdk): add tests for protobuf version compatibility --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index eace2dbcafd..66a0ef31440 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -384,6 +384,8 @@ jobs: - run: name: Check protobuf version compatibility command: | + pip install -U pip + pip install . python tools/check_protobuf_version_compatibility.py no_output_timeout: 5m - save-test-results From fefbc931f02a5660c9af278f8a1991d707541a49 Mon Sep 17 00:00:00 2001 From: Dmitry Duev Date: Mon, 14 Nov 2022 23:40:40 -0800 Subject: [PATCH 4/9] system requirements --- requirements.txt | 3 +- ...> check-protobuf-version-compatibility.py} | 52 ++++++++++++++++++- 2 files changed, 52 insertions(+), 3 deletions(-) rename tools/{check_protobuf_version_compatibility.py => check-protobuf-version-compatibility.py} (57%) diff --git a/requirements.txt b/requirements.txt index 0984d7e570f..e70bfc02c45 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,8 @@ psutil>=5.0.0 sentry-sdk>=1.0.0 six>=1.13.0 docker-pycreds>=0.4.0 -protobuf>=3.12.0,!=4.21.0,<5 +protobuf>=3.12.0,!=4.21.0,<5; python_version < '3.9' and sys_platform == 'linux' +protobuf>=3.19.0,!=4.21.0,<5; python_version >= '3.9' PyYAML pathtools # supports vendored version of watchdog 0.9.0 setproctitle diff --git a/tools/check_protobuf_version_compatibility.py b/tools/check-protobuf-version-compatibility.py similarity index 57% rename from tools/check_protobuf_version_compatibility.py rename to tools/check-protobuf-version-compatibility.py index fccc868fdb3..c74c62959da 100644 --- a/tools/check_protobuf_version_compatibility.py +++ b/tools/check-protobuf-version-compatibility.py @@ -1,4 +1,6 @@ import pathlib +import platform +import re import subprocess import sys from typing import List, Tuple @@ -25,10 +27,56 @@ def parse_protobuf_requirements() -> List[Tuple[str, str]]: with open(path_requirements) as f: requirements = f.readlines() + system_python_version = f"{sys.version_info.major}.{sys.version_info.minor}" + system_platform = sys.platform + system_machine = platform.machine() + protobuf_reqs = [] for line in requirements: if line.startswith("protobuf"): - reqs = line.strip().split("protobuf")[1].split(",") + version_reqs = line.strip().split(";")[0] + + # first, check the system requirements + system_reqs = line.strip().split(";")[1] + # regex to find quoted python version in system_reqs + python_version = re.search( + r"python_version\s+([<>=!]+)\s+[',\"]([2,3]*[.][0-9]+)[',\"]", + system_reqs, + ) + if python_version is not None: + version_check = ( + f"parse_version('{system_python_version}') " + f"{python_version.group(1)} " + f"parse_version('{python_version.group(2)}')" + ) + if not eval(version_check): + continue + # regex to find quoted platform in system_reqs + platform_reqs = re.search( + r"sys_platform\s+([<>=!]+)\s+[',\"]([a-z]+)[',\"]", + system_reqs, + ) + + if platform_reqs is not None: + if not eval( + f"'{system_platform}' {platform_reqs.group(1)} '{platform_reqs.group(2)}'" + ): + continue + + # regex to find platform machine in system_reqs + platform_machine = re.search( + r"platform[.]machine\s+([<>=!]+)\s+[',\"]([a-z]+)[',\"]", + system_reqs, + ) + if platform_machine is not None: + if not eval( + f"'{system_machine}' {platform_machine.group(1)} '{platform_machine.group(2)}'" + ): + continue + + # finally, parse the protobuf version requirements + reqs = version_reqs.split("protobuf")[1].split(",") + print(reqs) for req in reqs: for i, char in enumerate(req): if char.isnumeric(): @@ -39,7 +87,7 @@ def parse_protobuf_requirements() -> List[Tuple[str, str]]: ) ) break - + print(protobuf_reqs) return protobuf_reqs From a1c85ede2353eba4837c4ab5122e9ded48aa0963 Mon Sep 17 00:00:00 2001 From: Dmitry Duev Date: Mon, 14 Nov 2022 23:43:52 -0800 Subject: [PATCH 5/9] system requirements --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e70bfc02c45..3d7f3036470 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ psutil>=5.0.0 sentry-sdk>=1.0.0 six>=1.13.0 docker-pycreds>=0.4.0 -protobuf>=3.12.0,!=4.21.0,<5; python_version < '3.9' and sys_platform == 'linux' +protobuf>=3.12.0,!=4.21.0,<5; python_version < '3.9' protobuf>=3.19.0,!=4.21.0,<5; python_version >= '3.9' PyYAML pathtools # supports vendored version of watchdog 0.9.0 From ffecf087636430fb4fcc909b833f5640724e78ce Mon Sep 17 00:00:00 2001 From: Dmitry Duev Date: Mon, 14 Nov 2022 23:52:21 -0800 Subject: [PATCH 6/9] lint --- tools/check-protobuf-version-compatibility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/check-protobuf-version-compatibility.py b/tools/check-protobuf-version-compatibility.py index c74c62959da..04a2991e5ab 100644 --- a/tools/check-protobuf-version-compatibility.py +++ b/tools/check-protobuf-version-compatibility.py @@ -5,7 +5,7 @@ import sys from typing import List, Tuple -from pkg_resources import parse_version +from pkg_resources import parse_version # noqa: F401 def get_available_protobuf_versions() -> List[str]: From d312e621f09334f9027c9105ea60d8f7811d0e2b Mon Sep 17 00:00:00 2001 From: Dmitry Duev Date: Mon, 14 Nov 2022 23:53:12 -0800 Subject: [PATCH 7/9] system requirements --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 74c4ad55419..903d20f1c87 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -389,7 +389,7 @@ jobs: command: | pip install -U pip pip install . - python tools/check_protobuf_version_compatibility.py + python tools/check-protobuf-version-compatibility.py no_output_timeout: 5m - save-test-results From 9c96954e3b2c4af224e604d1b051f5716affc658 Mon Sep 17 00:00:00 2001 From: Dmitry Duev Date: Mon, 14 Nov 2022 23:58:32 -0800 Subject: [PATCH 8/9] adjust requirements --- requirements.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 3d7f3036470..342612531a8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,8 +7,10 @@ psutil>=5.0.0 sentry-sdk>=1.0.0 six>=1.13.0 docker-pycreds>=0.4.0 -protobuf>=3.12.0,!=4.21.0,<5; python_version < '3.9' -protobuf>=3.19.0,!=4.21.0,<5; python_version >= '3.9' +protobuf>=3.12.0,!=4.21.0,<5; python_version < '3.9' and sys_platform == 'linux' +protobuf>=3.15.0,!=4.21.0,<5; python_version == '3.9' and sys_platform == 'linux' +protobuf>=3.19.0,!=4.21.0,<5; python_version > '3.9' and sys_platform == 'linux' +protobuf>=3.19.0,!=4.21.0,<5; sys_platform != 'linux' PyYAML pathtools # supports vendored version of watchdog 0.9.0 setproctitle From 11227b9efc5d4c76d67b36bf43b50cdaff9feeca Mon Sep 17 00:00:00 2001 From: Dmitry Duev Date: Tue, 15 Nov 2022 00:01:55 -0800 Subject: [PATCH 9/9] move tests to nightly --- .circleci/config.yml | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 903d20f1c87..747ff2fbc21 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1089,6 +1089,15 @@ workflows: notify_on_failure: true notify_on_failure_channel: $SLACK_SDK_NIGHTLY_CI_GROWTH_CHANNEL # + # protobuf compatibility tests + # + - protobuf-compatability: + matrix: + parameters: + python_version_major: [ 3 ] + python_version_minor: [ 7, 8, 9, 10 ] + name: "protobuf-compatability-py<><>" + # # standalone GPU tests on Windows # - win: @@ -1332,15 +1341,6 @@ workflows: # - pex: name: "pex" - # - # protobuf compatibility tests - # - - protobuf-compatability: - matrix: - parameters: - python_version_major: [ 3 ] - python_version_minor: [ 7, 8, 9, 10 ] - name: "protobuf-compatability-py<><>" # todo: needs love @@ -1412,6 +1412,15 @@ workflows: notify_on_failure: true notify_on_failure_channel: $SLACK_SDK_NIGHTLY_CI_GROWTH_CHANNEL # + # protobuf compatibility tests + # + - protobuf-compatability: + matrix: + parameters: + python_version_major: [ 3 ] + python_version_minor: [ 7, 8, 9, 10 ] + name: "protobuf-compatability-py<><>" + # # standalone GPU tests on Windows # - win: