python-ubercode-utils 2.0.5__py3-none-any.whl → 2.0.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-ubercode-utils
3
- Version: 2.0.5
3
+ Version: 2.0.7
4
4
  Summary: Core python utilities for all apps
5
5
  Home-page: https://github.com/sstacha/python-ubercode-utils
6
6
  Author: Steve Stacha
@@ -4,11 +4,11 @@ ubercode/utils/convert.py,sha256=INxAIlIkwTeHSdVpqm8R_N5MzrSrjY9CduioHipu39g,113
4
4
  ubercode/utils/cursor.py,sha256=zHqbmUavCF0l7ck_Tu4PfgSzRO762ULKHYsnqa3r0uY,1118
5
5
  ubercode/utils/data.py,sha256=DStj9BAXPSPvQRZwfEQVYt19EoMavyNFt11U8ZnhagE,4364
6
6
  ubercode/utils/dataframe.py,sha256=3AYoZGZB7wtN5brBDfRgnuIaEubhRrSc7qx8hi_vaaE,1616
7
- ubercode/utils/environment.py,sha256=97uYs0zGBkk7TfKuml6Th27kpdtYX_ILwfZTQW3Xac8,15818
7
+ ubercode/utils/environment.py,sha256=aOAtMLOOpNJ_0BPGcAQtzB3D2_TguPodjYxNB0QPDWY,16753
8
8
  ubercode/utils/logging.py,sha256=s4yIJWHo9MVO4oSk5IF3z6XTk-FOuyEiKnPFkiza3h4,9204
9
9
  ubercode/utils/urls.py,sha256=dkAHH-ZOXkqueKor94fCmwUz6I4KnvAM_XcW8k2XjaY,14507
10
- python_ubercode_utils-2.0.5.dist-info/LICENSE,sha256=lch0WEJaqJY3C5aCYSr0u6Gw0set96a2fp9ZWJRYuR8,1069
11
- python_ubercode_utils-2.0.5.dist-info/METADATA,sha256=FGWg4Rw72IguHetBcCIRrWOlWTehbF8DhsLRswBp86k,1225
12
- python_ubercode_utils-2.0.5.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
13
- python_ubercode_utils-2.0.5.dist-info/top_level.txt,sha256=5BojzbvNCpPkFXcVQVr7cfovhbYQYAlMKgiHSMgi7VU,9
14
- python_ubercode_utils-2.0.5.dist-info/RECORD,,
10
+ python_ubercode_utils-2.0.7.dist-info/LICENSE,sha256=lch0WEJaqJY3C5aCYSr0u6Gw0set96a2fp9ZWJRYuR8,1069
11
+ python_ubercode_utils-2.0.7.dist-info/METADATA,sha256=-T6UzN1Qdj6Xj2uIi6Z8u-uAyyMU5WvHHs9_OPZJzC0,1225
12
+ python_ubercode_utils-2.0.7.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
13
+ python_ubercode_utils-2.0.7.dist-info/top_level.txt,sha256=5BojzbvNCpPkFXcVQVr7cfovhbYQYAlMKgiHSMgi7VU,9
14
+ python_ubercode_utils-2.0.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.44.0)
2
+ Generator: bdist_wheel (0.46.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -71,16 +71,26 @@ class Environment:
71
71
  self._env_map = environment_variable_map
72
72
 
73
73
  @staticmethod
74
- def infer_data_type(value):
75
- if value is not None:
76
- if isinstance(value, bool):
74
+ def infer_data_type(default_value: Any, env_value: Any) -> str:
75
+ if default_value is not None:
76
+ if isinstance(default_value, bool):
77
77
  return 'bool'
78
- if isinstance(value, str):
79
- return 'str'
80
- if isinstance(value, int):
78
+ if isinstance(default_value, int):
81
79
  return 'int'
82
- if isinstance(value, datetime):
80
+ if isinstance(default_value, datetime):
83
81
  return 'date'
82
+ if isinstance(default_value, str):
83
+ return 'str'
84
+ else:
85
+ # NOTE: all env vals are sent as strings so 'True', 'False' with no settings var will be str not bool
86
+ # considering inferring that it is python boolean if True,False with caps. Will not do lower for
87
+ # js type true,false we want to pass through as strings lower case in a template; trying not to
88
+ # infer too much.
89
+ if env_value is not None and isinstance(env_value, str) and env_value.strip() in ('True', 'False'):
90
+ return 'bool'
91
+ # NOTE: we may want to look at some common date/time patters to infer date as well; but bool is
92
+ # important because things like DEBUG=False will evaluate as True if overridden right now without
93
+ # the variable being first initialized to something in the settings file.
84
94
  return 'str'
85
95
 
86
96
  def override_variable(self, variable_name: str, default_value: Any = None, environment_variable_name: str = None,
@@ -113,7 +123,7 @@ class Environment:
113
123
  if _env_value is not None:
114
124
  if data_type is None or data_type not in self.VARIABLE_DATA_TYPES:
115
125
  # infer type from default value
116
- data_type = self.infer_data_type(default_value)
126
+ data_type = self.infer_data_type(default_value, _env_value)
117
127
  # attempt to convert to datatype if not str
118
128
  if data_type == 'bool':
119
129
  _env_value = convert.to_bool(_env_value)
@@ -128,7 +138,7 @@ class Environment:
128
138
  _log_value = convert.to_mask(_env_value)
129
139
  if _log_from_value != "None":
130
140
  _log_from_value = convert.to_mask(_log_from_value)
131
- self._logger.info(f'overriding {variable_name}: [{str(_log_from_value)}] to [{str(_log_value)}]')
141
+ self._logger.info(f'overriding {variable_name} [{type(_env_value)}]: [{str(_log_from_value)}] to [{str(_log_value)}]')
132
142
  return _env_value
133
143
  return default_value
134
144
 
@@ -199,7 +209,7 @@ class Environment:
199
209
  _log_from_value = 'None'
200
210
  _log_to_value = str(v)
201
211
  # we may be setting up a completely new database from scratch so create if it doesn't exist
202
- if not db_dict[db_parts[1]]:
212
+ if not db_dict.get(db_parts[1]):
203
213
  self._logger.debug(f'database {db_parts[0]}[{db_parts[1]}] was not found; creating...')
204
214
  db_dict[db_parts[1]] = {}
205
215
  # we now have db dict; we may not have a property already defined; if not we want to add it