Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions autonerves/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test_autonerves/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading