Passes kwargs through AtomicWriter and uses io.open as opener#38
Conversation
|
tbh i'd much rather pass through only the options that |
untitaker
left a comment
There was a problem hiding this comment.
lgtm except that we shouldn't expose prefix and suffix
|
I can pop I don't think |
|
I was more thinking about a whitelist of options, or removing kwargs entirely in favor of explicit options (probably nicer for api docs) |
|
I guess I'm having trouble following what you're proposing. If you'd rather just have a Out of curiosity, how would |
|
@lorengordon I just want to keep the API surface minimal and I haven't seen a good usecase for changing the defaults. I do see the usecase for setting I wonder if that's worth the effort though... I'll think about it |
|
I see. Ok. Well if using the same opener on python 2 and python 3 is desirable, here's an option... No more diff --git a/atomicwrites/__init__.py b/atomicwrites/__init__.py
index 108af8e..aa48a43 100644
--- a/atomicwrites/__init__.py
+++ b/atomicwrites/__init__.py
@@ -1,4 +1,5 @@
import contextlib
+import io
import os
import sys
import tempfile
@@ -163,10 +164,10 @@ class AtomicWriter(object):
'''Return the temporary file to use.'''
if dir is None:
dir = os.path.normpath(os.path.dirname(self._path))
- kwargs['dir'] = dir
- kwargs['delete'] = False
+ descriptor, _ = tempfile.mkstemp(dir=dir)
kwargs['mode'] = self._mode
- return tempfile.NamedTemporaryFile(**kwargs)
+ kwargs['file'] = descriptor
+ return io.open(**kwargs)
def sync(self, f):
'''responsible for clearing as many file caches as possible before |
|
yuup that looks fine, thanks |
|
Ok, updated the pr to use io.open as the opener. |
| try: | ||
| success = False | ||
| with get_fileobject() as f: | ||
| with get_fileobject(**self._tempfile_kwargs) as f: |
There was a problem hiding this comment.
Could you rename this param to open_kwargs
There was a problem hiding this comment.
Quite right. Meant to do that before. Fixed!
|
I'll check later how we can fix the tests |
|
Yeah, looks like io.open makes that attribute read-only somehow or other. I can look into it late afternoon or this weekend if you don't get to it first. |
ame is not writeable on _io.TextIOWrapper objects
|
Just updated the test with one option. The second exception would be raised in a slightly different place, |
|
Hrm, the failure on py27 is more troubling. Introducing
Enforcing from __future__ import unicode_literalsLemme know if you want to press forward or revert that. |
|
Please don't use that future import but prefer explicit |
|
Sure thing. My preference has always been the other way around, and to just fix my python2 code accordingly. But, up to you of course. |
|
Cool, thx. Ping me if you need a release. |
|
I generally only install from pypi, and usually pin versions/ranges on dependencies, so a release would be great. Thanks! Always great working with a responsive maintainer! :D |
|
I had to make some last-minute changes in master (avoid API breakage due to use of io.open), will release later today
… On 24.08.2018, at 20:00, Loren Gordon ***@***.***> wrote:
I generally only install from pypi, and usually pin versions/ranges on dependencies, so a release would be great. Thanks! Always great working with a responsive maintainer! :D
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
Yup, understood. Appreciate it! |
The changes in untitaker#38 broke the ability to use prefix, suffix and bufsize arguments when creating the tempfile. This commit restores the ability.
The changes in untitaker#38 broke the ability to use prefix, suffix and bufsize arguments when creating the tempfile. This commit restores the ability.
The changes in #38 broke the ability to use prefix, suffix and bufsize arguments when creating the tempfile. This commit restores the ability.
This enables users to pass any option supported by
tempfile.NamedTemporaryFile()toatomic_write(). However,mode,dir, anddeletecontinue to be overwritten as they were previously, to enforce the atomic write behavior.Let me know if this approach is alright. I'm happy to adjust as needed.
Fixes #37