-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-45866: pegen strips directory of "generated from" header #29777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
@@ -416,7 +417,8 @@ def out_of_memory_goto(self, expr: str, goto_target: str) -> None: | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use pathlib instead of os.path?
from pathlib import Path
# [...]
basename = Path(filename).name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, pathlib can be used, but I prefer os.path :-) For this specific change, I don't think that pathlib is much better.
@@ -212,7 +213,8 @@ def generate(self, filename: str) -> None: | |||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
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