Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 3 additions & 52 deletions datastock/_generic_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,6 @@ def _check_dict_valid_keys(
var[k0] = None
continue

vv = var.get(k0)

# routine to call
if any([ss in v0.keys() for ss in lkarray]):
var[k0] = _check_flat1darray(
Expand Down Expand Up @@ -610,7 +608,7 @@ def _check_all_broadcastable(
ndim = lndim[0]

else:
lstr = [f"-t {k0}: {v0}" for k0, v0 in dndim.items()]
lstr = [f"\t- {k0}: {v0}" for k0, v0 in dndim.items()]
msg = (
"Some keyword args have non-compatible dimensions:\n"
+ "\n".join(lstr)
Expand Down Expand Up @@ -675,48 +673,6 @@ def _check_all_broadcastable(
# Utilities for plotting
# #############################################################################

# DEPRECATED
# def _check_inplace(coll=None, keys=None):
# """ Check key to data and inplace """

# # -----------------------------
# # keys of data to be extracted
# # ----------------------------

# if isinstance(keys, str):
# keys = [keys]
# keys = _check_var_iter(
# keys, 'keys',
# default=None,
# types=list,
# types_iter=str,
# allowed=list(coll.ddata.keys()),
# )

# # ----------------------
# # extract sub-collection
# # ----------------------

# lk0 = list(keys)
# for key in keys:

# # Include all data matching any single ref
# for rr in coll._ddata[key]['ref']:
# for k0, v0 in coll._ddata.items():
# if v0['ref'] == (rr,):
# if k0 not in lk0:
# lk0.append(k0)

# # include all data matching all refs
# for k0, v0 in coll._ddata.items():
# if v0['ref'] == coll._ddata[key]['ref']:
# if k0 not in lk0:
# lk0.append(k0)

# coll2 = coll.extract(lk0)

# return keys, coll2


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

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



def _apply_dlim(dlim=None, logic_intervals=None, logic=None, ddata=None):

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

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

def _check_cmap_vminvmax(data=None, cmap=None, vmin=None, vmax=None):
# cmap
c0 = (
cmap is None
or vmin is None
or vmax is None
)
if cmap is None or vmin is None or vmax is None:
nanmax = np.nanmax(data)
nanmin = np.nanmin(data)
Expand Down
32 changes: 29 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
[project]
name = "datastock"
version = "0.0.47"
description = "Generic handler for multiple heterogenous numpy arrays and subclasses"
readme = "README.md"
requires-python = ">=3.6"
dependencies = [
"numpy",
"scipy",
"matplotlib",
"astropy",
]


[build-system]
requires = ["setuptools>=40.8.0",
"wheel",
]
requires = [
"setuptools>=40.8.0, <64",
"wheel",
"Cython>=0.26",
"numpy",
]

[dependency-groups]
dev = [
"pytest",
]


[project.scripts]
datastock = "scripts.main:main"
Empty file added scripts/__init__.py
Empty file.
77 changes: 77 additions & 0 deletions scripts/_bash_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python

# Built-in
import os


###################################################
###################################################
# DEFAULTS
###################################################


_PATH_HERE = os.path.dirname(__file__)


###################################################
###################################################
# function
###################################################


def main(
verb=None,
envvar=None,
path=None,
warn=None,
force=None,
ddef=None,
):
""" Print version """

# --------------
# Check inputs
# --------------

kwd = locals()
for k0 in set(ddef.keys()).intersection(kwd.keys()):
if kwd[k0] is None:
kwd[k0] = ddef[k0]
verb, path = kwd['verb'], kwd['path']

# verb, warn, force
dbool = {'verb': verb}
for k0, v0 in dbool.items():
if v0 is None:
dbool[k0] = ddef[k0]
if not isinstance(dbool[k0], bool):
msg = (
f"Arg '{k0}' must be a bool\n"
f"\t- provided: {dbool[k0]}\n"
)
raise Exception(msg)

# --------------
# Fetch version from git tags, and write to version.py
# Also, when git is not available (PyPi package), use stored version.py

pfe = os.path.join(path, 'version.py')
if not os.path.isfile(pfe):
msg = (
"It seems your current install has no version.py:\n"
f"\t- looked for: {pfe}"
)
raise Exception(msg)

# --------------
# Read file

with open(pfe, 'r') as fh:
version = fh.read().strip().split("=")[-1].replace("'", '')
version = version.lower().replace('v', '').replace(' ', '')

# --------------
# Outputs

if dbool['verb'] is True:
print(version)
109 changes: 109 additions & 0 deletions scripts/_dparser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import sys
import os
import getpass
import argparse


# test if in a git repo
_HERE = os.path.abspath(os.path.dirname(__file__))
_REPOPATH = os.path.dirname(_HERE)
_REPO_NAME = 'datastock'


# #############################################################################
# utility functions
# #############################################################################


def _str2bool(v):
if isinstance(v, bool):
return v
elif v.lower() in ['yes', 'true', 'y', 't', '1']:
return True
elif v.lower() in ['no', 'false', 'n', 'f', '0']:
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected!')


def _str2boolstr(v):
if isinstance(v, bool):
return v
elif isinstance(v, str):
if v.lower() in ['yes', 'true', 'y', 't', '1']:
return True
elif v.lower() in ['no', 'false', 'n', 'f', '0']:
return False
elif v.lower() == 'none':
return None
else:
return v
else:
raise argparse.ArgumentTypeError('Boolean, None or str expected!')


def _str2tlim(v):
c0 = (v.isdigit()
or ('.' in v
and len(v.split('.')) == 2
and all([vv.isdigit() for vv in v.split('.')])))
if c0 is True:
v = float(v)
elif v.lower() == 'none':
v = None
return v


# #############################################################################
# Parser for version
# #############################################################################


def parser_version():
msg = f""" Get {_REPO_NAME} version from bash

If run from a git repo containing {_REPO_NAME}, just returns git describe
Otherwise reads the version stored in {_REPO_NAME}/version.py

"""
ddef = {
'path': os.path.join(_REPOPATH, _REPO_NAME),
'envvar': False,
'verb': True,
'warn': True,
'force': False,
'name': f'{_REPO_NAME.upper()}_VERSION',
}

# Instanciate parser
parser = argparse.ArgumentParser(description=msg)

# optional path
parser.add_argument(
'-p', '--path',
type=str,
help='source directory where version.py is found',
required=False,
default=ddef['path'],
)

# verb
parser.add_argument(
'-v', '--verb',
type=_str2bool,
help='flag indicating whether to print the version',
required=False,
default=ddef['verb'],
)

return ddef, parser


# #############################################################################
# Parser dict
# #############################################################################


_DPARSER = {
'version': parser_version,
}
Loading
Loading