Skip to content
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

bpo-45866: pegen strips directory of "generated from" header #29777

Merged
merged 1 commit into from Nov 26, 2021

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Nov 25, 2021

"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

@vstinner
Copy link
Member Author

@vstinner vstinner commented Nov 25, 2021

Loading

"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.
@hroncok
Copy link
Contributor

@hroncok hroncok commented Nov 25, 2021

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 missing _freeze_module error.

Loading

@@ -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)

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

Loading

Copy link
Member

@tiran tiran Nov 25, 2021

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.

Loading

Copy link
Member Author

@vstinner vstinner Nov 26, 2021

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.

Loading

@@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Loading

@vstinner
Copy link
Member Author

@vstinner vstinner commented Nov 26, 2021

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 missing _freeze_module error.

Right, I prefer to write a separated change for the other issue.

Loading

@pablogsal
Copy link
Member

@pablogsal pablogsal commented Nov 26, 2021

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

Loading

@vstinner vstinner merged commit 253b7a0 into python:main Nov 26, 2021
12 checks passed
Loading
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 26, 2021

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒🤖

Loading

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 26, 2021

Sorry, @vstinner, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 253b7a0a9fef1d72a4cb87b837885576e68e917c 3.10

Loading

@vstinner vstinner deleted the pegen_basename branch Nov 26, 2021
vstinner added a commit to vstinner/cpython that referenced this issue Nov 26, 2021
…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.

(cherry picked from commit 253b7a0)
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Nov 26, 2021

GH-29792 is a backport of this pull request to the 3.10 branch.

Loading

vstinner added a commit that referenced this issue Nov 26, 2021
… (GH-29792)

"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.

(cherry picked from commit 253b7a0)
vstinner added a commit to vstinner/cpython that referenced this issue Nov 26, 2021
…H-29777) (pythonGH-29792)

"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.

(cherry picked from commit 253b7a0)
(cherry picked from commit b6defde)
vstinner added a commit that referenced this issue Nov 26, 2021
… (GH-29792) (GH-29797)

"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.

(cherry picked from commit 253b7a0)
(cherry picked from commit b6defde)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment