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

Add utility func to get path to assets #777

Merged
merged 1 commit into from
May 15, 2020

Conversation

mthrok
Copy link
Contributor

@mthrok mthrok commented May 15, 2020

@cpuhrsch @zhangguanheng66

It turned out that buck runs test in a directory of which full path contains a comma.
When Sentence Piece Trainer is given such a path, it considers there are multiple of paths, and fails.

To workaround this, I added a helper function that facilitates path generation and optionally copy the file to temporary directory and return the path there.
Then I adopted the function to other places where it uses test assets.

atexit.register(_TEMP_DIR.cleanup)


def get_asset_path(*path_components, use_temp_dir=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

You could make this a context with get_assest that'll then also cleans up the temp file if it goes out of scope (if that is intended).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the typical approach, but that way user of this function has to be aware of temporary files and directories. This way, they are abstracted out and users need not care.

Copy link
Contributor

@cpuhrsch cpuhrsch left a comment

Choose a reason for hiding this comment

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

Added comment for follow-up

@mthrok mthrok merged commit 9bdfb04 into pytorch:master May 15, 2020
@mthrok mthrok deleted the unify-asset-access branch May 15, 2020 18:10
@mthrok
Copy link
Contributor Author

mthrok commented May 15, 2020

thanks!

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