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

ci(package): NamedTemporaryFile Being Opened Twice #2567

Merged
merged 23 commits into from Jan 29, 2021

Conversation

CoshUS
Copy link
Contributor

@CoshUS CoshUS commented Jan 29, 2021

Which issue(s) does this change fix?

Why is this change necessary?

In Windows NT or later, NamedTemporaryFile cannot be opened twice.
https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile

How does it address the issue?

What side effects does this change have?

Checklist

  • Add input/output type hints to new functions/methods
  • Write design document (Do I need to write a design document?)
  • Write unit tests
  • Write/update functional tests
  • Write/update integration tests
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@CoshUS CoshUS changed the title fix(package): NamedTemporaryFile Being Opened Twice ci(package): NamedTemporaryFile Being Opened Twice Jan 29, 2021
@@ -131,6 +131,10 @@ def test_package_template_with_image_function_in_nested_application(self, templa
# when image function is not in main template, erc_repo_name does not show up in stdout
# here we download the nested application template file and verify its content
with tempfile.NamedTemporaryFile() as packaged_file, tempfile.TemporaryFile() as packaged_nested_file:
# https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
# Closes the NamedTemporaryFile as on Windows NT or later, NamedTemporaryFile cannot be opened twice.
packaged_file.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use TemporaryFile() for package_file?

Copy link
Contributor Author

@CoshUS CoshUS Jan 29, 2021

Choose a reason for hiding this comment

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

TemporaryFile does not guarantee the file is visible in the file system on Unix. We need to read the file later using packaged_file.name in order to validate the output.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need a visible name for package_file in the file system, which is used for output_template_file in the command.

TemporaryFile() does not guarantee a visible name in the file system.
We don't need the file to actually exist though. Since the command will create the file again

Copy link
Contributor

@hawflau hawflau left a comment

Choose a reason for hiding this comment

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

LGTM!

@hawflau hawflau merged commit 87576ec into aws:develop Jan 29, 2021
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.

None yet

3 participants