1818PYPI_JSON_TIMEOUT_SECONDS = 20
1919POLICYENGINE_US = "policyengine-us"
2020STALE_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
2325def _annotation (level : str , message : str ) -> str :
@@ -86,6 +88,8 @@ def _latest_pypi_version() -> str:
8688def 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+
123140def 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
0 commit comments