ONE-api 3.0b3__py3-none-any.whl → 3.0b5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {ONE_api-3.0b3.dist-info → ONE_api-3.0b5.dist-info}/LICENSE +21 -21
  2. {ONE_api-3.0b3.dist-info → ONE_api-3.0b5.dist-info}/METADATA +115 -115
  3. ONE_api-3.0b5.dist-info/RECORD +37 -0
  4. one/__init__.py +2 -2
  5. one/alf/__init__.py +1 -1
  6. one/alf/cache.py +640 -653
  7. one/alf/exceptions.py +105 -105
  8. one/alf/io.py +876 -876
  9. one/alf/path.py +1450 -1450
  10. one/alf/spec.py +519 -519
  11. one/api.py +2979 -2973
  12. one/converters.py +850 -850
  13. one/params.py +414 -414
  14. one/registration.py +845 -845
  15. one/remote/__init__.py +1 -1
  16. one/remote/aws.py +313 -313
  17. one/remote/base.py +142 -142
  18. one/remote/globus.py +1254 -1254
  19. one/tests/fixtures/params/.caches +6 -6
  20. one/tests/fixtures/params/.test.alyx.internationalbrainlab.org +8 -8
  21. one/tests/fixtures/rest_responses/1f187d80fd59677b395fcdb18e68e4401bfa1cc9 +1 -1
  22. one/tests/fixtures/rest_responses/47893cf67c985e6361cdee009334963f49fb0746 +1 -1
  23. one/tests/fixtures/rest_responses/535d0e9a1e2c1efbdeba0d673b131e00361a2edb +1 -1
  24. one/tests/fixtures/rest_responses/6dc96f7e9bcc6ac2e7581489b9580a6cd3f28293 +1 -1
  25. one/tests/fixtures/rest_responses/db1731fb8df0208944ae85f76718430813a8bf50 +1 -1
  26. one/tests/fixtures/rest_responses/dcce48259bb929661f60a02a48563f70aa6185b3 +1 -1
  27. one/tests/fixtures/rest_responses/f530d6022f61cdc9e38cc66beb3cb71f3003c9a1 +1 -1
  28. one/tests/fixtures/test_dbs.json +14 -14
  29. one/util.py +524 -524
  30. one/webclient.py +1368 -1354
  31. ONE_api-3.0b3.dist-info/RECORD +0 -37
  32. {ONE_api-3.0b3.dist-info → ONE_api-3.0b5.dist-info}/WHEEL +0 -0
  33. {ONE_api-3.0b3.dist-info → ONE_api-3.0b5.dist-info}/top_level.txt +0 -0
