Skip to content

Commit 6c69223

Browse files
committed
Use unreleased policyengine-us git ref
1 parent d159567 commit 6c69223

4 files changed

Lines changed: 78 additions & 16 deletions

File tree

.github/scripts/check_policyengine_us_dependency.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
PYPI_JSON_TIMEOUT_SECONDS = 20
1919
POLICYENGINE_US = "policyengine-us"
2020
STALE_LOCK_PREFIX = "uv.lock has policyengine-us "
21+
LOCK_GIT_REF_PREFIX = "uv.lock resolves policyengine-us from a Git ref."
22+
PROJECT_GIT_REF_PREFIX = "pyproject.toml pins policyengine-us to a Git ref."
2123

2224

2325
def _annotation(level: str, message: str) -> str:
@@ -86,6 +88,8 @@ def _latest_pypi_version() -> str:
8688
def check_dependency(root: Path, latest_version: str | None = None) -> list[str]:
8789
locked_version, source = _locked_policyengine_us(root)
8890
project_dependency = _project_policyengine_us_dependency(root)
91+
lock_uses_git_ref = "git" in source
92+
project_uses_git_ref = "@" in project_dependency and "git+" in project_dependency
8993

9094
violations: list[str] = []
9195
if (
@@ -99,27 +103,40 @@ def check_dependency(root: Path, latest_version: str | None = None) -> list[str]
99103
)
100104

101105
expected_dependency = f"{POLICYENGINE_US}=={locked_version}"
102-
if project_dependency != expected_dependency:
106+
if not project_uses_git_ref and project_dependency != expected_dependency:
103107
violations.append(
104108
f"pyproject.toml must pin {expected_dependency} to match uv.lock; "
105109
f"found {project_dependency!r}."
106110
)
107111

108-
if "git" in source:
112+
if lock_uses_git_ref:
109113
violations.append(
110-
"uv.lock resolves policyengine-us from a Git ref. Prefer an exact "
114+
f"{LOCK_GIT_REF_PREFIX} Prefer an exact "
111115
f"PyPI release pin once policyengine-us {locked_version} is published."
112116
)
113117

114-
if "@" in project_dependency and "git+" in project_dependency:
118+
if project_uses_git_ref:
115119
violations.append(
116-
"pyproject.toml pins policyengine-us to a Git ref. Prefer an exact "
120+
f"{PROJECT_GIT_REF_PREFIX} Prefer an exact "
117121
"PyPI release pin for production data builds."
118122
)
119123

120124
return violations
121125

122126

127+
def _is_unreleased_git_ref_violation(
128+
violation: str,
129+
locked_version: str,
130+
latest_version: str | None,
131+
) -> bool:
132+
if latest_version is None:
133+
return False
134+
git_ref_violation = violation.startswith(
135+
LOCK_GIT_REF_PREFIX
136+
) or violation.startswith(PROJECT_GIT_REF_PREFIX)
137+
return git_ref_violation and _compare_versions(locked_version, latest_version) > 0
138+
139+
123140
def main() -> int:
124141
parser = argparse.ArgumentParser()
125142
parser.add_argument(
@@ -163,17 +180,30 @@ def main() -> int:
163180
print(f"policyengine-us dependency is current at {locked_version}.")
164181
return 0
165182

183+
locked_version, _source = _locked_policyengine_us(REPO_ROOT)
166184
has_blocking_violation = False
167185
allowed_stale_version = False
186+
allowed_unreleased_git_ref = False
168187
for violation in violations:
169188
stale_version_violation = violation.startswith(STALE_LOCK_PREFIX)
170189
allowed_by_override = allow_stale and stale_version_violation
171-
level = "warning" if args.mode == "warn" or allowed_by_override else "error"
190+
allowed_git_ref = _is_unreleased_git_ref_violation(
191+
violation,
192+
locked_version,
193+
latest_version,
194+
)
195+
level = (
196+
"warning"
197+
if args.mode == "warn" or allowed_by_override or allowed_git_ref
198+
else "error"
199+
)
172200
print(_annotation(level, violation))
173-
if args.mode == "fail" and not allowed_by_override:
201+
if args.mode == "fail" and not allowed_by_override and not allowed_git_ref:
174202
has_blocking_violation = True
175203
if allowed_by_override:
176204
allowed_stale_version = True
205+
if allowed_git_ref:
206+
allowed_unreleased_git_ref = True
177207

178208
if allowed_stale_version:
179209
print(
@@ -183,10 +213,18 @@ def main() -> int:
183213
"policyengine-us lagging the latest PyPI release.",
184214
)
185215
)
216+
if allowed_unreleased_git_ref:
217+
print(
218+
_annotation(
219+
"warning",
220+
"policyengine-us is pinned to an unreleased Git ref; switch to "
221+
f"policyengine-us=={locked_version} once that PyPI release exists.",
222+
)
223+
)
186224

187225
if has_blocking_violation:
188226
return 1
189-
if allowed_stale_version:
227+
if allowed_stale_version or allowed_unreleased_git_ref:
190228
return 0
191229

192230
return 1 if args.mode == "fail" else 0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ classifiers = [
2222
"Programming Language :: Python :: 3.14",
2323
]
2424
dependencies = [
25-
"policyengine-us==1.705.15",
25+
"policyengine-us @ git+https://github.com/PolicyEngine/policyengine-us@0dcc69aa7a38be901141d38c8dbb7a9c870f2561",
2626
# policyengine-core 3.26.1 is the current 3.26.x runtime and includes the fix for
2727
# PolicyEngine/policyengine-core#482 (user-set ETERNITY inputs lost
2828
# after _invalidate_all_caches) and is required by policyengine-us 1.682.1+.

tests/unit/test_publication_scripts.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,34 @@ def test_policyengine_us_dependency_check_flags_git_refs(tmp_path):
282282
assert any("Git ref" in violation for violation in violations)
283283

284284

285+
def test_policyengine_us_dependency_check_allows_unreleased_git_refs(
286+
tmp_path,
287+
monkeypatch,
288+
):
289+
module = _load_script(
290+
".github/scripts/check_policyengine_us_dependency.py",
291+
"check_policyengine_us_dependency_unreleased_git_test",
292+
)
293+
_write_pyproject_with_policyengine_us(
294+
tmp_path,
295+
"policyengine-us @ git+https://github.com/PolicyEngine/policyengine-us@abc",
296+
)
297+
_write_uv_lock_for_policyengine_us(
298+
tmp_path,
299+
"1.691.12",
300+
source='{ git = "https://github.com/PolicyEngine/policyengine-us?rev=abc#abc" }',
301+
)
302+
monkeypatch.setattr(module, "REPO_ROOT", tmp_path)
303+
monkeypatch.setattr(module, "_latest_pypi_version", lambda: "1.691.11")
304+
monkeypatch.setattr(
305+
sys,
306+
"argv",
307+
["check_policyengine_us_dependency.py", "--mode", "fail"],
308+
)
309+
310+
assert module.main() == 0
311+
312+
285313
def test_policyengine_us_dependency_check_flags_non_exact_pyproject_pin(tmp_path):
286314
module = _load_script(
287315
".github/scripts/check_policyengine_us_dependency.py",

uv.lock

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)