File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ h11==0.14.0
2424httpcore==1.0.2
2525httpx==0.25.2
2626idna==3.4
27+ importlib-metadata==7.0.0
2728iniconfig==2.0.0
2829isort==5.10.1
2930mypy==1.7.1
@@ -50,5 +51,6 @@ time-machine==2.9.0
5051tomli==2.0.1
5152typing-extensions==4.8.0
5253virtualenv==20.24.5
54+ zipp==3.17.0
5355# The following packages are considered to be unsafe in a requirements file:
5456setuptools==68.2.2
You can’t perform that action at this time.
0 commit comments