"pegen.py python" should validate the output file.
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 32/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
pegen/build.py から始め、特に build_python_generator と build_python_parser_and_generator を確認してください。生成された parser の出力がどのように生成・検証されるかを追跡し、検証に失敗した場合は既存の出力ファイルを保持し、検証に成功した後でのみ正常な出力が書き込まれることを確認してください。すでに進行中の作業については、リンクされた PR gh-101937 を確認してください。
索引モデルが issue の本文から書いたものです。
説明
I ran pegen python -o grammar_parser.py after making an incorrect change to metagrammar.gram. This was invoked by make regen-pegen-metaparser, or build.bat --regen on Windows.
The resulting output file was syntactically correct, but it could not correctly parse the metagrammar file. So when I ran the make again later, it failed. The call to GeneratedParser.start() raised an exception.
The previous (correctly working) version of grammar_parser.py is now lost, unless I could get it back from Git.
Desired behavior
pegen must be sure that the newly generated output file will work correctly, before writing it out to the filesystem.
Generation of the output file begins in pegen/build.py,
def build_python_generator(
grammar: Grammar,
grammar_file: str,
output_file: str,
skip_actions: bool = False,
) -> ParserGenerator:
with open(output_file, "w") as file:
gen: ParserGenerator = PythonParserGenerator(grammar, file) # TODO: skip_actions
gen.generate(grammar_file)
return gen
This creates a new output file. Even if the body of the with raises an exception, the output file is closed and remains in the filesystem, overwriting the previous version.
Instead,
- Use a
StringIOas the file, instead of a realopen()file. Call itresult. - Generate the file, which fills in
result. - Validate
result(see more below). - If validation succeeds, then write the
resultto a newopen(output_file, "w"). - Otherwise, do nothing more. The file designated by
output_filewill still be intact.
Validating the output file
To validate the output file result, go through the entire process of generating result, except using
result instead of the grammar_parser module. This process is the entire code of build_python_parser_and_generator, not just the build_python_generator function.
grammar_parser is used to import the class GeneratedParser. For validation purposes, exec(result) with an empty globals/locals dict, then use the ['GeneratedParser'] item. Note, in build.py, this class is imported as the name GrammarParser.
This process should generate a new_result StringIO, and it should be identical to result. Perhaps there may be some insignificant differences between the two, and if so, they shouldn't be compared.
If the generation of new_result raises an exception, then the validation has failed.
Linked PRs
- gh-101937
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
🐛 Bug 🔔 Pending processing
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
modelscope/DiffSynth-Studio#1702 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·