Skip to content

Commit c9e6dec

Browse files
Fix leading slash issue on insert into remote storage.
1 parent 870f4de commit c9e6dec

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Release notes
22

3+
### 0.12.2 -- Nov 8, 2019
4+
* Bugfix - Insert into external does not trim leading slash if defined in `dj.config['stores']['<store>']['location']` (#692)
5+
36
### 0.12.1 -- Nov 2, 2019
47
* Bugfix - AttributeAdapter converts into a string (#684)
58

datajoint/external.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pathlib import Path, PurePosixPath
1+
from pathlib import Path, PurePosixPath, PureWindowsPath
22
from collections import Mapping
33
from tqdm import tqdm
44
from .settings import config
@@ -74,7 +74,12 @@ def s3(self):
7474

7575
def _make_external_filepath(self, relative_filepath):
7676
"""resolve the complete external path based on the relative path"""
77-
return PurePosixPath(Path(self.spec['location']), relative_filepath)
77+
posix_path = PurePosixPath(PureWindowsPath(self.spec['location']))
78+
location_path = Path(
79+
*posix_path.parts[1:]) if any(
80+
case in posix_path.parts[0] for case in (
81+
'\\', ':')) else Path(posix_path)
82+
return PurePosixPath(location_path, relative_filepath)
7883

7984
def _make_uuid_path(self, uuid, suffix=''):
8085
"""create external path based on the uuid hash"""

datajoint/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.12.1"
1+
__version__ = "0.12.2"
22

33
assert len(__version__) <= 10 # The log table limits version to the 10 characters

docs-parts/intro/Releases_lang1.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.12.1 -- Nov 8, 2019
2+
-------------------------
3+
* Bugfix - Insert into external does not trim leading slash if defined in `dj.config['stores']['<store>']['location']` (#692)
4+
15
0.12.1 -- Nov 2, 2019
26
-------------------------
37
* Bugfix - AttributeAdapter converts into a string (#684)

tests/schema_external.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ class Simple(dj.Manual):
5555
"""
5656

5757

58+
@schema
59+
class SimpleRemote(dj.Manual):
60+
definition = """
61+
simple : int
62+
---
63+
item : blob@share
64+
"""
65+
66+
5867
@schema
5968
class Seed(dj.Lookup):
6069
definition = """

tests/test_external.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .schema_external import schema
88
import datajoint as dj
99
from .schema_external import stores_config
10+
from .schema_external import SimpleRemote
1011

1112

1213
def setUp(self):
@@ -33,3 +34,34 @@ def test_external_put():
3334

3435
output_ = unpack(ext.get(hash1))
3536
assert_array_equal(input_, output_)
37+
38+
39+
def test_leading_slash():
40+
"""
41+
external storage configured with leading slash
42+
"""
43+
value = np.array([1, 2, 3])
44+
45+
id = 100
46+
dj.config['stores']['share']['location'] = 'leading/slash/test'
47+
SimpleRemote.insert([{'simple': id, 'item': value}])
48+
assert_true(np.array_equal(
49+
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
50+
51+
id = 101
52+
dj.config['stores']['share']['location'] = '/leading/slash/test'
53+
SimpleRemote.insert([{'simple': id, 'item': value}])
54+
assert_true(np.array_equal(
55+
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
56+
57+
id = 102
58+
dj.config['stores']['share']['location'] = 'leading\\slash\\test'
59+
SimpleRemote.insert([{'simple': id, 'item': value}])
60+
assert_true(np.array_equal(
61+
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
62+
63+
id = 103
64+
dj.config['stores']['share']['location'] = 'f:\\leading\\slash\\test'
65+
SimpleRemote.insert([{'simple': id, 'item': value}])
66+
assert_true(np.array_equal(
67+
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))

0 commit comments

Comments
 (0)