Fix Dependabot build failure in bnf package by making ANTLR generation optional - #140
Conversation
- Made antlr4 command check optional in setup.py - Fixed pyproject.toml license format to comply with PEP 621 - Package can now be built without antlr4 for dependency resolution Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
| description = "BNF parser and unparsers for DS - conversion between lisp-like and traditional syntax" | ||
| readme = "README.md" | ||
| license = "AGPL-3.0-or-later" | ||
| license = {text = "AGPL-3.0-or-later"} |
| grammars_dir = base_dir | ||
| output_dir = base_dir / "apyds_bnf" | ||
|
|
||
| # Check if antlr4 is available |
- Revert license field format change in pyproject.toml (per review) - Remove comment from setup.py (per review) - Move antlr4 check to top of function (per review) Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR attempts to fix Dependabot build failures by making ANTLR parser generation optional in the bnf package. When the antlr4 command is unavailable (e.g., in Dependabot's environment), the build process now skips parser generation with a warning instead of failing.
Key Changes
- Added conditional check using
shutil.which()to detect ifantlr4command is available - Skip parser generation with informative warning messages when ANTLR is not found
- Allows package metadata extraction without requiring full build toolchain
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if not shutil.which("antlr4"): | ||
| print("Warning: antlr4 command not found. Skipping parser generation.") | ||
| print("This is normal when resolving dependencies (e.g., with Dependabot).") | ||
| return |
There was a problem hiding this comment.
Skipping parser generation will cause runtime import errors. The package's __init__.py imports generated files like DspLexer, DspParser, DsLexer, and DsParser (lines 5-10 in apyds_bnf/init.py), which won't exist if generation is skipped. Since these generated files are excluded from git (.gitignore), the package will be non-functional when installed.
Consider one of these approaches:
- Check if generated files already exist before skipping generation, only skip if they're present
- Include pre-generated parser files in the repository and source distribution (remove from .gitignore or use MANIFEST.in)
- Use a try-except block in init.py to provide a more informative error message when parsers are missing
Dependabot was failing to resolve Python dependencies because the build required the
antlr4command, which isn't available in Dependabot's environment.Changes
bnf/setup.py: Made ANTLR parser generation optional during build. Ifantlr4command is unavailable, skip generation with a warning instead of failing. This allows dependency resolution without requiring the full build toolchain. The check is placed at the top of thegenerate_antlr_parsers()method for early return.The package can now be built for metadata extraction (what Dependabot needs) without ANTLR, while parser generation still works normally when the tool is available (CI, production builds).
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.