Skip to content

[gyb] Support -o with relative path #67995

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

Merged
merged 1 commit into from
Sep 11, 2023
Merged

Conversation

dabrahams
Copy link
Contributor

Fixes a surprising bug where a relative output file path would be interpreted relative to the directory of the .gyb file being processed rather than the current working directory upon invocation.

Fixes a surprising bug where a relative output file path would be interpreted relative to the directory of the `.gyb` file being processed rather than the current working directory upon invocation.
# Allow the template to open files and import .py files relative to its own
# directory
saved_cwd = os.getcwd()
os.chdir(os.path.dirname(os.path.abspath(args.file)))
sys.path = ['.'] + sys.path
Copy link
Member

Choose a reason for hiding this comment

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

Could we use the computed path and prepend that to sys.path instead of of doing the chdir?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly. That might even be a better solution; amendments welcome.

@compnerd
Copy link
Member

@swift-ci please smoke test

@dabrahams dabrahams merged commit 8e2b48b into main Sep 11, 2023
@dabrahams dabrahams deleted the gyb-relative-output-path-fix branch September 11, 2023 18:12
mininny pushed a commit to mininny/swift that referenced this pull request Sep 14, 2023
Fixes a surprising bug where a relative output file path would be interpreted relative to the directory of the `.gyb` file being processed rather than the current working directory upon invocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants