File tree 2 files changed +5
-7
lines changed
2 files changed +5
-7
lines changed Original file line number Diff line number Diff line change 2
2
Utilities for dealing with temporary file management.
3
3
"""
4
4
import os
5
+ import uuid
5
6
from tempfile import NamedTemporaryFile
6
7
7
8
import numpy as np
8
9
9
10
10
11
def unique_name ():
11
12
"""
12
- Generate a unique name with the prefix 'gmt-python-' .
13
+ Generate a unique name.
13
14
14
15
Useful for generating unique names for figures (otherwise GMT will plot
15
16
everything on the same figure instead of creating a new one).
16
17
17
18
Returns
18
19
-------
19
20
name : str
20
- A unique name generated by ``tempfile.NamedTemporaryFile` `
21
+ A unique name generated by :func:`uuid.uuid4 `
21
22
22
23
"""
23
- # Use the tempfile module to generate a unique name.
24
- with NamedTemporaryFile (prefix = "gmt-python-" ) as tmpfile :
25
- return os .path .split (tmpfile .name )[- 1 ]
24
+ return uuid .uuid4 ().hex
26
25
27
26
28
27
class GMTTempFile :
Original file line number Diff line number Diff line change 10
10
11
11
12
12
def test_unique_name ():
13
- "Make sure the names start with gmt-python- and are really unique"
13
+ "Make sure the names are really unique"
14
14
names = [unique_name () for i in range (100 )]
15
- assert all ([name .startswith ("gmt-python-" ) for name in names ])
16
15
assert len (names ) == len (set (names ))
17
16
18
17
You can’t perform that action at this time.
0 commit comments