bpo-45866: pegen strips directory of "generated from" header (GH-29777)

"make regen-all" now produces the same output when run from a
directory other than the source tree: when building Python out of the
source tree.
This commit is contained in:
Victor Stinner 2021-11-26 11:50:34 +01:00 committed by GitHub
parent ee1e2c604c
commit 253b7a0a9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 4 deletions

View file

@ -1,3 +1,4 @@
import os.path
import token
from typing import IO, Any, Dict, Optional, Sequence, Set, Text, Tuple
@ -212,7 +213,8 @@ class PythonParserGenerator(ParserGenerator, GrammarVisitor):
self.collect_rules()
header = self.grammar.metas.get("header", MODULE_PREFIX)
if header is not None:
self.print(header.rstrip("\n").format(filename=filename))
basename = os.path.basename(filename)
self.print(header.rstrip("\n").format(filename=basename))
subheader = self.grammar.metas.get("subheader", "")
if subheader:
self.print(subheader)