Skip to content

Commit e03d2f9

Browse files
authored
Merge pull request #210 from ToFuProject/Issue187_pyprojecttoml
[#187] Minor fixes
2 parents 92aeed2 + 4a2992e commit e03d2f9

File tree

7 files changed

+375
-61
lines changed

7 files changed

+375
-61
lines changed

datastock/_generic_check.py

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,6 @@ def _check_dict_valid_keys(
362362
var[k0] = None
363363
continue
364364

365-
vv = var.get(k0)
366-
367365
# routine to call
368366
if any([ss in v0.keys() for ss in lkarray]):
369367
var[k0] = _check_flat1darray(
@@ -610,7 +608,7 @@ def _check_all_broadcastable(
610608
ndim = lndim[0]
611609

612610
else:
613-
lstr = [f"-t {k0}: {v0}" for k0, v0 in dndim.items()]
611+
lstr = [f"\t- {k0}: {v0}" for k0, v0 in dndim.items()]
614612
msg = (
615613
"Some keyword args have non-compatible dimensions:\n"
616614
+ "\n".join(lstr)
@@ -675,48 +673,6 @@ def _check_all_broadcastable(
675673
# Utilities for plotting
676674
# #############################################################################
677675

678-
# DEPRECATED
679-
# def _check_inplace(coll=None, keys=None):
680-
# """ Check key to data and inplace """
681-
682-
# # -----------------------------
683-
# # keys of data to be extracted
684-
# # ----------------------------
685-
686-
# if isinstance(keys, str):
687-
# keys = [keys]
688-
# keys = _check_var_iter(
689-
# keys, 'keys',
690-
# default=None,
691-
# types=list,
692-
# types_iter=str,
693-
# allowed=list(coll.ddata.keys()),
694-
# )
695-
696-
# # ----------------------
697-
# # extract sub-collection
698-
# # ----------------------
699-
700-
# lk0 = list(keys)
701-
# for key in keys:
702-
703-
# # Include all data matching any single ref
704-
# for rr in coll._ddata[key]['ref']:
705-
# for k0, v0 in coll._ddata.items():
706-
# if v0['ref'] == (rr,):
707-
# if k0 not in lk0:
708-
# lk0.append(k0)
709-
710-
# # include all data matching all refs
711-
# for k0, v0 in coll._ddata.items():
712-
# if v0['ref'] == coll._ddata[key]['ref']:
713-
# if k0 not in lk0:
714-
# lk0.append(k0)
715-
716-
# coll2 = coll.extract(lk0)
717-
718-
# return keys, coll2
719-
720676

721677
def _check_dax(dax=None, main=None):
722678

@@ -844,7 +800,7 @@ def _check_lim(lim):
844800
if len(dfail) > 0:
845801
lstr = [f"\t- lim[{ii}]: {vv}" for ii, vv in dfail.items()]
846802
msg = (
847-
"The following non-conformities in lim have been identified:\n"*
803+
"The following non-conformities in lim have been identified:\n"
848804
+ "\n".join(lstr)
849805
)
850806
raise Exception(msg)
@@ -900,7 +856,6 @@ def _apply_lim(lim=None, data=None, logic=None):
900856
return ind
901857

902858

903-
904859
def _apply_dlim(dlim=None, logic_intervals=None, logic=None, ddata=None):
905860

906861
# ------------
@@ -960,6 +915,7 @@ def _apply_dlim(dlim=None, logic_intervals=None, logic=None, ddata=None):
960915
lstr = [f"\t- {k0}: {v0}" for k0, v0 in dfail.items()]
961916
msg = (
962917
"The following keys have non-compatible shapes:\n"
918+
+ "\n".join(lstr)
963919
)
964920
raise Exception(msg)
965921

@@ -1021,11 +977,6 @@ def _apply_dlim(dlim=None, logic_intervals=None, logic=None, ddata=None):
1021977

1022978
def _check_cmap_vminvmax(data=None, cmap=None, vmin=None, vmax=None):
1023979
# cmap
1024-
c0 = (
1025-
cmap is None
1026-
or vmin is None
1027-
or vmax is None
1028-
)
1029980
if cmap is None or vmin is None or vmax is None:
1030981
nanmax = np.nanmax(data)
1031982
nanmin = np.nanmin(data)

pyproject.toml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
1+
[project]
2+
name = "datastock"
3+
version = "0.0.47"
4+
description = "Generic handler for multiple heterogenous numpy arrays and subclasses"
5+
readme = "README.md"
6+
requires-python = ">=3.6"
7+
dependencies = [
8+
"numpy",
9+
"scipy",
10+
"matplotlib",
11+
"astropy",
12+
]
13+
14+
115
[build-system]
2-
requires = ["setuptools>=40.8.0",
3-
"wheel",
4-
]
16+
requires = [
17+
"setuptools>=40.8.0, <64",
18+
"wheel",
19+
"Cython>=0.26",
20+
"numpy",
21+
]
22+
23+
[dependency-groups]
24+
dev = [
25+
"pytest",
26+
]
27+
28+
29+
[project.scripts]
30+
datastock = "scripts.main:main"

scripts/__init__.py

Whitespace-only changes.

scripts/_bash_version.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
}

0 commit comments

Comments
 (0)