Skip to content

fix __file__ value inside components #1056

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
Apr 30, 2025

Conversation

daniel-ohayon
Copy link
Contributor

Summary:
Currently when we exec a component, we pass it the caller file's namespace. As a result, __file__ resolves to .../torchx/specs/finder.py inside the compoennt at runtime, which is confusing.
This fixes that.

Differential Revision: D73793210

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 28, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D73793210

daniel-ohayon pushed a commit to daniel-ohayon/torchx that referenced this pull request Apr 30, 2025
Summary:

Currently when we exec a component, we pass it the caller file's namespace. As a result, `__file__` resolves to `.../torchx/specs/finder.py` inside the compoennt at runtime, which is confusing.
This fixes that.

Reviewed By: crassirostris

Differential Revision: D73793210
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D73793210

daniel-ohayon pushed a commit to daniel-ohayon/torchx that referenced this pull request Apr 30, 2025
Summary:
Pull Request resolved: pytorch#1056

Currently when we exec a component, we pass it the caller file's namespace. As a result, `__file__` resolves to `.../torchx/specs/finder.py` inside the compoennt at runtime, which is confusing.
This fixes that.

Reviewed By: crassirostris

Differential Revision: D73793210
daniel-ohayon pushed a commit to daniel-ohayon/torchx that referenced this pull request Apr 30, 2025
Summary:

Currently when we exec a component, we pass it the caller file's namespace. As a result, `__file__` resolves to `.../torchx/specs/finder.py` inside the compoennt at runtime, which is confusing.
This fixes that.

Reviewed By: crassirostris

Differential Revision: D73793210
Summary:
Pull Request resolved: pytorch#1056

Currently when we exec a component, we pass it the caller file's namespace. As a result, `__file__` resolves to `.../torchx/specs/finder.py` inside the compoennt at runtime, which is confusing.
This fixes that.

Reviewed By: crassirostris

Differential Revision: D73793210
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D73793210

namespace = globals()
namespace = copy.copy(globals())
# so that __file__ used inside the component points to the correct file
namespace["__file__"] = os.path.abspath(self._filepath)
Copy link
Contributor

Choose a reason for hiding this comment

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

would be great to add a unittest assertion for this (either as a testcase or simply adding an assertion in an existing testcase here: https://github.com/pytorch/torchx/blob/main/torchx/specs/test/finder_test.py#L194)

@facebook-github-bot facebook-github-bot merged commit 16cefac into pytorch:main Apr 30, 2025
22 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants