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

Close NamedTemporaryFile early for Windows compat #3

Merged
merged 1 commit into from
Dec 7, 2016

Conversation

userzimmermann
Copy link
Contributor

Hi. Running python manage.py assets build or watch causes the following error on Windows:

webassets.exceptions.FilterError: elm: subprocess returned a non-success result code: 1,
stdout=b'Success! Compiled 0 modules.\r\n',
stderr=b'elm-make: C:\\Users\\Zimmermann\\AppData\\Local\\Temp\\tmph2k6lcv_.js: openFile: permission denied (Permission denied)\n'

The problem comes from Python's tempfile.NamedTemporaryFile. As long as the file is not closed in Python, it can't be accessed by external processes on Windows. You can read about that here:

https://bugs.python.org/issue14243

and in the tempfile documentation:

https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile

The solution is just to create the temp file with detete=False, close it immediately, and delete it manually when it's not used anymore. webassets.filter.ExternalTool.subprocess itself uses a similar approach, only with tempfile.mkstemp instead.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 27f9ea9 on userzimmermann:zimmermann/windows into 8ac1320 on cuducos:master.

@cuducos cuducos merged commit 5bb2207 into cuducos:master Dec 7, 2016
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.

3 participants