datastock 0.0.49__py3-none-any.whl → 0.0.50__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.
- datastock/__init__.py +23 -2
- datastock/_version.py +21 -0
- datastock/tests/prepublish.py +3 -0
- datastock/version.py +1 -1
- {datastock-0.0.49.dist-info → datastock-0.0.50.dist-info}/METADATA +46 -71
- {datastock-0.0.49.dist-info → datastock-0.0.50.dist-info}/RECORD +10 -13
- {datastock-0.0.49.dist-info → datastock-0.0.50.dist-info}/WHEEL +1 -1
- datastock-0.0.49.dist-info/LICENSE → datastock-0.0.50.dist-info/licenses/LICENSE.txt +1 -1
- datastock-0.0.50.dist-info/top_level.txt +1 -0
- _updateversion.py +0 -32
- datastock-0.0.49.dist-info/top_level.txt +0 -3
- scripts/__init__.py +0 -0
- scripts/_bash_version.py +0 -77
- scripts/_dparser.py +0 -109
- scripts/main.py +0 -147
- {datastock-0.0.49.dist-info → datastock-0.0.50.dist-info}/entry_points.txt +0 -0
datastock/__init__.py
CHANGED
@@ -1,10 +1,31 @@
|
|
1
|
+
# ###############
|
2
|
+
# __version__
|
3
|
+
# ###############
|
1
4
|
|
2
5
|
|
3
|
-
from .
|
6
|
+
from . import _version
|
7
|
+
__version__ = _version.version
|
8
|
+
__version_tuple__ = _version.version_tuple
|
9
|
+
|
10
|
+
|
11
|
+
# from setuptools_scm import get_version
|
12
|
+
# __version__ = get_version(root='..', relative_to=__file__)
|
13
|
+
|
14
|
+
|
15
|
+
# from importlib.metadata import version
|
16
|
+
# __version__ = version(__package__)
|
17
|
+
# cleanup
|
18
|
+
# del get_version
|
19
|
+
|
20
|
+
|
21
|
+
# ###############
|
22
|
+
# sub-packages
|
23
|
+
# ###############
|
24
|
+
|
4
25
|
|
5
26
|
from . import _generic_check
|
6
27
|
from ._generic_utils_plot import *
|
7
28
|
from ._class import DataStock
|
8
29
|
from ._saveload import load, get_files
|
9
30
|
from ._direct_calls import *
|
10
|
-
from . import tests
|
31
|
+
from . import tests
|
datastock/_version.py
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# file generated by setuptools-scm
|
2
|
+
# don't change, don't track in version control
|
3
|
+
|
4
|
+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
|
5
|
+
|
6
|
+
TYPE_CHECKING = False
|
7
|
+
if TYPE_CHECKING:
|
8
|
+
from typing import Tuple
|
9
|
+
from typing import Union
|
10
|
+
|
11
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
12
|
+
else:
|
13
|
+
VERSION_TUPLE = object
|
14
|
+
|
15
|
+
version: str
|
16
|
+
__version__: str
|
17
|
+
__version_tuple__: VERSION_TUPLE
|
18
|
+
version_tuple: VERSION_TUPLE
|
19
|
+
|
20
|
+
__version__ = version = '0.0.50'
|
21
|
+
__version_tuple__ = version_tuple = (0, 0, 50)
|
datastock/version.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
# Do not edit, pipeline versioning governed by git tags!
|
2
|
-
__version__ = '0.0.49'
|
2
|
+
__version__ = '0.0.49-1-g545b8a4'
|
@@ -1,33 +1,12 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: datastock
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.50
|
4
4
|
Summary: Generic handler for multiple heterogenous numpy arrays and subclasses
|
5
|
-
Home-page: https://github.com/ToFuProject/datastock
|
6
|
-
Author: Didier VEZINET
|
7
5
|
Author-email: Didier VEZINET <didier.vezinet@gmail.com>
|
8
6
|
Maintainer-email: Didier VEZINET <didier.vezinet@gmail.com>
|
9
|
-
License: MIT
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
14
|
-
of this software and associated documentation files (the "Software"), to deal
|
15
|
-
in the Software without restriction, including without limitation the rights
|
16
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17
|
-
copies of the Software, and to permit persons to whom the Software is
|
18
|
-
furnished to do so, subject to the following conditions:
|
19
|
-
|
20
|
-
The above copyright notice and this permission notice shall be included in all
|
21
|
-
copies or substantial portions of the Software.
|
22
|
-
|
23
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
24
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
25
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
26
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
28
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
29
|
-
SOFTWARE.
|
30
|
-
|
7
|
+
License: MIT
|
8
|
+
Project-URL: Homepage, https://github.com/ToFuProject/datastock
|
9
|
+
Project-URL: Issues, https://github.com/ToFuProject/datastock/issues
|
31
10
|
Keywords: data,analysis,interactive,heterogeneous arrays,numpy,Collection
|
32
11
|
Classifier: Development Status :: 5 - Production/Stable
|
33
12
|
Classifier: Intended Audience :: Science/Research
|
@@ -38,24 +17,20 @@ Classifier: Programming Language :: Python :: 3.8
|
|
38
17
|
Classifier: Programming Language :: Python :: 3.9
|
39
18
|
Classifier: Programming Language :: Python :: 3.10
|
40
19
|
Classifier: Programming Language :: Python :: 3.11
|
41
|
-
|
20
|
+
Classifier: Natural Language :: English
|
21
|
+
Requires-Python: >=3.8
|
42
22
|
Description-Content-Type: text/markdown
|
43
|
-
License-File: LICENSE
|
23
|
+
License-File: LICENSE.txt
|
44
24
|
Requires-Dist: numpy
|
45
25
|
Requires-Dist: scipy
|
46
26
|
Requires-Dist: matplotlib
|
27
|
+
Requires-Dist: PyQt5; platform_system != "Windows"
|
47
28
|
Requires-Dist: astropy
|
48
|
-
Provides-Extra: dev
|
49
|
-
Requires-Dist: check-manifest; extra == "dev"
|
50
|
-
Requires-Dist: coverage; extra == "dev"
|
51
|
-
Requires-Dist: pytest; extra == "dev"
|
52
|
-
Requires-Dist: sphinx; extra == "dev"
|
53
|
-
Requires-Dist: sphinx-gallery; extra == "dev"
|
54
|
-
Requires-Dist: sphinx-bootstrap-theme; extra == "dev"
|
55
|
-
Provides-Extra: formatting
|
56
|
-
Requires-Dist: ruff; extra == "formatting"
|
57
29
|
Provides-Extra: linting
|
58
30
|
Requires-Dist: ruff; extra == "linting"
|
31
|
+
Provides-Extra: formatting
|
32
|
+
Requires-Dist: ruff; extra == "formatting"
|
33
|
+
Dynamic: license-file
|
59
34
|
|
60
35
|
[](https://anaconda.org/conda-forge/datastock)
|
61
36
|
[](https://anaconda.org/conda-forge/datastock)
|
@@ -100,15 +75,15 @@ Examples:
|
|
100
75
|
Straightforward array visualization:
|
101
76
|
------------------------------------
|
102
77
|
|
103
|
-
|
78
|
+
``
|
104
79
|
import datastock as ds
|
105
80
|
|
106
81
|
# any 1d, 2d or 3d array
|
107
|
-
aa = np.
|
82
|
+
aa = np.random((100, 100, 100))
|
108
83
|
|
109
84
|
# plot interactive figure using shortcut to method
|
110
85
|
dax = ds.plot_as_array(aa)
|
111
|
-
|
86
|
+
``
|
112
87
|
|
113
88
|
Now do **shift + left clic** on any axes, the rest of the interactive commands are automatically printed in your python console
|
114
89
|
|
@@ -134,7 +109,7 @@ Thanks to dref, the class knows the relationaships between all numpy arrays.
|
|
134
109
|
In particular it knows which arrays share the same references / dimensions
|
135
110
|
|
136
111
|
|
137
|
-
```
|
112
|
+
```python
|
138
113
|
import numpy as np
|
139
114
|
import datastock as ds
|
140
115
|
|
@@ -155,24 +130,24 @@ lprof = [(1 + np.cos(t)[:, None]) * x[None, :] for t in lt]
|
|
155
130
|
# Populate DataStock
|
156
131
|
|
157
132
|
# instanciate
|
158
|
-
|
133
|
+
coll = ds.DataStock()
|
159
134
|
|
160
135
|
# add references (i.e.: store size of each dimension under a unique key)
|
161
|
-
|
162
|
-
|
136
|
+
coll.add_ref(key='nc', size=nc)
|
137
|
+
coll.add_ref(key='nx', size=nx)
|
163
138
|
for ii, nt in enumerate(lnt):
|
164
|
-
|
139
|
+
coll.add_ref(key=f'nt{ii}', size=nt)
|
165
140
|
|
166
141
|
# add data dependening on these references
|
167
142
|
# you can, optionally, specify units, physical dimensionality (ex: distance, time...), quantity (ex: radius, height, ...) and name (to your liking)
|
168
143
|
|
169
|
-
|
144
|
+
coll.add_data(key='x', data=x, dimension='distance', quant='radius', units='m', ref='nx')
|
170
145
|
for ii, nt in enumerate(lnt):
|
171
|
-
|
172
|
-
|
146
|
+
coll.add_data(key=f't{ii}', data=lt[ii], dimension='time', units='s', ref=f'nt{ii}')
|
147
|
+
coll.add_data(key=f'prof{ii}', data=lprof[ii], dimension='velocity', units='m/s', ref=(f'nt{ii}', 'x'))
|
173
148
|
|
174
149
|
# print in the console the content of st
|
175
|
-
|
150
|
+
coll
|
176
151
|
```
|
177
152
|
|
178
153
|
<p align="center">
|
@@ -183,22 +158,22 @@ You can see that DataStock stores the relationships between each array and each
|
|
183
158
|
Specifying explicitly the references is only necessary if there is an ambiguity (i.e.: several references have the same size, like nx and nt2 in our case)
|
184
159
|
|
185
160
|
|
186
|
-
|
161
|
+
``
|
187
162
|
# plot any array interactively
|
188
|
-
dax =
|
189
|
-
dax =
|
190
|
-
dax =
|
191
|
-
dax =
|
192
|
-
|
163
|
+
dax = coll.plot_as_array('x')
|
164
|
+
dax = coll.plot_as_array('t0')
|
165
|
+
dax = coll.plot_as_array('prof0')
|
166
|
+
dax = coll.plot_as_array('prof0', keyX='t0', keyY='x', aspect='auto')
|
167
|
+
``
|
193
168
|
|
194
169
|
You can then decide to store any object category
|
195
170
|
Let's create a 'campaign' category to store the characteristics of each measurements campaign
|
196
171
|
and let's add a 'campaign' parameter to each profile data
|
197
172
|
|
198
|
-
|
173
|
+
``
|
199
174
|
# add arbitrary object category as sub-dict of self.dobj
|
200
175
|
for ii in range(nc):
|
201
|
-
|
176
|
+
coll.add_obj(
|
202
177
|
which='campaign',
|
203
178
|
key=f'c{ii}',
|
204
179
|
start_date=f'{ii}.04.2022',
|
@@ -209,16 +184,16 @@ for ii in range(nc):
|
|
209
184
|
)
|
210
185
|
|
211
186
|
# create new 'campaign' parameter for data arrays
|
212
|
-
|
187
|
+
coll.add_param('campaign', which='data')
|
213
188
|
|
214
189
|
# tag each data with its campaign
|
215
190
|
for ii in range(nc):
|
216
|
-
|
217
|
-
|
191
|
+
coll.set_param(which='data', key=f't{ii}', param='campaign', value=f'c{ii}')
|
192
|
+
coll.set_param(which='data', key=f'prof{ii}', param='campaign', value=f'c{ii}')
|
218
193
|
|
219
194
|
# print in the console the content of st
|
220
|
-
|
221
|
-
|
195
|
+
coll
|
196
|
+
``
|
222
197
|
|
223
198
|
<p align="center">
|
224
199
|
<img align="middle" src="https://github.com/ToFuProject/datastock/blob/devel/README_figures/DataStock_Obj.png" width="600" alt="Direct 3d array visualization"/>
|
@@ -227,31 +202,31 @@ st
|
|
227
202
|
DataStock also provides built-in object selection method to allow return all
|
228
203
|
objects matching a criterion, as lits of int indices, bool indices or keys.
|
229
204
|
|
230
|
-
|
231
|
-
In [9]:
|
205
|
+
``
|
206
|
+
In [9]: coll.select(which='campaign', index=2, returnas=int)
|
232
207
|
Out[9]: array([2])
|
233
208
|
|
234
209
|
# list of 2 => return all matches inside the interval
|
235
|
-
In [10]:
|
210
|
+
In [10]: coll.select(which='campaign', index=[2, 4], returnas=int)
|
236
211
|
Out[10]: array([2, 3, 4])
|
237
212
|
|
238
213
|
# tuple of 2 => return all matches outside the interval
|
239
|
-
In [11]:
|
214
|
+
In [11]: coll.select(which='campaign', index=(2, 4), returnas=int)
|
240
215
|
Out[11]: array([0, 1])
|
241
216
|
|
242
217
|
# return as keys
|
243
|
-
In [12]:
|
218
|
+
In [12]: coll.select(which='campaign', index=(2, 4), returnas=str)
|
244
219
|
Out[12]: array(['c0', 'c1'], dtype='<U2')
|
245
220
|
|
246
221
|
# return as bool indices
|
247
|
-
In [13]:
|
222
|
+
In [13]: coll.select(which='campaign', index=(2, 4), returnas=bool)
|
248
223
|
Out[13]: array([ True, True, False, False, False])
|
249
224
|
|
250
225
|
# You can combine as many constraints as needed
|
251
|
-
In [17]:
|
226
|
+
In [17]: coll.select(which='campaign', index=[2, 4], operator='Barnaby', returnas=str)
|
252
227
|
Out[17]: array(['c3', 'c4'], dtype='<U2')
|
253
228
|
|
254
|
-
|
229
|
+
``
|
255
230
|
|
256
231
|
You can also decide to sub-class DataStock to implement methods and visualizations specific to your needs
|
257
232
|
|
@@ -264,6 +239,6 @@ DataStock provides built-in methods like:
|
|
264
239
|
- size is the total size of all data stored in the instance in bytes
|
265
240
|
- dsize is a dict with the detail (size for each item in each sub-dict of the instance)
|
266
241
|
* `save()`: will save the instance
|
267
|
-
* `
|
242
|
+
* `coll.load()`: will load a saved instance
|
268
243
|
|
269
244
|
|
@@ -1,6 +1,5 @@
|
|
1
|
-
_updateversion.py,sha256=OR6OJJozaHWzu7NWjKu5ERi0IyYqR61KrWvzf7kfoto,951
|
2
1
|
datastock/_DataCollection_utils.py,sha256=hHf6HvGKMmM-psx3fj9QcY1TEmKrAtTdkRokH7SFqoo,7143
|
3
|
-
datastock/__init__.py,sha256=
|
2
|
+
datastock/__init__.py,sha256=LLPm4DAkXl5xYAQT4jUfQd5ZAmYx5w2nBSBmjN2XhdE,598
|
4
3
|
datastock/_class.py,sha256=Az9PS3aSskiPMb1ekt78Y2ynBujYVc_cDjJxW9xH9g4,47
|
5
4
|
datastock/_class0.py,sha256=je4ckTynK8lEGBa7OSURYZZ_-3XjzAtf6SazN3b-f5k,6028
|
6
5
|
datastock/_class1.py,sha256=2PrIT26yRfNrP6YmZMpvb0_b0v_397Y9tOjzeVOxK_I,29313
|
@@ -32,17 +31,15 @@ datastock/_plot_correlations.py,sha256=ITOypu_AEoKl0ihxocV-JVTXIHqut6p9TfG-xZmQy
|
|
32
31
|
datastock/_plot_old_backup.py,sha256=XixTi2CiihKjtQP0TRycH0b25caWN1m35DgpsDeiWZE,21729
|
33
32
|
datastock/_plot_text.py,sha256=wQPqjfpLyIioS2JeOt3E9C9HgYUJ49YEoOgRuKYvAR8,3143
|
34
33
|
datastock/_saveload.py,sha256=1vAMp27KfqXbo5b_Pi8hJux0stsHq6dO5vy8k1d4_iA,14141
|
35
|
-
datastock/
|
34
|
+
datastock/_version.py,sha256=E35Bq14aHx0dG_mA8HPiJoVRTCMU_V3unyyjRET8Kww,513
|
35
|
+
datastock/version.py,sha256=VJcnSK0zygwEhh_p6KIoC9yiMkp0bs-SJgLCbyubs9o,91
|
36
36
|
datastock/tests/__init__.py,sha256=teOo2xP0IO7PQMuMDmum61XVHe2TuxW3BiHiL73X8jQ,35
|
37
|
+
datastock/tests/prepublish.py,sha256=3gSr3nRhEl5qsmhxJ-nEoePvbINYq0EvcZCfxfUVHBM,83
|
37
38
|
datastock/tests/test_01_DataStock.py,sha256=aUseXH2zYnFtNDJSCuEROgPxfKKNeLCkCQSR--_Fheg,19176
|
38
39
|
datastock/tests/output/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
datastock-0.0.
|
44
|
-
datastock-0.0.
|
45
|
-
datastock-0.0.49.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
46
|
-
datastock-0.0.49.dist-info/entry_points.txt,sha256=GqmxVVp9G2ulEDaS9gLpwSVOBLF_FEBlj8k5Z6TJKsc,42
|
47
|
-
datastock-0.0.49.dist-info/top_level.txt,sha256=4mahLJQfvNnKq213ODWrMXeNzyoyjzRRke_OAw07iA8,33
|
48
|
-
datastock-0.0.49.dist-info/RECORD,,
|
40
|
+
datastock-0.0.50.dist-info/licenses/LICENSE.txt,sha256=SM-QOA3JwR1e0RVBGb1HhPmc5yD1Gsl1CRPnMSKJhH8,1068
|
41
|
+
datastock-0.0.50.dist-info/METADATA,sha256=FLc5tLiMeT7uqPs9_kNV3tZNALar_DErqHZeO0uql68,8893
|
42
|
+
datastock-0.0.50.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
43
|
+
datastock-0.0.50.dist-info/entry_points.txt,sha256=GqmxVVp9G2ulEDaS9gLpwSVOBLF_FEBlj8k5Z6TJKsc,42
|
44
|
+
datastock-0.0.50.dist-info/top_level.txt,sha256=0HeA0gZ4G1IKtkPhmqijZRYH9hID6LKLQskeSjAna8g,10
|
45
|
+
datastock-0.0.50.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
datastock
|
_updateversion.py
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
#!/usr/bin/env/python
|
2
|
-
# coding=utf-8
|
3
|
-
|
4
|
-
|
5
|
-
import os
|
6
|
-
import subprocess
|
7
|
-
|
8
|
-
|
9
|
-
_HERE = os.path.abspath(os.path.dirname(__file__))
|
10
|
-
|
11
|
-
|
12
|
-
def updateversion(path=_HERE):
|
13
|
-
|
14
|
-
# Fetch version from git tags, and write to version.py
|
15
|
-
# Also, when git is not available (PyPi package), use stored version.py
|
16
|
-
version_py = os.path.join(path, 'datastock', 'version.py')
|
17
|
-
try:
|
18
|
-
version_git = subprocess.check_output(
|
19
|
-
["git", "describe"]
|
20
|
-
).rstrip().decode()
|
21
|
-
|
22
|
-
except subprocess.CalledProcessError:
|
23
|
-
with open(version_py, 'r') as fh:
|
24
|
-
version_git = fh.read().strip().split("=")[-1].replace("'", '')
|
25
|
-
|
26
|
-
version_git = version_git.lower().replace('v', '').replace(' ', '')
|
27
|
-
|
28
|
-
version_msg = "# Do not edit, pipeline versioning governed by git tags!"
|
29
|
-
with open(version_py, "w") as fh:
|
30
|
-
msg = "{0}__version__ = '{1}'{0}".format(os.linesep, version_git)
|
31
|
-
fh.write(version_msg + msg)
|
32
|
-
return version_git
|
scripts/__init__.py
DELETED
File without changes
|
scripts/_bash_version.py
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
|
3
|
-
# Built-in
|
4
|
-
import os
|
5
|
-
|
6
|
-
|
7
|
-
###################################################
|
8
|
-
###################################################
|
9
|
-
# DEFAULTS
|
10
|
-
###################################################
|
11
|
-
|
12
|
-
|
13
|
-
_PATH_HERE = os.path.dirname(__file__)
|
14
|
-
|
15
|
-
|
16
|
-
###################################################
|
17
|
-
###################################################
|
18
|
-
# function
|
19
|
-
###################################################
|
20
|
-
|
21
|
-
|
22
|
-
def main(
|
23
|
-
verb=None,
|
24
|
-
envvar=None,
|
25
|
-
path=None,
|
26
|
-
warn=None,
|
27
|
-
force=None,
|
28
|
-
ddef=None,
|
29
|
-
):
|
30
|
-
""" Print version """
|
31
|
-
|
32
|
-
# --------------
|
33
|
-
# Check inputs
|
34
|
-
# --------------
|
35
|
-
|
36
|
-
kwd = locals()
|
37
|
-
for k0 in set(ddef.keys()).intersection(kwd.keys()):
|
38
|
-
if kwd[k0] is None:
|
39
|
-
kwd[k0] = ddef[k0]
|
40
|
-
verb, path = kwd['verb'], kwd['path']
|
41
|
-
|
42
|
-
# verb, warn, force
|
43
|
-
dbool = {'verb': verb}
|
44
|
-
for k0, v0 in dbool.items():
|
45
|
-
if v0 is None:
|
46
|
-
dbool[k0] = ddef[k0]
|
47
|
-
if not isinstance(dbool[k0], bool):
|
48
|
-
msg = (
|
49
|
-
f"Arg '{k0}' must be a bool\n"
|
50
|
-
f"\t- provided: {dbool[k0]}\n"
|
51
|
-
)
|
52
|
-
raise Exception(msg)
|
53
|
-
|
54
|
-
# --------------
|
55
|
-
# Fetch version from git tags, and write to version.py
|
56
|
-
# Also, when git is not available (PyPi package), use stored version.py
|
57
|
-
|
58
|
-
pfe = os.path.join(path, 'version.py')
|
59
|
-
if not os.path.isfile(pfe):
|
60
|
-
msg = (
|
61
|
-
"It seems your current install has no version.py:\n"
|
62
|
-
f"\t- looked for: {pfe}"
|
63
|
-
)
|
64
|
-
raise Exception(msg)
|
65
|
-
|
66
|
-
# --------------
|
67
|
-
# Read file
|
68
|
-
|
69
|
-
with open(pfe, 'r') as fh:
|
70
|
-
version = fh.read().strip().split("=")[-1].replace("'", '')
|
71
|
-
version = version.lower().replace('v', '').replace(' ', '')
|
72
|
-
|
73
|
-
# --------------
|
74
|
-
# Outputs
|
75
|
-
|
76
|
-
if dbool['verb'] is True:
|
77
|
-
print(version)
|
scripts/_dparser.py
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
import sys
|
2
|
-
import os
|
3
|
-
import getpass
|
4
|
-
import argparse
|
5
|
-
|
6
|
-
|
7
|
-
# test if in a git repo
|
8
|
-
_HERE = os.path.abspath(os.path.dirname(__file__))
|
9
|
-
_REPOPATH = os.path.dirname(_HERE)
|
10
|
-
_REPO_NAME = 'datastock'
|
11
|
-
|
12
|
-
|
13
|
-
# #############################################################################
|
14
|
-
# utility functions
|
15
|
-
# #############################################################################
|
16
|
-
|
17
|
-
|
18
|
-
def _str2bool(v):
|
19
|
-
if isinstance(v, bool):
|
20
|
-
return v
|
21
|
-
elif v.lower() in ['yes', 'true', 'y', 't', '1']:
|
22
|
-
return True
|
23
|
-
elif v.lower() in ['no', 'false', 'n', 'f', '0']:
|
24
|
-
return False
|
25
|
-
else:
|
26
|
-
raise argparse.ArgumentTypeError('Boolean value expected!')
|
27
|
-
|
28
|
-
|
29
|
-
def _str2boolstr(v):
|
30
|
-
if isinstance(v, bool):
|
31
|
-
return v
|
32
|
-
elif isinstance(v, str):
|
33
|
-
if v.lower() in ['yes', 'true', 'y', 't', '1']:
|
34
|
-
return True
|
35
|
-
elif v.lower() in ['no', 'false', 'n', 'f', '0']:
|
36
|
-
return False
|
37
|
-
elif v.lower() == 'none':
|
38
|
-
return None
|
39
|
-
else:
|
40
|
-
return v
|
41
|
-
else:
|
42
|
-
raise argparse.ArgumentTypeError('Boolean, None or str expected!')
|
43
|
-
|
44
|
-
|
45
|
-
def _str2tlim(v):
|
46
|
-
c0 = (v.isdigit()
|
47
|
-
or ('.' in v
|
48
|
-
and len(v.split('.')) == 2
|
49
|
-
and all([vv.isdigit() for vv in v.split('.')])))
|
50
|
-
if c0 is True:
|
51
|
-
v = float(v)
|
52
|
-
elif v.lower() == 'none':
|
53
|
-
v = None
|
54
|
-
return v
|
55
|
-
|
56
|
-
|
57
|
-
# #############################################################################
|
58
|
-
# Parser for version
|
59
|
-
# #############################################################################
|
60
|
-
|
61
|
-
|
62
|
-
def parser_version():
|
63
|
-
msg = f""" Get {_REPO_NAME} version from bash
|
64
|
-
|
65
|
-
If run from a git repo containing {_REPO_NAME}, just returns git describe
|
66
|
-
Otherwise reads the version stored in {_REPO_NAME}/version.py
|
67
|
-
|
68
|
-
"""
|
69
|
-
ddef = {
|
70
|
-
'path': os.path.join(_REPOPATH, _REPO_NAME),
|
71
|
-
'envvar': False,
|
72
|
-
'verb': True,
|
73
|
-
'warn': True,
|
74
|
-
'force': False,
|
75
|
-
'name': f'{_REPO_NAME.upper()}_VERSION',
|
76
|
-
}
|
77
|
-
|
78
|
-
# Instanciate parser
|
79
|
-
parser = argparse.ArgumentParser(description=msg)
|
80
|
-
|
81
|
-
# optional path
|
82
|
-
parser.add_argument(
|
83
|
-
'-p', '--path',
|
84
|
-
type=str,
|
85
|
-
help='source directory where version.py is found',
|
86
|
-
required=False,
|
87
|
-
default=ddef['path'],
|
88
|
-
)
|
89
|
-
|
90
|
-
# verb
|
91
|
-
parser.add_argument(
|
92
|
-
'-v', '--verb',
|
93
|
-
type=_str2bool,
|
94
|
-
help='flag indicating whether to print the version',
|
95
|
-
required=False,
|
96
|
-
default=ddef['verb'],
|
97
|
-
)
|
98
|
-
|
99
|
-
return ddef, parser
|
100
|
-
|
101
|
-
|
102
|
-
# #############################################################################
|
103
|
-
# Parser dict
|
104
|
-
# #############################################################################
|
105
|
-
|
106
|
-
|
107
|
-
_DPARSER = {
|
108
|
-
'version': parser_version,
|
109
|
-
}
|
scripts/main.py
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
|
3
|
-
# Built-in
|
4
|
-
import sys
|
5
|
-
import os
|
6
|
-
import argparse
|
7
|
-
|
8
|
-
|
9
|
-
# import parser dicti
|
10
|
-
from . import _dparser
|
11
|
-
from . import _bash_version
|
12
|
-
|
13
|
-
|
14
|
-
###################################################
|
15
|
-
###################################################
|
16
|
-
# default values
|
17
|
-
###################################################
|
18
|
-
|
19
|
-
|
20
|
-
_PATH_HERE = os.path.abspath(os.path.dirname(__file__))
|
21
|
-
|
22
|
-
|
23
|
-
_LOPTIONS = ['--version']
|
24
|
-
_LOPSTRIP = [ss.strip('--') for ss in _LOPTIONS]
|
25
|
-
|
26
|
-
|
27
|
-
###################################################
|
28
|
-
###################################################
|
29
|
-
# function
|
30
|
-
###################################################
|
31
|
-
|
32
|
-
|
33
|
-
def datastock_bash(option=None, ddef=None, **kwdargs):
|
34
|
-
""" Print tofu version and / or store in environment variable """
|
35
|
-
|
36
|
-
# --------------
|
37
|
-
# Check inputs
|
38
|
-
# --------------
|
39
|
-
|
40
|
-
if option not in _LOPSTRIP:
|
41
|
-
msg = (
|
42
|
-
"Provided option is not acceptable:\n"
|
43
|
-
f"\t- available: {_LOPSTRIP}\n"
|
44
|
-
f"\t- provided: {option}"
|
45
|
-
)
|
46
|
-
raise Exception(msg)
|
47
|
-
|
48
|
-
# --------------
|
49
|
-
# call corresponding bash command
|
50
|
-
# --------------
|
51
|
-
|
52
|
-
if option == 'version':
|
53
|
-
_bash_version.main(
|
54
|
-
ddef=ddef,
|
55
|
-
**kwdargs,
|
56
|
-
)
|
57
|
-
|
58
|
-
|
59
|
-
###################################################
|
60
|
-
###################################################
|
61
|
-
# main
|
62
|
-
###################################################
|
63
|
-
|
64
|
-
|
65
|
-
def main():
|
66
|
-
# Parse input arguments
|
67
|
-
msg = """ Get tofu version from bash optionally set an enviroment variable
|
68
|
-
|
69
|
-
If run from a git repo containing tofu, simply returns git describe
|
70
|
-
Otherwise reads the tofu version stored in tofu/version.py
|
71
|
-
|
72
|
-
"""
|
73
|
-
|
74
|
-
# ------------------
|
75
|
-
# Instanciate parser
|
76
|
-
# ------------------
|
77
|
-
|
78
|
-
parser = argparse.ArgumentParser(description=msg)
|
79
|
-
|
80
|
-
# ---------------------
|
81
|
-
# which script to call
|
82
|
-
# ---------------------
|
83
|
-
|
84
|
-
parser.add_argument(
|
85
|
-
'option',
|
86
|
-
nargs='?',
|
87
|
-
type=str,
|
88
|
-
default='None',
|
89
|
-
)
|
90
|
-
|
91
|
-
#
|
92
|
-
parser.add_argument(
|
93
|
-
'-v', '--version',
|
94
|
-
help='get tofu current version',
|
95
|
-
required=False,
|
96
|
-
action='store_true',
|
97
|
-
)
|
98
|
-
|
99
|
-
# Others
|
100
|
-
# parser.add_argument('kwd', nargs='?', type=str, default='None')
|
101
|
-
|
102
|
-
# -------------------
|
103
|
-
# check options
|
104
|
-
# -------------------
|
105
|
-
|
106
|
-
if sys.argv[1] not in _LOPTIONS:
|
107
|
-
msg = (
|
108
|
-
"Provided option is not acceptable:\n"
|
109
|
-
f"\t- available: {_LOPTIONS}\n"
|
110
|
-
f"\t- provided: {sys.argv[1]}\n"
|
111
|
-
)
|
112
|
-
raise Exception(msg)
|
113
|
-
|
114
|
-
if len(sys.argv) > 2:
|
115
|
-
if any([ss in sys.argv[2:] for ss in _LOPTIONS]):
|
116
|
-
lopt = [ss for ss in sys.argv[1:] if ss in _LOPTIONS]
|
117
|
-
msg = (
|
118
|
-
"Only one option can be provided!\n"
|
119
|
-
f"\t- provided: {lopt}"
|
120
|
-
)
|
121
|
-
raise Exception(msg)
|
122
|
-
|
123
|
-
# ----------------------
|
124
|
-
# def values and parser
|
125
|
-
# ----------------------
|
126
|
-
|
127
|
-
option = sys.argv[1].strip('--')
|
128
|
-
ddef, parser = _dparser._DPARSER[option]()
|
129
|
-
if len(sys.argv) > 2:
|
130
|
-
kwdargs = dict(parser.parse_args(sys.argv[2:])._get_kwargs())
|
131
|
-
else:
|
132
|
-
kwdargs = {}
|
133
|
-
|
134
|
-
# ----------------------
|
135
|
-
# Call function
|
136
|
-
# ----------------------
|
137
|
-
|
138
|
-
datastock_bash(option=option, ddef=ddef, **kwdargs)
|
139
|
-
|
140
|
-
|
141
|
-
###################################################
|
142
|
-
###################################################
|
143
|
-
# __main__
|
144
|
-
###################################################
|
145
|
-
|
146
|
-
if __name__ == '__main__':
|
147
|
-
main()
|
File without changes
|