|
16 | 16 | import os
|
17 | 17 | import re
|
18 | 18 | import sys
|
| 19 | +from pathlib import Path |
19 | 20 | from typing import Optional, Union
|
20 | 21 |
|
21 | 22 | import fire
|
22 | 23 | from packaging.version import parse
|
23 | 24 |
|
24 | 25 | _REQUEST_TIMEOUT = 10
|
25 |
| -_PATH_ROOT = os.path.dirname(os.path.dirname(__file__)) |
| 26 | +_PATH_REPO_ROOT = Path(__file__).resolve().parent.parent |
| 27 | +_PATH_DIR_TESTS = _PATH_REPO_ROOT / "tests" |
26 | 28 | _PKG_WIDE_SUBPACKAGES = ("utilities", "helpers")
|
27 | 29 | LUT_PYTHON_TORCH = {
|
28 | 30 | "3.8": "1.4",
|
29 | 31 | "3.9": "1.7.1",
|
30 | 32 | "3.10": "1.11",
|
31 | 33 | "3.11": "1.13",
|
32 | 34 | }
|
33 |
| -_path_root = lambda *ds: os.path.join(_PATH_ROOT, *ds) |
| 35 | +_path_root = lambda *ds: os.path.join(_PATH_REPO_ROOT, *ds) |
34 | 36 | REQUIREMENTS_FILES = (*glob.glob(_path_root("requirements", "*.txt")), _path_root("requirements.txt"))
|
35 | 37 |
|
36 | 38 |
|
@@ -190,10 +192,17 @@ def _crop_path(fname: str, paths: tuple[str] = ("src/torchmetrics/", "tests/unit
|
190 | 192 | if as_list: # keep only unique
|
191 | 193 | return list(test_modules)
|
192 | 194 |
|
193 |
| - test_modules = [f"unittests/{md}" for md in set(test_modules)] |
194 |
| - not_exists = [p for p in test_modules if os.path.exists(p)] |
| 195 | + test_modules = [os.path.join("unittests", fp) for fp in set(test_modules)] |
| 196 | + # filter only existing modules |
| 197 | + not_exists = [fp for fp in test_modules if not (_PATH_DIR_TESTS / fp).exists()] |
195 | 198 | if not_exists:
|
196 |
| - raise ValueError(f"Missing following paths: {not_exists}") |
| 199 | + logging.debug(f"Missing following paths: {not_exists}") |
| 200 | + # filter only existing path in repo |
| 201 | + test_modules = [fp for fp in test_modules if (_PATH_DIR_TESTS / fp).exists()] |
| 202 | + if not test_modules: |
| 203 | + logging.debug("No tests were changed -> rather test everything...") |
| 204 | + return _return_all |
| 205 | + |
197 | 206 | return " ".join(test_modules)
|
198 | 207 |
|
199 | 208 | @staticmethod
|
|
0 commit comments