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

@ -0,0 +1,4 @@
``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.
pegen now strips directory of the "generated by pygen from <FILENAME" header
Patch by Victor Stinner.

View File

@ -1,4 +1,4 @@
// @generated by pegen from ./Grammar/python.gram // @generated by pegen from python.gram
#include "pegen.h" #include "pegen.h"
#if defined(Py_DEBUG) && defined(Py_BUILD_CORE) #if defined(Py_DEBUG) && defined(Py_BUILD_CORE)

View File

@ -1,4 +1,5 @@
import ast import ast
import os.path
import re import re
from dataclasses import dataclass, field from dataclasses import dataclass, field
from enum import Enum from enum import Enum
@ -416,7 +417,8 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
def generate(self, filename: str) -> None: def generate(self, filename: str) -> None:
self.collect_rules() self.collect_rules()
self.print(f"// @generated by pegen from {filename}") basename = os.path.basename(filename)
self.print(f"// @generated by pegen from {basename}")
header = self.grammar.metas.get("header", EXTENSION_PREFIX) header = self.grammar.metas.get("header", EXTENSION_PREFIX)
if header: if header:
self.print(header.rstrip("\n")) self.print(header.rstrip("\n"))

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3.8 #!/usr/bin/env python3.8
# @generated by pegen from ./Tools/peg_generator/pegen/metagrammar.gram # @generated by pegen from metagrammar.gram
import ast import ast
import sys import sys

View File

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