data-manipulation-utilities 0.2.3__py3-none-any.whl → 0.2.4__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.
- {data_manipulation_utilities-0.2.3.dist-info → data_manipulation_utilities-0.2.4.dist-info}/METADATA +35 -1
- {data_manipulation_utilities-0.2.3.dist-info → data_manipulation_utilities-0.2.4.dist-info}/RECORD +7 -6
- dmu/generic/version_management.py +132 -0
- {data_manipulation_utilities-0.2.3.data → data_manipulation_utilities-0.2.4.data}/scripts/publish +0 -0
- {data_manipulation_utilities-0.2.3.dist-info → data_manipulation_utilities-0.2.4.dist-info}/WHEEL +0 -0
- {data_manipulation_utilities-0.2.3.dist-info → data_manipulation_utilities-0.2.4.dist-info}/entry_points.txt +0 -0
- {data_manipulation_utilities-0.2.3.dist-info → data_manipulation_utilities-0.2.4.dist-info}/top_level.txt +0 -0
{data_manipulation_utilities-0.2.3.dist-info → data_manipulation_utilities-0.2.4.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: data_manipulation_utilities
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.4
|
4
4
|
Description-Content-Type: text/markdown
|
5
5
|
Requires-Dist: logzero
|
6
6
|
Requires-Dist: PyYAML
|
@@ -856,6 +856,40 @@ Trees only in file_2.root:
|
|
856
856
|
- Hlt2RD_BsToPhiMuMu_MVA/DecayTree
|
857
857
|
```
|
858
858
|
|
859
|
+
# File system
|
860
|
+
|
861
|
+
## Versions
|
862
|
+
|
863
|
+
The utilities below allow the user to deal with versioned files and directories
|
864
|
+
|
865
|
+
```python
|
866
|
+
from dmu.generic.version_management import get_last_version
|
867
|
+
from dmu.generic.version_management import get_next_version
|
868
|
+
from dmu.generic.version_management import get_latest_file
|
869
|
+
|
870
|
+
# get_next_version will take a version and provide the next one, e.g.
|
871
|
+
get_next_version('v1') # -> 'v2'
|
872
|
+
get_next_version('v1.1') # -> 'v2.1'
|
873
|
+
get_next_version('v10.1') # -> 'v11.1'
|
874
|
+
|
875
|
+
get_next_version('/a/b/c/v1') # -> '/a/b/c/v2'
|
876
|
+
get_next_version('/a/b/c/v1.1') # -> '/a/b/c/v2.1'
|
877
|
+
get_next_version('/a/b/c/v10.1') # -> '/a/b/c/v11.1'
|
878
|
+
|
879
|
+
# `get_latest_file` will return the path to the file with the highest version
|
880
|
+
# in the `dir_path` directory that matches a wildcard, e.g.:
|
881
|
+
|
882
|
+
last_file = get_latest_file(dir_path = file_dir, wc='name_*.txt')
|
883
|
+
|
884
|
+
# `get_last_version` will return the string with the latest version
|
885
|
+
# of directories in `dir_path`, e.g.:
|
886
|
+
|
887
|
+
oversion=get_last_version(dir_path=dir_path, version_only=True) # This will return only the version, e.g. v3.2
|
888
|
+
oversion=get_last_version(dir_path=dir_path, version_only=False) # This will return full path, e.g. /a/b/c/v3.2
|
889
|
+
```
|
890
|
+
|
891
|
+
The function above should work for numeric (e.g. `v1.2`) and non-numeric (e.g. `va`, `vb`) versions.
|
892
|
+
|
859
893
|
# Text manipulation
|
860
894
|
|
861
895
|
## Transformations
|
{data_manipulation_utilities-0.2.3.dist-info → data_manipulation_utilities-0.2.4.dist-info}/RECORD
RENAMED
@@ -1,6 +1,7 @@
|
|
1
|
-
data_manipulation_utilities-0.2.
|
1
|
+
data_manipulation_utilities-0.2.4.data/scripts/publish,sha256=-3K_Y2_4CfWCV50rPB8CRuhjxDu7xMGswinRwPovgLs,1976
|
2
2
|
dmu/arrays/utilities.py,sha256=PKoYyybPptA2aU-V3KLnJXBudWxTXu4x1uGdIMQ49HY,1722
|
3
3
|
dmu/generic/utilities.py,sha256=0Xnq9t35wuebAqKxbyAiMk1ISB7IcXK4cFH25MT1fgw,1741
|
4
|
+
dmu/generic/version_management.py,sha256=G_HjGY-hu8lotZuTdVAg0B8yD0AltE866q2vJxvTg1g,3749
|
4
5
|
dmu/logging/log_store.py,sha256=umdvjNDuV3LdezbG26b0AiyTglbvkxST19CQu9QATbA,4184
|
5
6
|
dmu/ml/cv_classifier.py,sha256=8Jwx6xMhJaRLktlRdq0tFl32v6t8i63KmpxrlnXlomU,3759
|
6
7
|
dmu/ml/cv_predict.py,sha256=4G7F_1yOvnLftsDC6zUpdvkxuHXGkPemhj0RsYySYDM,6708
|
@@ -47,8 +48,8 @@ dmu_scripts/rfile/compare_root_files.py,sha256=T8lDnQxsRNMr37x1Y7YvWD8ySHrJOWZki
|
|
47
48
|
dmu_scripts/rfile/print_trees.py,sha256=Ze4Ccl_iUldl4eVEDVnYBoe4amqBT1fSBR1zN5WSztk,941
|
48
49
|
dmu_scripts/ssh/coned.py,sha256=lhilYNHWRCGxC-jtyJ3LQ4oUgWW33B2l1tYCcyHHsR0,4858
|
49
50
|
dmu_scripts/text/transform_text.py,sha256=9akj1LB0HAyopOvkLjNOJiptZw5XoOQLe17SlcrGMD0,1456
|
50
|
-
data_manipulation_utilities-0.2.
|
51
|
-
data_manipulation_utilities-0.2.
|
52
|
-
data_manipulation_utilities-0.2.
|
53
|
-
data_manipulation_utilities-0.2.
|
54
|
-
data_manipulation_utilities-0.2.
|
51
|
+
data_manipulation_utilities-0.2.4.dist-info/METADATA,sha256=Gc-ZuL88YHEK3pOK1IfQmaN6rKCcVVqrFS2VlT70jyk,29229
|
52
|
+
data_manipulation_utilities-0.2.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
53
|
+
data_manipulation_utilities-0.2.4.dist-info/entry_points.txt,sha256=1TIZDed651KuOH-DgaN5AoBdirKmrKE_oM1b6b7zTUU,270
|
54
|
+
data_manipulation_utilities-0.2.4.dist-info/top_level.txt,sha256=n_x5J6uWtSqy9mRImKtdA2V2NJNyU8Kn3u8DTOKJix0,25
|
55
|
+
data_manipulation_utilities-0.2.4.dist-info/RECORD,,
|
@@ -0,0 +1,132 @@
|
|
1
|
+
'''
|
2
|
+
Module containing functions used to find latest, next version, etc of a path.
|
3
|
+
'''
|
4
|
+
|
5
|
+
import glob
|
6
|
+
import os
|
7
|
+
import re
|
8
|
+
|
9
|
+
from dmu.logging.log_store import LogStore
|
10
|
+
|
11
|
+
log=LogStore.add_logger('dmu:version_management')
|
12
|
+
#---------------------------------------
|
13
|
+
def _get_numeric_version(version : str) -> int:
|
14
|
+
'''
|
15
|
+
Takes string with numbers at the end (padded or not)
|
16
|
+
Returns integer version of numbers
|
17
|
+
'''
|
18
|
+
#Skip these directories
|
19
|
+
if version in ['__pycache__']:
|
20
|
+
return -1
|
21
|
+
|
22
|
+
regex=r'[a-z]+(\d+)'
|
23
|
+
mtch =re.match(regex, version)
|
24
|
+
if not mtch:
|
25
|
+
log.debug(f'Cannot extract numeric version from: {version}')
|
26
|
+
return -1
|
27
|
+
|
28
|
+
str_val = mtch.group(1)
|
29
|
+
val = int(str_val)
|
30
|
+
|
31
|
+
return val
|
32
|
+
#---------------------------------------
|
33
|
+
def get_last_version(dir_path : str, version_only : bool = True, main_only : bool = False):
|
34
|
+
'''Returns path or just version associated to latest version found in given path
|
35
|
+
|
36
|
+
Parameters
|
37
|
+
---------------------
|
38
|
+
dir_path (str) : Path to directory where versioned subdirectories exist
|
39
|
+
version_only (bool): Returns only vxxxx if True, otherwise, full path to directory
|
40
|
+
main_only (bool): Returns vX where X is a number. Otherwise it will return vx.y in case version has subversion
|
41
|
+
'''
|
42
|
+
l_obj = glob.glob(f'{dir_path}/*')
|
43
|
+
|
44
|
+
if len(l_obj) == 0:
|
45
|
+
log.error(f'Nothing found in {dir_path}')
|
46
|
+
raise ValueError
|
47
|
+
|
48
|
+
d_dir_org = { os.path.basename(obj).replace('.', '') : obj for obj in l_obj if os.path.isdir(obj) }
|
49
|
+
d_dir_num = { _get_numeric_version(name) : dir_path for name, dir_path in d_dir_org.items() }
|
50
|
+
|
51
|
+
c_dir = sorted(d_dir_num.items())
|
52
|
+
|
53
|
+
try:
|
54
|
+
_, path = c_dir[-1]
|
55
|
+
except:
|
56
|
+
log.error(f'Cannot find path in: {dir_path}')
|
57
|
+
raise
|
58
|
+
|
59
|
+
name = os.path.basename(path)
|
60
|
+
dirn = os.path.dirname(path)
|
61
|
+
|
62
|
+
if main_only and '.' in name:
|
63
|
+
ind = name.index('.')
|
64
|
+
name= name[:ind]
|
65
|
+
|
66
|
+
if version_only:
|
67
|
+
return name
|
68
|
+
|
69
|
+
return f'{dirn}/{name}'
|
70
|
+
#---------------------------------------
|
71
|
+
def get_latest_file(dir_path : str, wc : str) -> str:
|
72
|
+
'''Will find latest file in a given directory
|
73
|
+
|
74
|
+
Parameters
|
75
|
+
--------------------
|
76
|
+
dir_path (str): Directory where files are found
|
77
|
+
wc (str): Wildcard associated to files, e.g. file_*.txt
|
78
|
+
|
79
|
+
Returns
|
80
|
+
--------------------
|
81
|
+
Path to latest file, according to version
|
82
|
+
'''
|
83
|
+
l_path = glob.glob(f'{dir_path}/{wc}')
|
84
|
+
if len(l_path) == 0:
|
85
|
+
log.error(f'Cannot find files in: {dir_path}/{wc}')
|
86
|
+
raise ValueError
|
87
|
+
|
88
|
+
l_path.sort()
|
89
|
+
|
90
|
+
return l_path[-1]
|
91
|
+
#---------------------------------------
|
92
|
+
def get_next_version(version : str) -> str:
|
93
|
+
'''Pick up string symbolizing version and return next version
|
94
|
+
Parameters
|
95
|
+
-------------------------
|
96
|
+
version (str) : Of the form vx.y or vx where x and y are integers. It can also be a full path
|
97
|
+
|
98
|
+
Returns
|
99
|
+
-------------------------
|
100
|
+
String equal to the argument, but with the main version augmented by 1, e.g. vx+1.y
|
101
|
+
|
102
|
+
Examples:
|
103
|
+
-------------------------
|
104
|
+
|
105
|
+
get_next_version('v1.1') = 'v2.1'
|
106
|
+
get_next_version('v1' ) = 'v2'
|
107
|
+
'''
|
108
|
+
if '/' in version:
|
109
|
+
path = version
|
110
|
+
dirname = os.path.dirname(path)
|
111
|
+
version = os.path.basename(path)
|
112
|
+
else:
|
113
|
+
dirname = None
|
114
|
+
|
115
|
+
rgx = r'v(\d+)(\.\d+)?'
|
116
|
+
|
117
|
+
mtch = re.match(rgx, version)
|
118
|
+
if not mtch:
|
119
|
+
log.error(f'Cannot match {version} with {rgx}')
|
120
|
+
raise ValueError
|
121
|
+
|
122
|
+
ver_org = mtch.group(1)
|
123
|
+
ver_nxt = int(ver_org) + 1
|
124
|
+
ver_nxt = str(ver_nxt)
|
125
|
+
|
126
|
+
version = version.replace(f'v{ver_org}', f'v{ver_nxt}')
|
127
|
+
|
128
|
+
if dirname is not None:
|
129
|
+
version = f'{dirname}/{version}'
|
130
|
+
|
131
|
+
return version
|
132
|
+
#---------------------------------------
|
{data_manipulation_utilities-0.2.3.data → data_manipulation_utilities-0.2.4.data}/scripts/publish
RENAMED
File without changes
|
{data_manipulation_utilities-0.2.3.dist-info → data_manipulation_utilities-0.2.4.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|
File without changes
|