Skip to content

Commit 28b169a

Browse files
authored
Repository version files now define a minimum (#26)
1 parent 4e851d6 commit 28b169a

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
## Unreleased
1010

11+
***Fixed:***
12+
13+
- Repository-specific version files (`.deva-version` or `.deva/version`) now define the minimum required version rather than the exact version
14+
1115
## 0.4.1 - 2025-01-18
1216

1317
***Fixed:***

src/deva/cli/__init__.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,18 @@ def deva(
153153
cwd = Path.cwd()
154154
if (version_file := cwd / ".deva-version").is_file() or (version_file := cwd / ".deva" / "version").is_file():
155155
pinned_version = version_file.read_text().strip()
156-
if pinned_version != __version__:
157-
app.abort(f"deva version mismatch: {__version__} != {pinned_version}")
156+
pinned_version_parts = list(map(int, pinned_version.split(".")))
157+
# Limit to X.Y.Z in case of dev versions e.g. 1.2.3.dev1
158+
current_version_parts = list(map(int, __version__.split(".")[:3]))
159+
160+
if current_version_parts < pinned_version_parts:
161+
app.display_critical(
162+
f"Repo requires at least deva version {pinned_version} but {__version__} is installed."
163+
)
164+
if app.managed_installation:
165+
app.display("Run the following command:\ndeva self update")
166+
167+
app.abort()
158168

159169
# Persist app data for sub-commands
160170
ctx.obj = app

src/deva/cli/application.py

+4
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ def tools(self) -> Tools:
5555
@cached_property
5656
def dynamic_deps_allowed(self) -> bool:
5757
return os.getenv(AppEnvVars.NO_DYNAMIC_DEPS) not in {"1", "true"}
58+
59+
@cached_property
60+
def managed_installation(self) -> bool:
61+
return os.getenv("PYAPP") is not None

tests/cli/test_pin.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,48 @@
33
# SPDX-License-Identifier: MIT
44
from __future__ import annotations
55

6+
import pytest
7+
68
from deva._version import __version__
79

810

11+
@pytest.fixture(scope="module")
12+
def next_major_version():
13+
version_parts = list(map(int, __version__.split(".")[:3]))
14+
version_parts[0] += 1
15+
return ".".join(map(str, version_parts))
16+
17+
918
class TestVersionMismatch:
10-
def test_root(self, deva, helpers, temp_dir):
19+
def test_root(self, deva, helpers, temp_dir, next_major_version):
1120
version_file = temp_dir / ".deva-version"
1221
with temp_dir.as_cwd():
13-
version_file.write_text("0.0.0")
22+
version_file.write_text(next_major_version)
1423

1524
result = deva("config")
1625

1726
assert result.exit_code == 1, result.output
1827
assert result.output == helpers.dedent(
1928
f"""
20-
deva version mismatch: {__version__} != 0.0.0
29+
Repo requires at least deva version {next_major_version} but {__version__} is installed.
30+
Run the following command:
31+
deva self update
2132
"""
2233
)
2334

24-
def test_directory(self, deva, helpers, temp_dir):
35+
def test_directory(self, deva, helpers, temp_dir, next_major_version):
2536
version_file = temp_dir / ".deva" / "version"
2637
version_file.parent.ensure_dir()
2738
with temp_dir.as_cwd():
28-
version_file.write_text("0.0.0")
39+
version_file.write_text(next_major_version)
2940

3041
result = deva("config")
3142

3243
assert result.exit_code == 1, result.output
3344
assert result.output == helpers.dedent(
3445
f"""
35-
deva version mismatch: {__version__} != 0.0.0
46+
Repo requires at least deva version {next_major_version} but {__version__} is installed.
47+
Run the following command:
48+
deva self update
3649
"""
3750
)

tests/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def isolation() -> Generator[Path, None, None]:
6767
ConfigEnvVars.DATA: str(data_dir),
6868
ConfigEnvVars.CACHE: str(cache_dir),
6969
AppEnvVars.NO_COLOR: "1",
70+
"PYAPP": "1",
7071
"DEVA_SELF_TESTING": "true",
7172
"GIT_AUTHOR_NAME": "Foo Bar",
7273
"GIT_AUTHOR_EMAIL": "[email protected]",

0 commit comments

Comments
 (0)