bpo-45866: pegen strips directory of "generated from" header#29777
bpo-45866: pegen strips directory of "generated from" header#29777vstinner merged 1 commit intopython:mainfrom vstinner:pegen_basename
Conversation
|
cc @pablogsal |
"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.
|
For the record, this fixes the minor problem of the dirty working tree when the files are regenerated from out-of-tree, but it does not fix the |
| def generate(self, filename: str) -> None: | ||
| self.collect_rules() | ||
| self.print(f"// @generated by pegen from {filename}") | ||
| basename = os.path.basename(filename) |
There was a problem hiding this comment.
Can we use pathlib instead of os.path?
from pathlib import Path
# [...]
basename = Path(filename).nameThere was a problem hiding this comment.
pathlib has a much more complex import tree and relies on more modules. os.path has the benefit that it works with a minimal interpreter at an early stage of the bootstrapping process.
There was a problem hiding this comment.
Yes, pathlib can be used, but I prefer os.path :-) For this specific change, I don't think that pathlib is much better.
| 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) |
Right, I prefer to write a separated change for the other issue. |
|
LGTM I liked that the file shows the full path so people can easily find the file, but I understand the downside so I am ok with this PR |
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10. |
|
Sorry, @vstinner, I could not cleanly backport this to |
|
GH-29792 is a backport of this pull request to the 3.10 branch. |
…H-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.
"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.
https://bugs.python.org/issue45866