Merge lp:~jelmer/brz/tempdir into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 7645
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/tempdir
Merge into: lp:brz
Diff against target: 342 lines (+32/-48)
16 files modified
breezy/bzr/remote.py (+7/-13)
breezy/bzr/smart/repository.py (+1/-1)
breezy/bzr/tests/test_bundle.py (+2/-1)
breezy/bzr/transform.py (+2/-1)
breezy/diff.py (+1/-1)
breezy/doc/api/branch.txt (+2/-2)
breezy/git/transform.py (+2/-1)
breezy/mail_client.py (+1/-1)
breezy/merge.py (+2/-4)
breezy/osutils.py (+0/-10)
breezy/tests/__init__.py (+2/-2)
breezy/tests/blackbox/test_outside_wt.py (+3/-2)
breezy/tests/features.py (+3/-3)
breezy/tests/test_merge_core.py (+2/-1)
breezy/tests/test_osutils.py (+0/-4)
breezy/tests/test_whitebox.py (+2/-1)
To merge this branch: bzr merge lp:~jelmer/brz/tempdir
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+430341@code.launchpad.net

Commit message

Avoid osutils.mkdtemp.

Description of the change

Avoid osutils.mkdtemp.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/remote.py'
2--- breezy/bzr/remote.py 2022-08-22 18:19:46 +0000
3+++ breezy/bzr/remote.py 2022-09-23 07:44:17 +0000
4@@ -2633,19 +2633,13 @@
5 if tar_file is None:
6 return None
7 destination = to_bzrdir.create_repository()
8- try:
9- tar = tarfile.open('repository', fileobj=tar_file,
10- mode='r|bz2')
11- tmpdir = osutils.mkdtemp()
12- try:
13- tar.extractall(tmpdir)
14- tmp_bzrdir = _mod_bzrdir.BzrDir.open(tmpdir)
15- tmp_repo = tmp_bzrdir.open_repository()
16- tmp_repo.copy_content_into(destination, revision_id)
17- finally:
18- osutils.rmtree(tmpdir)
19- finally:
20- tar_file.close()
21+ with tarfile.open('repository', fileobj=tar_file,
22+ mode='r|bz2') as tar, \
23+ osutils.TemporaryDirectory() as tmpdir:
24+ tar.extractall(tmpdir)
25+ tmp_bzrdir = _mod_bzrdir.BzrDir.open(tmpdir)
26+ tmp_repo = tmp_bzrdir.open_repository()
27+ tmp_repo.copy_content_into(destination, revision_id)
28 return destination
29 # TODO: Suggestion from john: using external tar is much faster than
30 # python's tarfile library, but it may not work on windows.
31
32=== modified file 'breezy/bzr/smart/repository.py'
33--- breezy/bzr/smart/repository.py 2021-08-18 22:38:08 +0000
34+++ breezy/bzr/smart/repository.py 2022-09-23 07:44:17 +0000
35@@ -829,7 +829,7 @@
36 osutils.rmtree(tmp_dirname)
37
38 def _copy_to_tempdir(self, from_repo):
39- tmp_dirname = osutils.mkdtemp(prefix='tmpbzrclone')
40+ tmp_dirname = tempfile.mkdtemp(prefix='tmpbzrclone')
41 tmp_bzrdir = from_repo.controldir._format.initialize(tmp_dirname)
42 tmp_repo = from_repo._format.initialize(tmp_bzrdir)
43 from_repo.copy_content_into(tmp_repo)
44
45=== modified file 'breezy/bzr/tests/test_bundle.py'
46--- breezy/bzr/tests/test_bundle.py 2022-08-22 18:19:46 +0000
47+++ breezy/bzr/tests/test_bundle.py 2022-09-23 07:44:17 +0000
48@@ -18,6 +18,7 @@
49 from io import BytesIO
50 import os
51 import sys
52+import tempfile
53
54 from ... import (
55 diff,
56@@ -479,7 +480,7 @@
57 """
58
59 if checkout_dir is None:
60- checkout_dir = osutils.mkdtemp(prefix='test-branch-', dir='.')
61+ checkout_dir = tempfile.mkdtemp(prefix='test-branch-', dir='.')
62 else:
63 if not os.path.exists(checkout_dir):
64 os.mkdir(checkout_dir)
65
66=== modified file 'breezy/bzr/transform.py'
67--- breezy/bzr/transform.py 2022-08-22 18:19:46 +0000
68+++ breezy/bzr/transform.py 2022-09-23 07:44:17 +0000
69@@ -21,6 +21,7 @@
70 import errno
71 import os
72 from stat import S_IEXEC, S_ISREG
73+import tempfile
74 import time
75
76 from .. import (
77@@ -1853,7 +1854,7 @@
78
79 def __init__(self, tree, pb=None, case_sensitive=True):
80 tree.lock_read()
81- limbodir = osutils.mkdtemp(prefix='bzr-limbo-')
82+ limbodir = tempfile.mkdtemp(prefix='bzr-limbo-')
83 DiskTreeTransform.__init__(self, tree, limbodir, pb, case_sensitive)
84
85 def canonical_path(self, path):
86
87=== modified file 'breezy/diff.py'
88--- breezy/diff.py 2022-08-22 18:19:46 +0000
89+++ breezy/diff.py 2022-09-23 07:44:17 +0000
90@@ -777,7 +777,7 @@
91 path_encoding='utf-8'):
92 DiffPath.__init__(self, old_tree, new_tree, to_file, path_encoding)
93 self.command_template = command_template
94- self._root = osutils.mkdtemp(prefix='brz-diff-')
95+ self._root = tempfile.mkdtemp(prefix='brz-diff-')
96
97 @classmethod
98 def from_string(klass,
99
100=== modified file 'breezy/doc/api/branch.txt'
101--- breezy/doc/api/branch.txt 2020-02-07 02:14:30 +0000
102+++ breezy/doc/api/branch.txt 2022-09-23 07:44:17 +0000
103@@ -4,8 +4,8 @@
104
105 Make a temporary directory for these tests:
106
107- >>> from breezy import osutils
108- >>> test_dir = osutils.mkdtemp(prefix='breezy_doc_api_branch_txt_')
109+ >>> import tempfile
110+ >>> test_dir = tempfile.mkdtemp(prefix='breezy_doc_api_branch_txt_')
111
112 Branches are created by ControlDir's:
113
114
115=== modified file 'breezy/git/transform.py'
116--- breezy/git/transform.py 2022-08-22 18:19:46 +0000
117+++ breezy/git/transform.py 2022-09-23 07:44:17 +0000
118@@ -21,6 +21,7 @@
119 import os
120 import posixpath
121 from stat import S_IEXEC, S_ISREG
122+import tempfile
123 import time
124
125 from .mapping import encode_git_path, mode_kind, mode_is_executable, object_mode
126@@ -1528,7 +1529,7 @@
127
128 def __init__(self, tree, pb=None, case_sensitive=True):
129 tree.lock_read()
130- limbodir = osutils.mkdtemp(prefix='git-limbo-')
131+ limbodir = tempfile.mkdtemp(prefix='git-limbo-')
132 DiskTreeTransform.__init__(self, tree, limbodir, pb, case_sensitive)
133
134 def canonical_path(self, path):
135
136=== modified file 'breezy/mail_client.py'
137--- breezy/mail_client.py 2020-02-18 01:57:45 +0000
138+++ breezy/mail_client.py 2022-09-23 07:44:17 +0000
139@@ -164,7 +164,7 @@
140 """
141 if basename is None:
142 basename = 'attachment'
143- pathname = osutils.mkdtemp(prefix='bzr-mail-')
144+ pathname = tempfile.mkdtemp(prefix='bzr-mail-')
145 attach_path = osutils.pathjoin(pathname, basename + extension)
146 with open(attach_path, 'wb') as outfile:
147 outfile.write(attachment)
148
149=== modified file 'breezy/merge.py'
150--- breezy/merge.py 2022-08-22 18:19:46 +0000
151+++ breezy/merge.py 2022-09-23 07:44:17 +0000
152@@ -15,6 +15,7 @@
153 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
154
155 import contextlib
156+import tempfile
157
158 from .lazy_import import lazy_import
159 lazy_import(globals(), """
160@@ -1644,8 +1645,7 @@
161 """
162 import breezy.patch
163 base_path, other_path, this_path = paths
164- temp_dir = osutils.mkdtemp(prefix="bzr-")
165- try:
166+ with tempfile.TemporaryDirectory(prefix="bzr-") as temp_dir:
167 new_file = osutils.pathjoin(temp_dir, "new")
168 this = self.dump_file(
169 temp_dir, "this", self.this_tree, this_path)
170@@ -1663,8 +1663,6 @@
171 parent_id = self.tt.final_parent(trans_id)
172 self._dump_conflicts(name, paths, parent_id)
173 self._raw_conflicts.append(('text conflict', trans_id))
174- finally:
175- osutils.rmtree(temp_dir)
176
177
178 class PathNotInTree(errors.BzrError):
179
180=== modified file 'breezy/osutils.py'
181--- breezy/osutils.py 2022-08-22 18:19:46 +0000
182+++ breezy/osutils.py 2022-09-23 07:44:17 +0000
183@@ -36,10 +36,6 @@
184 from shutil import rmtree
185 import socket
186 import subprocess
187-# We need to import both tempfile and mkdtemp as we export the later on posix
188-# and need the former on windows
189-import tempfile
190-from tempfile import mkdtemp
191 import unicodedata
192
193 from breezy import (
194@@ -359,10 +355,6 @@
195 return _win32_fixdrive(_win32_fix_separators(_getcwd()))
196
197
198-def _win32_mkdtemp(*args, **kwargs):
199- return _win32_fixdrive(_win32_fix_separators(tempfile.mkdtemp(*args, **kwargs)))
200-
201-
202 def _win32_rename(old, new):
203 """We expect to be able to atomically replace 'new' with old.
204
205@@ -426,7 +418,6 @@
206 split = os.path.split
207 splitext = os.path.splitext
208 # These were already lazily imported into local scope
209-# mkdtemp = tempfile.mkdtemp
210 # rmtree = shutil.rmtree
211 lstat = os.lstat
212 fstat = os.fstat
213@@ -445,7 +436,6 @@
214 pathjoin = _win32_pathjoin
215 normpath = _win32_normpath
216 getcwd = _win32_getcwd
217- mkdtemp = _win32_mkdtemp
218 rename = _rename_wrap_exception(_win32_rename)
219 try:
220 from . import _walkdirs_win32
221
222=== modified file 'breezy/tests/__init__.py'
223--- breezy/tests/__init__.py 2022-08-22 18:19:46 +0000
224+++ breezy/tests/__init__.py 2022-09-23 07:44:17 +0000
225@@ -2693,8 +2693,8 @@
226 def _make_test_root(self):
227 if TestCaseWithMemoryTransport.TEST_ROOT is None:
228 # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
229- root = osutils.realpath(osutils.mkdtemp(prefix='testbzr-',
230- suffix='.tmp'))
231+ root = osutils.realpath(tempfile.mkdtemp(prefix='testbzr-',
232+ suffix='.tmp'))
233 TestCaseWithMemoryTransport.TEST_ROOT = root
234
235 self._create_safety_net()
236
237=== modified file 'breezy/tests/blackbox/test_outside_wt.py'
238--- breezy/tests/blackbox/test_outside_wt.py 2018-11-11 04:08:32 +0000
239+++ breezy/tests/blackbox/test_outside_wt.py 2022-09-23 07:44:17 +0000
240@@ -19,6 +19,7 @@
241 """Black-box tests for running brz outside of a working tree."""
242
243 import os
244+import tempfile
245
246 from breezy import (
247 osutils,
248@@ -33,7 +34,7 @@
249
250 def test_cwd_log(self):
251 # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
252- tmp_dir = osutils.realpath(osutils.mkdtemp())
253+ tmp_dir = osutils.realpath(tempfile.mkdtemp())
254 # We expect a read-to-root attempt to occur.
255 self.permit_url('file:///')
256 self.addCleanup(osutils.rmtree, tmp_dir)
257@@ -56,7 +57,7 @@
258 # in a brz tree (though if there is one at or above $TEMPDIR, this is
259 # false and may cause test failures).
260 # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
261- tmp_dir = osutils.realpath(osutils.mkdtemp())
262+ tmp_dir = osutils.realpath(tempfile.mkdtemp())
263 self.addCleanup(osutils.rmtree, tmp_dir)
264 # We expect a read-to-root attempt to occur.
265 self.permit_url('file:///')
266
267=== modified file 'breezy/tests/features.py'
268--- breezy/tests/features.py 2022-05-15 14:17:32 +0000
269+++ breezy/tests/features.py 2022-09-23 07:44:17 +0000
270@@ -338,12 +338,12 @@
271 from breezy import tests
272
273 if tests.TestCaseWithMemoryTransport.TEST_ROOT is None:
274- root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
275+ root = tempfile.mkdtemp(prefix='testbzr-', suffix='.tmp')
276 tests.TestCaseWithMemoryTransport.TEST_ROOT = root
277 else:
278 root = tests.TestCaseWithMemoryTransport.TEST_ROOT
279- tdir = osutils.mkdtemp(prefix='case-sensitive-probe-', suffix='',
280- dir=root)
281+ tdir = tempfile.mkdtemp(prefix='case-sensitive-probe-', suffix='',
282+ dir=root)
283 name_a = osutils.pathjoin(tdir, 'a')
284 name_A = osutils.pathjoin(tdir, 'A')
285 os.mkdir(name_a)
286
287=== modified file 'breezy/tests/test_merge_core.py'
288--- breezy/tests/test_merge_core.py 2022-01-21 17:19:24 +0000
289+++ breezy/tests/test_merge_core.py 2022-09-23 07:44:17 +0000
290@@ -16,6 +16,7 @@
291
292 import os
293 import sys
294+import tempfile
295
296 import breezy
297 from .. import (
298@@ -46,7 +47,7 @@
299 class MergeBuilder(object):
300
301 def __init__(self, dir=None):
302- self.dir = osutils.mkdtemp(prefix="merge-test", dir=dir)
303+ self.dir = tempfile.mkdtemp(prefix="merge-test", dir=dir)
304 self.tree_root = generate_ids.gen_root_id()
305
306 def wt(name):
307
308=== modified file 'breezy/tests/test_osutils.py'
309--- breezy/tests/test_osutils.py 2022-05-15 14:17:32 +0000
310+++ breezy/tests/test_osutils.py 2022-09-23 07:44:17 +0000
311@@ -950,10 +950,6 @@
312 self.assertEqual({'a-b', 'a', 'a0b'},
313 osutils.minimum_path_selection(['a-b', 'a/b', 'a0b', 'a']))
314
315- def test_mkdtemp(self):
316- tmpdir = osutils._win32_mkdtemp(dir='.')
317- self.assertFalse('\\' in tmpdir)
318-
319 def test_rename(self):
320 with open('a', 'wb') as a:
321 a.write(b'foo\n')
322
323=== modified file 'breezy/tests/test_whitebox.py'
324--- breezy/tests/test_whitebox.py 2018-11-11 04:08:32 +0000
325+++ breezy/tests/test_whitebox.py 2022-09-23 07:44:17 +0000
326@@ -15,6 +15,7 @@
327 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
328
329 import os
330+import tempfile
331
332 import breezy
333 from .. import (
334@@ -34,7 +35,7 @@
335 job: given a path (either relative to cwd or absolute), work out
336 if it is inside a branch and return the path relative to the base.
337 """
338- dtmp = osutils.mkdtemp()
339+ dtmp = tempfile.mkdtemp()
340 self.addCleanup(osutils.rmtree, dtmp)
341 # On Mac OSX, /tmp actually expands to /private/tmp
342 dtmp = realpath(dtmp)

Subscribers

People subscribed via source and target branches