ae-base 0.3.64__py3-none-any.whl → 0.3.66__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.
ae/base.py CHANGED
@@ -32,6 +32,10 @@ sortable and compact string from a timestamp.
32
32
  base helper functions
33
33
  ---------------------
34
34
 
35
+ the function :func:`evaluate_literal` can be used as a replacement of :func:`ast.literal_eval` to retrieve
36
+ basic data structure values from config, ini and .env files, while also accepting unquoted strings as a `str` type
37
+ instance.
38
+
35
39
  most programming languages providing a function to determine the sign of a number. the :func:`sign` functino,
36
40
  provided by this module/portion is filling this gap in Python.
37
41
 
@@ -148,6 +152,7 @@ os.path shortcuts
148
152
  the following data items are pointers to shortcut at runtime the lookup to their related functions in the
149
153
  Python module :mod:`os.path`:
150
154
  """
155
+ # pylint: disable=too-many-lines
151
156
  import datetime
152
157
  import getpass
153
158
  import importlib.abc
@@ -171,7 +176,7 @@ from types import ModuleType
171
176
  from typing import Any, Callable, Generator, Iterable, MutableMapping, Optional, Union, cast
172
177
 
173
178
 
174
- __version__ = '0.3.64'
179
+ __version__ = '0.3.66'
175
180
 
176
181
 
177
182
  os_path_abspath = os.path.abspath
@@ -355,6 +360,7 @@ def deep_dict_update(data: dict, update: dict, overwrite: bool = True):
355
360
 
356
361
 
357
362
  URI_SEP_CHAR = '⫻' # U+2AFB: TRIPLE SOLIDUS BINARY RELATION
363
+ # noinspection GrazieInspection
358
364
  ASCII_UNICODE = (
359
365
  ('/', '⁄'), # U+2044: Fraction Slash; '∕' U+2215: Division Slash; '⧸' U+29F8: Big Solidus;
360
366
  # '╱' U+FF0F: Fullwidth Solidus; '╱' U+2571: Box Drawings Light Diagonal Upper Right to Lower Left
@@ -428,7 +434,7 @@ def defuse(value: str) -> str:
428
434
  in most unix variants only the slash and the ASCII 0 characters are not allowed in file names.
429
435
 
430
436
  in MS Windows are not allowed: ASCII 0..31 / | \\ : * ? ” % < > ( ). some blogs recommend also not allowing
431
- (convert) the characters # and '.
437
+ (convert) the characters `#` and `'`.
432
438
 
433
439
  only old POSIX seems to be even more restricted (only allowing alphanumeric characters plus . - and _).
434
440
 
@@ -494,6 +500,20 @@ def env_str(name: str, convert_name: bool = False) -> Optional[str]:
494
500
  return os.environ.get(name)
495
501
 
496
502
 
503
+ def evaluate_literal(literal_string: str) -> Any:
504
+ """ evaluates a Python expression while accepting unquoted strings as str type.
505
+
506
+ :param literal_string: any literal of the base types (like dict, list, set, tuple) which are recognized
507
+ by :func:`ast.literal_eval`.
508
+ :return: an instance of the data type or the specified string, even if it is not quoted with
509
+ high comma characters.
510
+ """
511
+ try:
512
+ return literal_eval(literal_string)
513
+ except (IndentationError, SyntaxError, TypeError, ValueError):
514
+ return literal_string
515
+
516
+
497
517
  def force_encoding(text: Union[str, bytes], encoding: str = DEF_ENCODING, errors: str = DEF_ENCODE_ERRORS) -> str:
498
518
  """ force/ensure the encoding of text (str or bytes) without any UnicodeDecodeError/UnicodeEncodeError.
499
519
 
@@ -630,14 +650,26 @@ def in_wd(new_cwd: str) -> Generator[None, None, None]:
630
650
  os.chdir(cur_dir)
631
651
 
632
652
 
633
- def load_dotenvs():
634
- """ detect and load multiple ``.env`` files in/above the current working directory and the calling module folder.
653
+ def load_dotenvs(from_module_path: bool = False):
654
+ """ detect and load not defined OS environment variables from ``.env`` files.
635
655
 
636
- .. hint:: call from the main module of project/app in order to also load ``.env`` files in/above the project folder.
656
+ :param from_module_path: pass True to load OS environment variables (that are not already loaded from ``.env``
657
+ files situated in or above the current working directory) also from/above the folder of
658
+ the first module in the call stack that gets not excluded/skipped by :func:`stack_var`.
659
+
660
+ in order to also load ``.env`` files in/above the project folder.
661
+ call this function from the main module of project/app.
662
+
663
+ .. note::
664
+ only variables that are not already defined in the OS environment variables mapping :data:`os.environ` will be
665
+ loaded/added. variables will be loaded first from the first ``.env`` file found in or above the current working
666
+ directory, while the variable values in the deeper situated files are overwriting the values defined in the
667
+ ``.env`` files situated in the above folders.
637
668
  """
638
669
  env_vars = os.environ
639
670
  load_env_var_defaults(os.getcwd(), env_vars)
640
- if file_name := stack_var('__file__'):
671
+
672
+ if from_module_path and (file_name := stack_var('__file__')):
641
673
  load_env_var_defaults(os_path_dirname(os_path_abspath(file_name)), env_vars)
642
674
 
643
675
 
@@ -769,11 +801,12 @@ def module_name(*skip_modules: str, depth: int = 0) -> Optional[str]:
769
801
 
770
802
 
771
803
  def norm_line_sep(text: str) -> str:
804
+ # noinspection GrazieInspection
772
805
  """ convert any combination of line separators in the :paramref:`~norm_line_sep.text` arg to new-line characters.
