Skip to content

Commit 9fe973e

Browse files
chore(internal): add bin script (#238)
1 parent 490fd17 commit 9fe973e

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

bin/check-env-state.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Script that exits 1 if the current environment is not
2+
in sync with the `requirements-dev.lock` file.
3+
"""
4+
5+
from pathlib import Path
6+
7+
import importlib_metadata
8+
9+
10+
def should_run_sync() -> bool:
11+
dev_lock = Path(__file__).parent.parent.joinpath("requirements-dev.lock")
12+
13+
for line in dev_lock.read_text().splitlines():
14+
if not line or line.startswith("#") or line.startswith("-e"):
15+
continue
16+
17+
dep, lock_version = line.split("==")
18+
19+
try:
20+
version = importlib_metadata.version(dep)
21+
22+
if lock_version != version:
23+
print(f"mismatch for {dep} current={version} lock={lock_version}")
24+
return True
25+
except Exception:
26+
print(f"could not import {dep}")
27+
return True
28+
29+
return False
30+
31+
32+
def main() -> None:
33+
if should_run_sync():
34+
exit(1)
35+
else:
36+
exit(0)
37+
38+
39+
if __name__ == "__main__":
40+
main()

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dev-dependencies = [
5858
"time-machine",
5959
"nox",
6060
"dirty-equals>=0.6.0",
61+
"importlib-metadata>=6.7.0",
6162

6263
]
6364

requirements-dev.lock

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ h11==0.14.0
2424
httpcore==1.0.2
2525
httpx==0.25.2
2626
idna==3.4
27+
importlib-metadata==7.0.0
2728
iniconfig==2.0.0
2829
isort==5.10.1
2930
mypy==1.7.1
@@ -50,5 +51,6 @@ time-machine==2.9.0
5051
tomli==2.0.1
5152
typing-extensions==4.8.0
5253
virtualenv==20.24.5
54+
zipp==3.17.0
5355
# The following packages are considered to be unsafe in a requirements file:
5456
setuptools==68.2.2

0 commit comments

Comments
 (0)