diff --git a/.github/workflows/dependencies_check.yml b/.github/workflows/dependencies_check.yml new file mode 100644 index 00000000..54930af8 --- /dev/null +++ b/.github/workflows/dependencies_check.yml @@ -0,0 +1,27 @@ +--- +name: Dependencies Check +on: + pull_request: + types: + - opened + - reopened + - synchronize + paths: + - pyproject.toml + - requirements.txt + - scripts/check_deps.py + +jobs: + test: + name: Check dependencies sync between pyproject.toml and requirements.txt + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@master + - name: Set up Python 3.13 + uses: actions/setup-python@v4 + with: + python-version: 3.13 + - name: Install dependencies + run: python -m pip install --upgrade tomli + - name: Run script + run: python3 bin/check_deps.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c7ef78c..868696dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## \[Unreleased\] -- Nothing yet. +### Fixed + +- Updated pyproject.toml dependencies. Thanks, @kkorlyak ([#244](https://github.com/amplify-education/python-hcl2/pull/244)) ## \[7.3.0\] - 2025-07-23 diff --git a/bin/check_deps.py b/bin/check_deps.py new file mode 100644 index 00000000..55e7e098 --- /dev/null +++ b/bin/check_deps.py @@ -0,0 +1,54 @@ +"""Used by dependencies_check.yml to verify if dependencies between pyproject.yml and requirements.txt are in sync""" +import sys +from typing import Set +import difflib +import tomli + + +def get_pyproject_deps() -> Set[str]: + with open("pyproject.toml", "rb") as f: + pyproject_data = tomli.load(f) + return set(pyproject_data.get("project", {}).get("dependencies", set())) + + +def get_requirements_deps() -> Set[str]: + result = set() + with open("requirements.txt", "r") as f: + for line in f: + line = line.strip() + if line and not line.startswith("#"): + result.add(line) + return result + + +def main(): + + pyproject_deps = get_pyproject_deps() + requirements_deps = get_requirements_deps() + + pyproject_lines = list(sorted(pyproject_deps)) + + if pyproject_deps == requirements_deps: + print("All dependencies are in sync:") + for line in pyproject_lines: + print(line) + sys.exit(0) + + print("Failed, dependencies mismatch:") + requirements_lines = list(sorted(requirements_deps)) + + diff = difflib.unified_diff( + pyproject_lines, + requirements_lines, + fromfile="pyproject.toml", + tofile="requirements.txt", + lineterm="", + ) + for line in diff: + print(line) + + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index e4d3baf9..4440461a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,11 @@ classifiers = [ "Programming Language :: Python :: 3.13", ] requires-python = ">=3.7.0" -dependencies = ["lark>=1,<2"] + +dependencies = [ + "lark>=1.1.5,<2.0", + "regex>=2024.4.16" +] dynamic = ["version"] [project.readme]