Skip to content

Commit e5debcf

Browse files
add github PR check for dependencies sync
1 parent 128aaee commit e5debcf

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Dependencies Check
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
paths:
10+
- pyproject.toml
11+
- requirements.txt
12+
- scripts/check_deps.py # Include the script itself
13+
14+
15+
jobs:
16+
test:
17+
name: Check dependencies sync between pyproject.toml and requirements.txt
18+
runs-on: ubuntu-22.04
19+
steps:
20+
- uses: actions/checkout@master
21+
- name: Set up Python 3.13
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: 3.13
25+
- name: Install dependencies
26+
run: python -m pip install --upgrade tomli
27+
- name: Run script
28+
run: python3 bin/check_deps.py

bin/check_deps.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import sys
2+
from typing import Set
3+
import difflib
4+
import tomli
5+
6+
7+
def get_pyproject_deps() -> Set[str]:
8+
with open("pyproject.toml", "rb") as f:
9+
pyproject_data = tomli.load(f)
10+
return set(pyproject_data.get("project", {}).get("dependencies", set()))
11+
12+
13+
def get_requirements_deps() -> Set[str]:
14+
result = set()
15+
with open("requirements.txt", "r") as f:
16+
for line in f:
17+
line = line.strip()
18+
if line and not line.startswith("#"):
19+
result.add(line)
20+
return result
21+
22+
23+
def main():
24+
25+
pyproject_deps = get_pyproject_deps()
26+
requirements_deps = get_requirements_deps()
27+
28+
pyproject_lines = [dep for dep in sorted(pyproject_deps)]
29+
30+
if pyproject_deps == requirements_deps:
31+
print("All dependencies are in sync:")
32+
for line in pyproject_lines:
33+
print(line)
34+
sys.exit(0)
35+
36+
print("Failed, dependencies mismatch:")
37+
requirements_lines = [dep for dep in sorted(requirements_deps)]
38+
39+
diff = difflib.unified_diff(
40+
pyproject_lines,
41+
requirements_lines,
42+
fromfile="pyproject.toml",
43+
tofile="requirements.txt",
44+
lineterm="",
45+
)
46+
for line in diff:
47+
print(line)
48+
49+
sys.exit(1)
50+
51+
52+
if __name__ == "__main__":
53+
main()

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ classifiers = [
2525
"Programming Language :: Python :: 3.13",
2626
]
2727
requires-python = ">=3.7.0"
28-
dependencies = ["lark>=1,<2"]
28+
29+
dependencies = [
30+
"lark>=1.1.5,<2.0",
31+
"regex>=2024.4.16"
32+
]
2933
dynamic = ["version"]
3034

3135
[project.readme]

0 commit comments

Comments
 (0)