openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
bin/check-env-state.py
40lines · modecode
| 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() |
| 41 | |