one/remote/base.py CHANGED
@@ -1,142 +1,142 @@
1
- """Download methods common to all remote file download clients.
2
-
3
- All supported access protocols are defined in ALYX_JSON.
4
-
5
- Remote parameters:
6
- - All parameters are stored in the .remote JSON file.
7
- - The base keys are access protocols (e.g. 'globus').
8
- - Each contains a map of ID to parameters (e.g. keys such as 'default', 'admin').
9
- - load_client_params and save_client_params are used to read/write these params.
10
-
11
- Includes the DownloadClient superclass.
12
-
13
- TODO Currently record2url assumes all data are stored on a single HTTP data server. Data repos
14
- are not stored in the cache tables so should by default use HTTP data server but could get
15
- address by precedence. NB: OneAlyx._download_dataset uses record2url then calls
16
- AlyxClient.download_file.
17
- TODO Could have .one/.params file that stores ONE state, including whether files are distributed?
18
- """
19
- from abc import abstractmethod
20
- import logging
21
-
22
- from iblutil.io import params as iopar
23
-
24
- from one.params import _PAR_ID_STR
25
-
26
- """tuple: Default order of precedence for download protocol"""
27
- PROC_PRECEDENCE = ('aws', 'http', 'globus', 'kachary')
28
- ALYX_JSON = {
29
- 'access_protocol': {
30
- ('aws', 'http', 'kachary', 'globus')
31
- }
32
- }
33
- """str: Location of the remote download client parameters"""
34
- PAR_ID_STR = f'{_PAR_ID_STR}/remote'
35
- _logger = logging.getLogger(__name__)
36
-
37
-
38
- def load_client_params(client_key=None, assert_present=True):
39
- """Load the parameters from the remote params file.
40
-
41
- If a client key is provided, only those client parameters are returned.
42
- NB: Remote param values are expected to all be dicts.
43
-
44
- Parameters
45
- ----------
46
- client_key : str
47
- An optional, specific client whose parameters to return.
48
- assert_present : bool
49
- If True, raise error if client parameters not found.
50
-
51
- Returns
52
- -------
53
- IBLParams, None
54
- Download client parameters or None if assert_present is False and no parameters found.
55
-
56
- Raises
57
- ------
58
- FileNotFoundError
59
- No one/remote JSON file found.
60
- AttributeError
61
- Provided client key not present in one/remote params.
62
-
63
- Examples
64
- --------
65
- Load all remote parameters
66
-
67
- >>> pars = load_client_params()
68
-
69
- Load all glogus parameters or return None if non-existent
70
-
71
- >>> pars = load_client_params('globus', assert_present=False)
72
-
73
- Load parameters for a specific globus profile
74
-
75
- >>> pars = load_client_params('globus.admin')
76
-
77
- """
78
- try:
79
- p = iopar.read(PAR_ID_STR)
80
- if not client_key:
81
- return p
82
- for k in client_key.split('.'):
83
- p = iopar.from_dict(getattr(p, k))
84
- return p
85
- except (FileNotFoundError, AttributeError) as ex:
86
- if assert_present:
87
- raise ex
88
-
89
-
90
- def save_client_params(new_pars, client_key=None):
91
- """Save parameters into the remote params file.
92
-
93
- If a client key is provided, parameters are saved into this field.
94
-
95
- Parameters
96
- ----------
97
- new_pars : dict, IBLParams
98
- A set or subset or parameters to save.
99
- client_key : str
100
- An optional, specific client whose parameters to save.
101
-
102
- Raises
103
- ------
104
- ValueError
105
- If client_key is None, all parameter fields must hold dicts.
106
-
107
- """
108
- if not client_key:
109
- if not all(isinstance(x, dict) for x in iopar.as_dict(new_pars).values()):
110
- raise ValueError('Not all parameter fields contain dicts')
111
- return iopar.write(PAR_ID_STR, new_pars) # Save all parameters
112
- # Save parameters into client key field
113
- pars = iopar.as_dict(iopar.read(PAR_ID_STR, {}) or {})
114
- pars[client_key] = iopar.as_dict(new_pars)
115
- iopar.write(PAR_ID_STR, pars)
116
-
117
-
118
- class DownloadClient:
119
- """Data download handler base class."""
120
-
121
- def __init__(self):
122
- pass
123
-
124
- @abstractmethod
125
- def to_address(self, data_path, *args, **kwargs):
126
- """Returns the remote data URL for a given ALF path."""
127
- pass # pragma: no cover
128
-
129
- @abstractmethod
130
- def download_file(self, file_address, *args, **kwargs):
131
- """Download an ALF dataset given its address."""
132
- pass # pragma: no cover
133
-
134
- @staticmethod
135
- @abstractmethod
136
- def setup(*args, **kwargs):
137
- pass # pragma: no cover
138
-
139
- @staticmethod
140
- def repo_from_alyx(name, alyx):
141
- """Return the data repository information for a given data repository."""
142
- return alyx.rest('data-repository', 'read', id=name)
1
+ """Download methods common to all remote file download clients.
2
+
3
+ All supported access protocols are defined in ALYX_JSON.
4
+
5
+ Remote parameters:
6
+ - All parameters are stored in the .remote JSON file.
7
+ - The base keys are access protocols (e.g. 'globus').
8
+ - Each contains a map of ID to parameters (e.g. keys such as 'default', 'admin').
9
+ - load_client_params and save_client_params are used to read/write these params.
10
+
11
+ Includes the DownloadClient superclass.
12
+
13
+ TODO Currently record2url assumes all data are stored on a single HTTP data server. Data repos
14
+ are not stored in the cache tables so should by default use HTTP data server but could get
15
+ address by precedence. NB: OneAlyx._download_dataset uses record2url then calls
16
+ AlyxClient.download_file.
17
+ TODO Could have .one/.params file that stores ONE state, including whether files are distributed?
18
+ """
19
+ from abc import abstractmethod
20
+ import logging
21
+
22
+ from iblutil.io import params as iopar
23
+
24
+ from one.params import _PAR_ID_STR
25
+
26
+ """tuple: Default order of precedence for download protocol"""
27
+ PROC_PRECEDENCE = ('aws', 'http', 'globus', 'kachary')
28
+ ALYX_JSON = {
29
+ 'access_protocol': {
30
+ ('aws', 'http', 'kachary', 'globus')
31
+ }
32
+ }
33
+ """str: Location of the remote download client parameters"""
34
+ PAR_ID_STR = f'{_PAR_ID_STR}/remote'
35
+ _logger = logging.getLogger(__name__)
36
+
37
+
38
+ def load_client_params(client_key=None, assert_present=True):
39
+ """Load the parameters from the remote params file.
40
+
41
+ If a client key is provided, only those client parameters are returned.
42
+ NB: Remote param values are expected to all be dicts.
43
+
44
+ Parameters
45
+ ----------
46
+ client_key : str
47
+ An optional, specific client whose parameters to return.
48
+ assert_present : bool
49
+ If True, raise error if client parameters not found.
50
+
51
+ Returns
52
+ -------
53
+ IBLParams, None
54
+ Download client parameters or None if assert_present is False and no parameters found.
55
+
56
+ Raises
57
+ ------
58
+ FileNotFoundError
59
+ No one/remote JSON file found.
60
+ AttributeError
61
+ Provided client key not present in one/remote params.
62
+
63
+ Examples
64
+ --------
65
+ Load all remote parameters
66
+
67
+ >>> pars = load_client_params()
68
+
69
+ Load all glogus parameters or return None if non-existent
70
+
71
+ >>> pars = load_client_params('globus', assert_present=False)
72
+
73
+ Load parameters for a specific globus profile
74
+
75
+ >>> pars = load_client_params('globus.admin')
76
+
77
+ """
78
+ try:
79
+ p = iopar.read(PAR_ID_STR)
80
+ if not client_key:
81
+ return p
82
+ for k in client_key.split('.'):
83
+ p = iopar.from_dict(getattr(p, k))
84
+ return p
85
+ except (FileNotFoundError, AttributeError) as ex:
86
+ if assert_present:
87
+ raise ex
88
+
89
+
90
+ def save_client_params(new_pars, client_key=None):
91
+ """Save parameters into the remote params file.
92
+
93
+ If a client key is provided, parameters are saved into this field.
94
+
95
+ Parameters
96
+ ----------
97
+ new_pars : dict, IBLParams
98
+ A set or subset or parameters to save.
99
+ client_key : str
100
+ An optional, specific client whose parameters to save.
101
+
102
+ Raises
103
+ ------
104
+ ValueError
105
+ If client_key is None, all parameter fields must hold dicts.
106
+
107
+ """
108
+ if not client_key:
109
+ if not all(isinstance(x, dict) for x in iopar.as_dict(new_pars).values()):
110
+ raise ValueError('Not all parameter fields contain dicts')
111
+ return iopar.write(PAR_ID_STR, new_pars) # Save all parameters
112
+ # Save parameters into client key field
113
+ pars = iopar.as_dict(iopar.read(PAR_ID_STR, {}) or {})
114
+ pars[client_key] = iopar.as_dict(new_pars)
115
+ iopar.write(PAR_ID_STR, pars)
116
+
117
+
118
+ class DownloadClient:
119
+ """Data download handler base class."""
120
+
121
+ def __init__(self):
122
+ pass
123
+
124
+ @abstractmethod
125
+ def to_address(self, data_path, *args, **kwargs):
126
+ """Returns the remote data URL for a given ALF path."""
127
+ pass # pragma: no cover
128
+
129
+ @abstractmethod
130
+ def download_file(self, file_address, *args, **kwargs):
131
+ """Download an ALF dataset given its address."""
132
+ pass # pragma: no cover
133
+
134
+ @staticmethod
135
+ @abstractmethod
136
+ def setup(*args, **kwargs):
137
+ pass # pragma: no cover
138
+
139
+ @staticmethod
140
+ def repo_from_alyx(name, alyx):
141
+ """Return the data repository information for a given data repository."""
142
+ return alyx.rest('data-repository', 'read', id=name)