Closed
Bug 821362
Opened 13 years ago
Closed 13 years ago
migrate NamedTemporaryFile improvement to mozfile
Categories
(Testing :: Mozbase, defect)
Testing
Mozbase
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: k0scist, Unassigned)
References
Details
Attachments
(2 files)
|
2.66 KB,
patch
|
wlach
:
review-
|
Details | Diff | Splinter Review |
|
2.78 KB,
patch
|
wlach
:
review+
|
Details | Diff | Splinter Review |
A python stdlib method doesn't work on windows! Wonderful!
Luckily we have a great place to put these hacks: mozfile. Let's
throw it there.
For context, see:
https://bugzilla.mozilla.org/show_bug.cgi?id=818777
https://bug818777.bugzilla.mozilla.org/attachment.cgi?id=691701
| Reporter | ||
Comment 1•13 years ago
|
||
the unittest is a joke but I figured better than no test at all (it actually helped me catch a missing import of tempfile, fwiw).
I also corrected the rmtree test name, since it actually was never run before!
Attachment #691884 -
Flags: review?(wlachance)
Comment 2•13 years ago
|
||
Be very careful with the naive implementation. I purposefully only put it in mozunit because it doesn't behave exactly like the stdlib does. Specifically, it doesn't do things like prevent fd inheritance by children, etc. Use at your own risk.
Comment 3•13 years ago
|
||
Comment on attachment 691884 [details] [diff] [review]
port from https://bug818777.bugzilla.mozilla.org/attachment.cgi?id=691701
I'm giving this an r- just because I'd like to see better documentation. I don't want people to blindly start using this function everywhere without having a realistic view of its pros and cons.
>+class NamedTemporaryFile(object):
>+ """Like tempfile.NamedTemporaryFile except it works on Windows.
This comment isn't quite true, from what I can gather from the original bug: NamedTemporaryFile *does* work on Windows, you just can't open the created file a second time.
>+ This behaves very similarly to tempfile.NamedTemporaryFile but may
>+ not behave exactly the same.
We should be more explicit about the limitations of this function here (e.g. what :gps said about it not preventing fd inheritance by children)
>+ Example usage:
>+
>+ with NamedTemporaryFile() as fh:
>+ fh.write(b'foobar')
>+
>+ print('Filename: %s' % fh.name)
>+
>+ see https://bugzilla.mozilla.org/show_bug.cgi?id=821362
>+ """
Attachment #691884 -
Flags: review?(wlachance) → review-
| Reporter | ||
Comment 4•13 years ago
|
||
So...I didn't write this class or docstring! In fact the only change I made from the code already checked in on m-c is noting the bug # in the docstring. I'll edit the patch to try to intuit what :gps meant to say but its not really my forte.
| Reporter | ||
Comment 5•13 years ago
|
||
If this isn't good enough, I recommend :wlach or :gps submit an appropriate patch with a more pallatable docstring. My main goal is to get this into mozfile, release a new mozfile, mirror to m-c, and get mozbuild/mach to use this code so that we have one place to fix things.
Attachment #692067 -
Flags: review?(wlachance)
Comment 6•13 years ago
|
||
Comment on attachment 692067 [details] [diff] [review]
docstring changes
This is better, thanks! I just have one nit about the phrasing in the comments. r+ with that addressed.
>diff --git a/mozfile/mozfile/mozfile.py b/mozfile/mozfile/mozfile.py
>+ This behaves very similarly to tempfile.NamedTemporaryFile but may
>+ not behave exactly the same. This does not prevent fd inheritence
>+ by children.
I would reword this last sentence to:
"For example, this function does not prevent fd inheritance by children."
I think that makes it a little more clear that this may not be the only difference.
Attachment #692067 -
Flags: review?(wlachance) → review+
| Reporter | ||
Comment 7•13 years ago
|
||
> I would reword this last sentence to:
>
> "For example, this function does not prevent fd inheritance by children."
>
> I think that makes it a little more clear that this may not be the only difference.
SGTM
| Reporter | ||
Comment 8•13 years ago
|
||
| Reporter | ||
Updated•13 years ago
|
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•