-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Python 2 NamedTemporaryFile #74
Comments
I have a reimplementation of fsencode but most of this code is just a workaround for new failures in python 3.7.2 that only occur in CI
|
ok so to give a better response here -- the code taken here is taken from the stdlib test utils which polls for the existence of a file while trying to remove it specifically to handle race conditions during testing. I'm not totally sure it's necessary anymore to be quite honest, but we were encountering race conditions in pipenv related to cleanup starting in 3.7.2... I'll see about removing this and whether it has upstream impact |
If you do find you need a real tempfile.NamedTemporaryFile with fsencoding , we should work together with others on it in the backports packages, but if you can avoiding needing that, you safe yourself a lot of unnecessary headache ;-) |
- Fixes #74 - add fsencode and fsdecode test Signed-off-by: Dan Ryan <dan@danryan.co>
Firstly, in
tempfile.py
there isWorth noting that the final
elif arg
means any use ofu''
orb''
is ignored. This is different from stdlib, but probably not a bad thing. There are also other differences with this implementations vs the stdlib one, resulting in lots of errors when testing this implementation of_infer_return_type
with the stdlib test classTestLowLevelInternals
.But the important part to note is that
unicode
input results inunicode
as the inferred type.isinstance(type(u'foo'), six.string_types)
isFalse
.os.fsencode
doesnt exist on Python 2, so any use ofunicode
as args to the localNamedTemporaryFile
will result in an error.This also applies to
create_tracked_tempfile
, which passes all args through toNamedTemporaryFile
.Copying the example from the doctest in the
README.rst
anddocs/quickstart.rst
, and making themunicode_literals
...atomic_open_for_write(u'foo/bar', ...)
doesnt hit this, as it supplies adir
and aprefix
.You can partially remove this problem by substituting
os.fsencode("tmp")
forb'tmp'
, as that is a no-brainer you dont needos.fsencode
for.Removing
os.fsencode(gettempdir())
will be more difficult/intrusive, depending on the implementation goals. The main source of problems isgettempdir
uses_candidate_tempdir_list()
which first tries envvarsTMPDIR
,TEMP
, andTMP
, so anything is possible. It could be re-implemented to only use those envvars if they are paths which resolve correctly without usingos.fsencode
, perhaps falling back to the OS default paths which are saner.Or, use
backports.os.fsencode
, but be aware of PiDelport/backports.os#13 , and I've also encountered other problems with it while working on PiDelport/backports.tempfile#7 , but I havent identified that problem as clearly atm, eluding to it only a code comment.The text was updated successfully, but these errors were encountered: