From e4fd690a3d73fb9abd7ffd993145b8c5366b7d1c Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Wed, 7 Oct 2026 10:39:11 +0100 Subject: [PATCH] fix: skip workspace version warning outside a workspace (no config/) check_version defaults workspace_root to the cwd and runs on every import of autofit/autogalaxy/autolens, so a plain script run from a data directory warned "Cannot verify the workspace ...". In the no-floor branch, return silently when the directory has no config/ (new _looks_like_workspace) as well as for source checkouts. A config/ with no version keys still warns. No walk-up to a parent directory. Reported by @HRSAstro in PyAutoLabs Discussion #13. Closes #191. Co-Authored-By: Claude Fable 5.1 --- autonerves/workspace.py | 34 +++++++++++++++++++++++++------ test_autonerves/test_workspace.py | 19 +++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/autonerves/workspace.py b/autonerves/workspace.py index 34fa932..f9881f5 100644 --- a/autonerves/workspace.py +++ b/autonerves/workspace.py @@ -107,10 +107,30 @@ def _is_source_checkout(root): false positive, since a source checkout is not a workspace and records no version floor to verify. Workspace clones ship neither file, so a genuine workspace missing its version keys still warns. + + The companion skip for directories that are not a workspace at all (a + plain data directory a user runs a script from) is + ``_looks_like_workspace``. """ return (root / "setup.py").exists() or (root / "pyproject.toml").exists() +def _looks_like_workspace(root): + """ + True when ``root`` has a ``config/`` directory, which every PyAuto + workspace ships. + + ``check_version`` defaults ``workspace_root`` to the current working + directory, so a plain script run from a data directory would otherwise + warn "Cannot verify the workspace ..." on every library import even + though no workspace is involved. Only the directory itself is inspected + -- there is deliberately no walk-up to a parent, which could pick up an + unrelated ``config/`` -- so a workspace script run from a subdirectory + is also treated as outside a workspace (silent, floor unchecked). + """ + return (root / "config").is_dir() + + def _library_name_from_workspace(workspace_root): name = workspace_root.name suffix = "_workspace" @@ -196,11 +216,13 @@ def check_version(library_version, workspace_root=None): Versions that cannot be parsed as date versions (e.g. development installs) warn on inequality rather than raising. - If no floor source is found, a warning is emitted and the check is - skipped — unless ``workspace_root`` is a package source checkout - (``setup.py``/``pyproject.toml`` at its top level), in which case the - check is skipped silently: running from inside a library's own repo is - not a workspace-compatibility question at all. + If no floor source is found, the check is skipped. It is skipped + silently when ``workspace_root`` is not a workspace at all: either a + package source checkout (``setup.py``/``pyproject.toml`` at its top + level — running from inside a library's own repo) or a directory with + no ``config/`` (e.g. a plain data directory a user runs a script from). + Otherwise — a ``config/`` directory with no version keys and no + ``version.txt``, i.e. a misconfigured workspace — a warning is emitted. The check can be disabled in two ways: @@ -235,7 +257,7 @@ def check_version(library_version, workspace_root=None): floor_version = version_file.read_text().strip() if floor_version is None or floor_version == "": - if _is_source_checkout(root): + if _is_source_checkout(root) or not _looks_like_workspace(root): return _warn_once(_missing_version_warning(root, library_version)) return diff --git a/test_autonerves/test_workspace.py b/test_autonerves/test_workspace.py index 0106181..35b9251 100644 --- a/test_autonerves/test_workspace.py +++ b/test_autonerves/test_workspace.py @@ -29,10 +29,29 @@ def test_mismatch_via_version_txt_raises(tmp_path): def test_missing_sources_warns(tmp_path): + (tmp_path / "config").mkdir() with pytest.warns(UserWarning, match="workspace_version_check: False"): check_version("2026.7.22.1", workspace_root=tmp_path) +def test_missing_sources_without_config_dir_is_silent(tmp_path): + """A plain directory with no ``config/`` (e.g. a data directory a user + runs a script from) is not a workspace -- importing a library from there + must not warn that the "workspace" version cannot be verified.""" + with warnings.catch_warnings(): + warnings.simplefilter("error") + check_version("2026.7.22.1", workspace_root=tmp_path) + + +def test_config_dir_without_general_yaml_or_version_txt_warns(tmp_path): + """A ``config/`` directory marks a workspace; one with no version floor + anywhere is misconfigured and still warns.""" + (tmp_path / "config").mkdir() + (tmp_path / "config" / "visualize.yaml").write_text("") + with pytest.warns(UserWarning, match="Cannot verify the workspace"): + check_version("2026.7.22.1", workspace_root=tmp_path) + + @pytest.mark.parametrize("marker", ["setup.py", "pyproject.toml"]) def test_missing_sources_in_source_checkout_skips_silently(tmp_path, marker): """A package source checkout (setup.py/pyproject.toml at the root) is not