hdx-python-utilities 3.6.3__tar.gz → 3.6.4__tar.gz
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.
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/PKG-INFO +1 -1
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/documentation/main.md +5 -2
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/_version.py +2 -2
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/loader.py +55 -13
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/typehint.py +1 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_loader.py +9 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/.config/black.toml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/.config/coveragerc +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/.config/pre-commit-config.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/.config/pytest.ini +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/.config/ruff.toml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/.github/workflows/publish.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/.github/workflows/run-python-tests.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/.gitignore +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/CONTRIBUTING.md +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/LICENSE +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/README.md +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/documentation/.readthedocs.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/documentation/pydoc-markdown.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/pyproject.toml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/requirements.txt +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/__init__.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/base_downloader.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/compare.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/dateparse.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/dictandlist.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/downloader.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/easy_logging.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/email.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/encoding.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/errors_onexit.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/frictionless_wrapper.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/html.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/path.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/retriever.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/saver.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/session.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/state.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/text.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/useragent.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/uuid.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/compare/test_csv_processing.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/compare/test_csv_processing2.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/empty.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/hdx_config.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/hdx_config.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/hdx_email_configuration.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/hdx_email_configuration.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/json_csv.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/logging_config.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/logging_config.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/project_configuration.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/project_configuration.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/smtp_config.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/smtp_config.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/user_agent_config.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/user_agent_config2.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/user_agent_config3.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/user_agent_config_wrong.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/basicauth.txt +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/extra_params.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/extra_params.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/extra_params_tree.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_csv_processing.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_csv_processing_blanks.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_data.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_data.xlsx +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_data1.csv/empty.txt +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_data2.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_json_processing.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_xls_processing.xls +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_xlsx_processing.xlsx +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/html/response.html +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/loader/empty.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/loader/empty.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/fallbacks/test.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/fallbacks/test.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/fallbacks/test.txt +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/fallbacks/test.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/retriever-test.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/test.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/test.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/test.txt +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/test.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/test_hxl.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/out.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/out.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/out2.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/out2.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/out5.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/out6.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/out7.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/out8.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/out8.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/pretty-false_sortkeys-false.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/pretty-false_sortkeys-false.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/pretty-false_sortkeys-true.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/pretty-false_sortkeys-true.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/pretty-true_sortkeys-false.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/pretty-true_sortkeys-false.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/pretty-true_sortkeys-true.json +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/saver/pretty-true_sortkeys-true.yaml +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/state/analysis_dates.txt +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/state/last_build_date.txt +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/test_data.csv +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/conftest.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_compare.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_dateparse.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_dictandlist.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_downloader.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_easy_logging.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_email.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_encoding.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_errors_onexit.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_html.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_path.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_retriever.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_saver.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_state.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_text.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_useragent.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_uuid.py +0 -0
- {hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hdx-python-utilities
|
|
3
|
-
Version: 3.6.
|
|
3
|
+
Version: 3.6.4
|
|
4
4
|
Summary: HDX Python Utilities for streaming tabular data, date and time handling and other helpful functions
|
|
5
5
|
Project-URL: Homepage, https://github.com/OCHA-DAP/hdx-python-utilities
|
|
6
6
|
Author-email: Michael Rans <rans@email.com>
|
|
@@ -348,8 +348,11 @@ Examples:
|
|
|
348
348
|
# Load YAML into existing dictionary
|
|
349
349
|
mydict = load_yaml_into_existing_dict(existing_dict, "my_yaml.yaml")
|
|
350
350
|
|
|
351
|
-
# Load JSON
|
|
352
|
-
mydict = load_json("my_json.
|
|
351
|
+
# Load JSON raising a LoadError if the file is empty
|
|
352
|
+
mydict = load_json("my_json.json")
|
|
353
|
+
|
|
354
|
+
# Load JSON returning None if the file is empty
|
|
355
|
+
mydict = load_json("my_json.json", loaderror_if_empty=False)
|
|
353
356
|
|
|
354
357
|
# Load 2 JSONs and merge into dictionary
|
|
355
358
|
mydict = load_and_merge_json("my_json1.json", "my_json2.json")
|
|
@@ -19,6 +19,7 @@ def load_text(
|
|
|
19
19
|
encoding: str = "utf-8",
|
|
20
20
|
strip: bool = False,
|
|
21
21
|
replace_newlines: Optional[str] = None,
|
|
22
|
+
loaderror_if_empty: bool = True,
|
|
22
23
|
) -> str:
|
|
23
24
|
"""Load file into a string removing newlines.
|
|
24
25
|
|
|
@@ -27,6 +28,7 @@ def load_text(
|
|
|
27
28
|
encoding (str): Encoding of file. Defaults to utf-8.
|
|
28
29
|
strip (bool): Whether to strip whitespace from start and end. Defaults to False.
|
|
29
30
|
replace_newlines (Optional[str]): String with which tp replace newlines. Defaults to None (don't replace).
|
|
31
|
+
loaderror_if_empty (bool): Whether to raise LoadError if file is empty. Default to True.
|
|
30
32
|
|
|
31
33
|
Returns:
|
|
32
34
|
str: String contents of file
|
|
@@ -38,16 +40,21 @@ def load_text(
|
|
|
38
40
|
if strip:
|
|
39
41
|
string = string.strip()
|
|
40
42
|
if not string:
|
|
41
|
-
|
|
43
|
+
if loaderror_if_empty:
|
|
44
|
+
raise LoadError(f"{path} file is empty!")
|
|
45
|
+
return ""
|
|
42
46
|
return string
|
|
43
47
|
|
|
44
48
|
|
|
45
|
-
def load_yaml(
|
|
49
|
+
def load_yaml(
|
|
50
|
+
path: str, encoding: str = "utf-8", loaderror_if_empty: bool = True
|
|
51
|
+
) -> Any:
|
|
46
52
|
"""Load YAML file into an ordered dictionary.
|
|
47
53
|
|
|
48
54
|
Args:
|
|
49
55
|
path (str): Path to YAML file
|
|
50
56
|
encoding (str): Encoding of file. Defaults to utf-8.
|
|
57
|
+
loaderror_if_empty (bool): Whether to raise LoadError if file is empty. Default to True.
|
|
51
58
|
|
|
52
59
|
Returns:
|
|
53
60
|
Any: The data from the YAML file
|
|
@@ -56,16 +63,21 @@ def load_yaml(path: str, encoding: str = "utf-8") -> Any:
|
|
|
56
63
|
yaml = YAML()
|
|
57
64
|
yamlobj = yaml.load(f.read())
|
|
58
65
|
if not yamlobj:
|
|
59
|
-
|
|
66
|
+
if loaderror_if_empty:
|
|
67
|
+
raise LoadError(f"YAML file: {path} is empty!")
|
|
68
|
+
return None
|
|
60
69
|
return yamlobj
|
|
61
70
|
|
|
62
71
|
|
|
63
|
-
def load_json(
|
|
72
|
+
def load_json(
|
|
73
|
+
path: str, encoding: str = "utf-8", loaderror_if_empty: bool = True
|
|
74
|
+
) -> Any:
|
|
64
75
|
"""Load JSON file into an ordered dictionary (dict for Python 3.7+)
|
|
65
76
|
|
|
66
77
|
Args:
|
|
67
78
|
path (str): Path to JSON file
|
|
68
79
|
encoding (str): Encoding of file. Defaults to utf-8.
|
|
80
|
+
loaderror_if_empty (bool): Whether to raise LoadError if file is empty. Default to True.
|
|
69
81
|
|
|
70
82
|
Returns:
|
|
71
83
|
Any: The data from the JSON file
|
|
@@ -73,12 +85,16 @@ def load_json(path: str, encoding: str = "utf-8") -> Dict:
|
|
|
73
85
|
with open(path, encoding=encoding) as f:
|
|
74
86
|
jsonobj = json.loads(f.read())
|
|
75
87
|
if not jsonobj:
|
|
76
|
-
|
|
88
|
+
if loaderror_if_empty:
|
|
89
|
+
raise LoadError(f"JSON file: {path} is empty!")
|
|
90
|
+
return None
|
|
77
91
|
return jsonobj
|
|
78
92
|
|
|
79
93
|
|
|
80
94
|
def load_and_merge_yaml(
|
|
81
|
-
paths: ListTuple[str],
|
|
95
|
+
paths: ListTuple[str],
|
|
96
|
+
encoding: str = "utf-8",
|
|
97
|
+
loaderror_if_empty: bool = True,
|
|
82
98
|
) -> Dict:
|
|
83
99
|
"""Load multiple YAML files that are in dictionary form and merge into one
|
|
84
100
|
dictionary.
|
|
@@ -86,16 +102,24 @@ def load_and_merge_yaml(
|
|
|
86
102
|
Args:
|
|
87
103
|
paths (ListTuple[str]): Paths to YAML files
|
|
88
104
|
encoding (str): Encoding of file. Defaults to utf-8.
|
|
105
|
+
loaderror_if_empty (bool): Whether to raise LoadError if any file is empty. Default to True.
|
|
89
106
|
|
|
90
107
|
Returns:
|
|
91
108
|
Dict: Dictionary of merged YAML files
|
|
92
109
|
"""
|
|
93
|
-
configs = [
|
|
110
|
+
configs = [
|
|
111
|
+
load_yaml(
|
|
112
|
+
path, encoding=encoding, loaderror_if_empty=loaderror_if_empty
|
|
113
|
+
)
|
|
114
|
+
for path in paths
|
|
115
|
+
]
|
|
94
116
|
return merge_dictionaries(configs)
|
|
95
117
|
|
|
96
118
|
|
|
97
119
|
def load_and_merge_json(
|
|
98
|
-
paths: ListTuple[str],
|
|
120
|
+
paths: ListTuple[str],
|
|
121
|
+
encoding: str = "utf-8",
|
|
122
|
+
loaderror_if_empty: bool = True,
|
|
99
123
|
) -> Dict:
|
|
100
124
|
"""Load multiple JSON files that are in dictionary form and merge into one
|
|
101
125
|
dictionary.
|
|
@@ -103,16 +127,25 @@ def load_and_merge_json(
|
|
|
103
127
|
Args:
|
|
104
128
|
paths (ListTuple[str]): Paths to JSON files
|
|
105
129
|
encoding (str): Encoding of file. Defaults to utf-8.
|
|
130
|
+
loaderror_if_empty (bool): Whether to raise LoadError if any file is empty. Default to True.
|
|
106
131
|
|
|
107
132
|
Returns:
|
|
108
133
|
Dict: Dictionary of merged JSON files
|
|
109
134
|
"""
|
|
110
|
-
configs = [
|
|
135
|
+
configs = [
|
|
136
|
+
load_json(
|
|
137
|
+
path, encoding=encoding, loaderror_if_empty=loaderror_if_empty
|
|
138
|
+
)
|
|
139
|
+
for path in paths
|
|
140
|
+
]
|
|
111
141
|
return merge_dictionaries(configs)
|
|
112
142
|
|
|
113
143
|
|
|
114
144
|
def load_yaml_into_existing_dict(
|
|
115
|
-
data: dict,
|
|
145
|
+
data: dict,
|
|
146
|
+
path: str,
|
|
147
|
+
encoding: str = "utf-8",
|
|
148
|
+
loaderror_if_empty: bool = True,
|
|
116
149
|
) -> Dict:
|
|
117
150
|
"""Merge YAML file that is in dictionary form into existing dictionary.
|
|
118
151
|
|
|
@@ -120,16 +153,22 @@ def load_yaml_into_existing_dict(
|
|
|
120
153
|
data (dict): Dictionary to merge into
|
|
121
154
|
path (str): YAML file to load and merge
|
|
122
155
|
encoding (str): Encoding of file. Defaults to utf-8.
|
|
156
|
+
loaderror_if_empty (bool): Whether to raise LoadError if file is empty. Default to True.
|
|
123
157
|
|
|
124
158
|
Returns:
|
|
125
159
|
Dict: YAML file merged into dictionary
|
|
126
160
|
"""
|
|
127
|
-
yamldict = load_yaml(
|
|
161
|
+
yamldict = load_yaml(
|
|
162
|
+
path, encoding=encoding, loaderror_if_empty=loaderror_if_empty
|
|
163
|
+
)
|
|
128
164
|
return merge_two_dictionaries(data, yamldict)
|
|
129
165
|
|
|
130
166
|
|
|
131
167
|
def load_json_into_existing_dict(
|
|
132
|
-
data: dict,
|
|
168
|
+
data: dict,
|
|
169
|
+
path: str,
|
|
170
|
+
encoding: str = "utf-8",
|
|
171
|
+
loaderror_if_empty: bool = True,
|
|
133
172
|
) -> Dict:
|
|
134
173
|
"""Merge JSON file that is in dictionary form into existing dictionary.
|
|
135
174
|
|
|
@@ -137,9 +176,12 @@ def load_json_into_existing_dict(
|
|
|
137
176
|
data (dict): Dictionary to merge into
|
|
138
177
|
path (str): JSON file to load and merge
|
|
139
178
|
encoding (str): Encoding of file. Defaults to utf-8.
|
|
179
|
+
loaderror_if_empty (bool): Whether to raise LoadError if file is empty. Default to True.
|
|
140
180
|
|
|
141
181
|
Returns:
|
|
142
182
|
dict: JSON file merged into dictionary
|
|
143
183
|
"""
|
|
144
|
-
jsondict = load_json(
|
|
184
|
+
jsondict = load_json(
|
|
185
|
+
path, encoding=encoding, loaderror_if_empty=loaderror_if_empty
|
|
186
|
+
)
|
|
145
187
|
return merge_two_dictionaries(data, jsondict)
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_loader.py
RENAMED
|
@@ -118,10 +118,19 @@ test"""
|
|
|
118
118
|
loaderfolder = join(fixturesfolder, "loader")
|
|
119
119
|
with pytest.raises(LoadError):
|
|
120
120
|
load_text(join(loaderfolder, "empty.yaml"))
|
|
121
|
+
load_text(
|
|
122
|
+
join(loaderfolder, "empty.yaml"), loaderror_if_empty=False
|
|
123
|
+
) == ""
|
|
121
124
|
with pytest.raises(LoadError):
|
|
122
125
|
load_yaml(join(loaderfolder, "empty.yaml"))
|
|
126
|
+
load_yaml(
|
|
127
|
+
join(loaderfolder, "empty.yaml"), loaderror_if_empty=False
|
|
128
|
+
) is None
|
|
123
129
|
with pytest.raises(LoadError):
|
|
124
130
|
load_json(join(loaderfolder, "empty.json"))
|
|
131
|
+
load_json(
|
|
132
|
+
join(loaderfolder, "empty.json"), loaderror_if_empty=False
|
|
133
|
+
) is None
|
|
125
134
|
|
|
126
135
|
def test_load_and_merge_yaml(self, configfolder):
|
|
127
136
|
result = load_and_merge_yaml(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/.github/workflows/run-python-tests.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/base_downloader.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/errors_onexit.py
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/src/hdx/utilities/frictionless_wrapper.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/hdx_config.json
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/hdx_config.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/json_csv.yaml
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/logging_config.json
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/logging_config.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/smtp_config.json
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/config/smtp_config.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/basicauth.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_data.csv
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_data.xlsx
RENAMED
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/downloader/test_data2.csv
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/test.json
RENAMED
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/test.yaml
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/retriever/test_hxl.csv
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/state/analysis_dates.txt
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/fixtures/state/last_build_date.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_compare.py
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_dateparse.py
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_dictandlist.py
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_downloader.py
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_easy_logging.py
RENAMED
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_encoding.py
RENAMED
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_errors_onexit.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_retriever.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_utilities-3.6.3 → hdx_python_utilities-3.6.4}/tests/hdx/utilities/test_useragent.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|