773
806
 
774
- :param text: string containing any combination of line separators ('\\\\r\\\\n' or '\\\\r').
775
- :return: normalized/converted string with only new-line ('\\\\n') line separator characters.
776
- """
807
+ :param text: string containing any combination of line separators ('\\\\r\\\\n' or '\\\\r').
808
+ :return: normalized/converted string with only new-line ('\\\\n') line separator characters.
809
+ """
777
810
  return text.replace('\r\n', '\n').replace('\r', '\n')
778
811
 
779
812
 
@@ -1,29 +1,29 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ae_base
3
- Version: 0.3.64
3
+ Version: 0.3.66
4
4
  Summary: ae namespace module portion base: basic constants, helper functions and context manager
5
5
  Home-page: https://gitlab.com/ae-group/ae_base
6
6
  Author: AndiEcker
7
7
  Author-email: aecker2@gmail.com
8
- License: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
8
+ License: GPL-3.0-or-later
9
9
  Project-URL: Bug Tracker, https://gitlab.com/ae-group/ae_base/-/issues
10
10
  Project-URL: Documentation, https://ae.readthedocs.io/en/latest/_autosummary/ae.base.html
11
11
  Project-URL: Repository, https://gitlab.com/ae-group/ae_base
12
12
  Project-URL: Source, https://ae.readthedocs.io/en/latest/_modules/ae/base.html
13
13
  Keywords: configuration,development,environment,productivity
14
14
  Classifier: Development Status :: 3 - Alpha
15
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
16
15
  Classifier: Natural Language :: English
17
16
  Classifier: Operating System :: OS Independent
18
17
  Classifier: Programming Language :: Python
19
18
  Classifier: Programming Language :: Python :: 3
20
19
  Classifier: Programming Language :: Python :: 3.9
21
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
22
  Requires-Python: >=3.9
23
23
  Description-Content-Type: text/markdown
24
24
  License-File: LICENSE.md
25
25
  Provides-Extra: dev
26
- Requires-Dist: aedev_tpl_project; extra == "dev"
26
+ Requires-Dist: aedev_project_tpls; extra == "dev"
27
27
  Requires-Dist: ae_ae; extra == "dev"
28
28
  Requires-Dist: anybadge; extra == "dev"
29
29
  Requires-Dist: coverage-badge; extra == "dev"
@@ -67,15 +67,15 @@ Dynamic: provides-extra
67
67
  Dynamic: requires-python
68
68
  Dynamic: summary
69
69
 
70
- <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae V0.3.96 -->
70
+ <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project ae.ae v0.3.96 -->
71
71
  <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_namespace_root V0.3.14 -->
72
- # base 0.3.64
72
+ # base 0.3.66
73
73
 
74
74
  [![GitLab develop](https://img.shields.io/gitlab/pipeline/ae-group/ae_base/develop?logo=python)](
75
75
  https://gitlab.com/ae-group/ae_base)
76
76
  [![LatestPyPIrelease](
77
- https://img.shields.io/gitlab/pipeline/ae-group/ae_base/release0.3.63?logo=python)](
78
- https://gitlab.com/ae-group/ae_base/-/tree/release0.3.63)
77
+ https://img.shields.io/gitlab/pipeline/ae-group/ae_base/release0.3.65?logo=python)](
78
+ https://gitlab.com/ae-group/ae_base/-/tree/release0.3.65)
79
79
  [![PyPIVersions](https://img.shields.io/pypi/v/ae_base)](
80
80
  https://pypi.org/project/ae-base/#history)
81
81
 
@@ -0,0 +1,7 @@
1
+ ae/base.py,sha256=JHqqxdP33QB7BI5NfLKBTF1QU2o_DIpIId9VQv8UKYs,69668
2
+ ae_base-0.3.66.dist-info/licenses/LICENSE.md,sha256=tgCt6xhP3pM6OcWOWsCTUNed3CEhLTOaRgBMUMynA0I,35003
3
+ ae_base-0.3.66.dist-info/METADATA,sha256=iDIXXfhbEK4B89iEK3tOqf8INLUpauy6WJvYeqzEMJs,5619
4
+ ae_base-0.3.66.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ ae_base-0.3.66.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
6
+ ae_base-0.3.66.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
+ ae_base-0.3.66.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
- <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.tpl_project V0.3.36 -->
1
+ <!-- THIS FILE IS EXCLUSIVELY MAINTAINED by the project aedev.project_tpls v0.3.46 -->
2
2
  ### GNU GENERAL PUBLIC LICENSE
3
3
 
4
4
  Version 3, 29 June 2007
@@ -1,7 +0,0 @@
1
- ae/base.py,sha256=STUdNRroIq5IXtXCqWRg8vIu-Vx-qvOT8f7gnv8uhH8,67812
2
- ae_base-0.3.64.dist-info/licenses/LICENSE.md,sha256=vn9XT8MDUxNAWsP60HLwHJp8ZLOI0OJBRe-1N2xXh08,35002
3
- ae_base-0.3.64.dist-info/METADATA,sha256=Yo8TxzMWNjmhRMgJwKFsXW3Ui6M9IA358AIO1abx4mE,5724
4
- ae_base-0.3.64.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- ae_base-0.3.64.dist-info/top_level.txt,sha256=vUdgAslSmhZLXWU48fm8AG2BjVnkOWLco8rzuW-5zY0,3
6
- ae_base-0.3.64.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
- ae_base-0.3.64.dist-info/RECORD,,