Skip to content

Commit 1676485

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

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
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

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## \[Unreleased\]
99

10-
- Nothing yet.
10+
### Fixed
11+
12+
- Updated pyproject.toml dependencies. Thanks, @kkorlyak ([#244](https://github.com/amplify-education/python-hcl2/pull/244))
1113

1214
## \[7.3.0\] - 2025-07-23
1315

bin/check_deps.py

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