hdx-python-utilities 3.6.7__tar.gz → 3.8.2__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.
Files changed (128) hide show
  1. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/.config/pre-commit-config.yaml +7 -6
  2. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/.config/ruff.toml +0 -1
  3. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/.github/workflows/publish.yaml +2 -1
  4. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/.github/workflows/run-python-tests.yaml +4 -3
  5. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/.gitignore +2 -0
  6. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/PKG-INFO +6 -4
  7. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/documentation/.readthedocs.yaml +1 -0
  8. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/documentation/main.md +50 -17
  9. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/documentation/pydoc-markdown.yaml +1 -1
  10. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/pyproject.toml +17 -16
  11. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/requirements.txt +69 -65
  12. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/_version.py +2 -2
  13. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/dateparse.py +18 -5
  14. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/downloader.py +19 -0
  15. hdx_python_utilities-3.8.2/src/hdx/utilities/error_handler.py +185 -0
  16. hdx_python_utilities-3.8.2/src/hdx/utilities/errors_onexit.py +14 -0
  17. hdx_python_utilities-3.6.7/src/hdx/utilities/text.py → hdx_python_utilities-3.8.2/src/hdx/utilities/matching.py +137 -259
  18. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/retriever.py +1 -1
  19. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/saver.py +1 -1
  20. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/session.py +1 -1
  21. hdx_python_utilities-3.8.2/src/hdx/utilities/text.py +269 -0
  22. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_dateparse.py +4 -0
  23. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_downloader.py +78 -2
  24. hdx_python_utilities-3.8.2/tests/hdx/utilities/test_error_handler.py +56 -0
  25. hdx_python_utilities-3.6.7/tests/hdx/utilities/test_text.py → hdx_python_utilities-3.8.2/tests/hdx/utilities/test_matching.py +179 -111
  26. hdx_python_utilities-3.8.2/tests/hdx/utilities/test_text.py +123 -0
  27. hdx_python_utilities-3.6.7/src/hdx/utilities/errors_onexit.py +0 -53
  28. hdx_python_utilities-3.6.7/tests/hdx/utilities/test_errors_onexit.py +0 -24
  29. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/.config/coveragerc +0 -0
  30. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/.config/pytest.ini +0 -0
  31. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/CONTRIBUTING.md +0 -0
  32. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/LICENSE +0 -0
  33. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/README.md +0 -0
  34. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/__init__.py +0 -0
  35. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/base_downloader.py +0 -0
  36. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/compare.py +0 -0
  37. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/dictandlist.py +0 -0
  38. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/easy_logging.py +0 -0
  39. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/email.py +0 -0
  40. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/encoding.py +0 -0
  41. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/frictionless_wrapper.py +0 -0
  42. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/html.py +0 -0
  43. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/loader.py +0 -0
  44. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/path.py +0 -0
  45. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/state.py +0 -0
  46. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/typehint.py +0 -0
  47. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/useragent.py +0 -0
  48. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/src/hdx/utilities/uuid.py +0 -0
  49. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/compare/test_csv_processing.csv +0 -0
  50. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/compare/test_csv_processing2.csv +0 -0
  51. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/empty.yaml +0 -0
  52. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/hdx_config.json +0 -0
  53. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/hdx_config.yaml +0 -0
  54. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/hdx_email_configuration.json +0 -0
  55. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/hdx_email_configuration.yaml +0 -0
  56. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/json_csv.yaml +0 -0
  57. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/logging_config.json +0 -0
  58. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/logging_config.yaml +0 -0
  59. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/project_configuration.json +0 -0
  60. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/project_configuration.yaml +0 -0
  61. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/smtp_config.json +0 -0
  62. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/smtp_config.yaml +0 -0
  63. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/user_agent_config.yaml +0 -0
  64. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/user_agent_config2.yaml +0 -0
  65. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/user_agent_config3.yaml +0 -0
  66. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/config/user_agent_config_wrong.yaml +0 -0
  67. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/basicauth.txt +0 -0
  68. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/bearertoken.txt +0 -0
  69. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/extra_params.json +0 -0
  70. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/extra_params.yaml +0 -0
  71. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/extra_params_tree.yaml +0 -0
  72. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/test_csv_processing.csv +0 -0
  73. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/test_csv_processing_blanks.csv +0 -0
  74. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/test_data.csv +0 -0
  75. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/test_data.xlsx +0 -0
  76. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/test_data1.csv/empty.txt +0 -0
  77. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/test_data2.csv +0 -0
  78. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/test_json_processing.json +0 -0
  79. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/test_xls_processing.xls +0 -0
  80. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/downloader/test_xlsx_processing.xlsx +0 -0
  81. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/html/response.html +0 -0
  82. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/loader/empty.json +0 -0
  83. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/loader/empty.yaml +0 -0
  84. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/fallbacks/test.csv +0 -0
  85. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/fallbacks/test.json +0 -0
  86. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/fallbacks/test.txt +0 -0
  87. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/fallbacks/test.yaml +0 -0
  88. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/retriever-test.csv +0 -0
  89. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/test.csv +0 -0
  90. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/test.json +0 -0
  91. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/test.txt +0 -0
  92. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/test.yaml +0 -0
  93. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/retriever/test_hxl.csv +0 -0
  94. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/out.csv +0 -0
  95. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/out.json +0 -0
  96. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/out2.csv +0 -0
  97. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/out2.json +0 -0
  98. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/out5.json +0 -0
  99. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/out6.json +0 -0
  100. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/out7.json +0 -0
  101. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/out8.csv +0 -0
  102. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/out8.json +0 -0
  103. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/pretty-false_sortkeys-false.json +0 -0
  104. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/pretty-false_sortkeys-false.yaml +0 -0
  105. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/pretty-false_sortkeys-true.json +0 -0
  106. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/pretty-false_sortkeys-true.yaml +0 -0
  107. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/pretty-true_sortkeys-false.json +0 -0
  108. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/pretty-true_sortkeys-false.yaml +0 -0
  109. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/pretty-true_sortkeys-true.json +0 -0
  110. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/saver/pretty-true_sortkeys-true.yaml +0 -0
  111. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/state/analysis_dates.txt +0 -0
  112. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/state/last_build_date.txt +0 -0
  113. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/fixtures/test_data.csv +0 -0
  114. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/conftest.py +0 -0
  115. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_compare.py +0 -0
  116. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_dictandlist.py +0 -0
  117. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_easy_logging.py +0 -0
  118. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_email.py +0 -0
  119. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_encoding.py +0 -0
  120. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_html.py +0 -0
  121. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_loader.py +0 -0
  122. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_path.py +0 -0
  123. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_retriever.py +0 -0
  124. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_saver.py +0 -0
  125. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_state.py +0 -0
  126. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_useragent.py +0 -0
  127. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/test_uuid.py +0 -0
  128. {hdx_python_utilities-3.6.7 → hdx_python_utilities-3.8.2}/tests/hdx/utilities/utils.py +0 -0
@@ -1,8 +1,8 @@
1
1
  default_language_version:
2
- python: python3.11
2
+ python: python3.12
3
3
  repos:
4
4
  - repo: https://github.com/pre-commit/pre-commit-hooks
5
- rev: v4.5.0
5
+ rev: v5.0.0
6
6
  hooks:
7
7
  - id: trailing-whitespace
8
8
  exclude: test_loader.py
@@ -10,7 +10,7 @@ repos:
10
10
  exclude: (test_csv_processing_blanks.csv|test.txt)
11
11
  - id: check-ast
12
12
  - repo: https://github.com/astral-sh/ruff-pre-commit
13
- rev: v0.3.2
13
+ rev: v0.8.6
14
14
  hooks:
15
15
  # Run the linter.
16
16
  - id: ruff
@@ -18,10 +18,11 @@ repos:
18
18
  # Run the formatter.
19
19
  - id: ruff-format
20
20
  args: [--config, .config/ruff.toml]
21
- - repo: https://github.com/jazzband/pip-tools
22
- rev: 7.4.1
21
+ - repo: https://github.com/astral-sh/uv-pre-commit
22
+ rev: 0.5.15
23
23
  hooks:
24
+ # Run the pip compile
24
25
  - id: pip-compile
25
26
  name: pip-compile requirements.txt
26
27
  files: pyproject.toml
27
- args: [pyproject.toml, --resolver=backtracking, --all-extras, --upgrade, -q, -o, requirements.txt]
28
+ args: [ pyproject.toml, --resolver=backtracking, --all-extras, --upgrade, -q, -o, requirements.txt ]
@@ -12,6 +12,5 @@ ignore = [
12
12
  "E501" # Line too long
13
13
  ]
14
14
 
15
-
16
15
  [lint.isort]
17
16
  known-local-folder = ["hdx"]
@@ -21,7 +21,8 @@ jobs:
21
21
  - name: Install dependencies
22
22
  run: |
23
23
  python -m pip install --upgrade pip
24
- pip install --upgrade hatch
24
+ - name: Install Hatch
25
+ uses: pypa/hatch@install
25
26
  - name: Build with hatch
26
27
  run: |
27
28
  hatch build
@@ -26,14 +26,15 @@ jobs:
26
26
  - name: Install dependencies
27
27
  run: |
28
28
  python -m pip install --upgrade pip
29
- pip install --upgrade hatch
29
+ - name: Install Hatch
30
+ uses: pypa/hatch@install
30
31
  - name: Test with hatch/pytest
31
32
  run: |
32
- hatch run test:test
33
+ hatch test
33
34
  - name: Check styling
34
35
  if: always()
35
36
  run: |
36
- hatch run lint:style
37
+ hatch fmt --check
37
38
  - name: Publish Unit Test Results
38
39
  uses: EnricoMi/publish-unit-test-result-action@v2
39
40
  if: always()
@@ -41,7 +41,9 @@ htmlcov/
41
41
  .coverage.*
42
42
  .cache
43
43
  nosetests.xml
44
+ coverage.lcov
44
45
  coverage.xml
46
+ test-results.xml
45
47
  *,cover
46
48
  .hypothesis/
47
49
  tests/*.log
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: hdx-python-utilities
3
- Version: 3.6.7
3
+ Version: 3.8.2
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>
@@ -25,17 +25,19 @@ Classifier: Programming Language :: Python :: 3.11
25
25
  Classifier: Programming Language :: Python :: 3.12
26
26
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
27
  Requires-Python: >=3.8
28
- Requires-Dist: frictionless>=5.16.1
28
+ Requires-Dist: frictionless>=5.18.0
29
29
  Requires-Dist: ijson>=3.2.3
30
30
  Requires-Dist: jsonlines>=4.0.0
31
31
  Requires-Dist: loguru
32
32
  Requires-Dist: openpyxl>=3.1.2
33
- Requires-Dist: python-dateutil==2.8.2
33
+ Requires-Dist: pyphonetics
34
+ Requires-Dist: python-dateutil<2.9.1,>=2.9.0
34
35
  Requires-Dist: ratelimit
35
36
  Requires-Dist: requests-file
36
37
  Requires-Dist: ruamel-yaml
37
38
  Requires-Dist: tableschema-to-template>=0.0.13
38
39
  Requires-Dist: xlrd>=2.0.1
40
+ Requires-Dist: xlsx2csv
39
41
  Requires-Dist: xlwt>=1.3.0
40
42
  Provides-Extra: dev
41
43
  Requires-Dist: pre-commit; extra == 'dev'
@@ -11,5 +11,6 @@ build:
11
11
  jobs:
12
12
  pre_build:
13
13
  - pip install --upgrade mkdocs
14
+ - pip install mkdocs-material
14
15
  - pip install pydoc-markdown
15
16
  - pydoc-markdown documentation/pydoc-markdown.yaml
@@ -18,6 +18,7 @@ Python developers. Note that these are not specific to HDX.
18
18
  1. [State utility](#state-utility)
19
19
  1. [Path utilities](#path-utilities)
20
20
  1. [Text processing](#text-processing)
21
+ 1. [Matching utilities](#matching-utilities)
21
22
  1. [Encoding utilities](#encoding-utilities)
22
23
  1. [Check valid UUID](#valid-uuid)
23
24
  1. [Easy building and packaging](#easy-building-and-packaging)
@@ -31,6 +32,12 @@ The code for the library is [here](https://github.com/OCHA-DAP/hdx-python-utilit
31
32
  The library has detailed API documentation which can be found in the menu at the top.
32
33
 
33
34
  ## Breaking Changes
35
+ From 3.8.0, multiple_replace, match_template_variables, earliest_index,
36
+ get_matching_text_in_strs, get_matching_text,
37
+ get_matching_then_nonmatching_text moved from hdx.utilities.text to
38
+ hdx.utilities.matching. ErrorOnExit renamed ErrorHandler with changed
39
+ functionality.
40
+
34
41
  From 3.5.5, Python 3.7 no longer supported
35
42
 
36
43
  From 3.3.7, improved parse_date and parse_date_range by default will attempt to parse
@@ -648,17 +655,23 @@ Then use the logger like this:
648
655
  There is a class that allows collecting of errors to be logged later, typically on exit.
649
656
  It is called ErrorsOnExit and can be used as follows:
650
657
 
651
- with ErrorsOnExit() as errors:
658
+ with ErrorsHandler() as errors:
652
659
  ...
653
- errors.add("MY ERROR MESSAGE")
660
+ errors.add_message("MY ERROR MESSAGE")
661
+ errors.add_message("MY WARNING MESSAGE", "category 1", "warning")
654
662
  ...
655
- errors.add("ANOTHER ERROR MESSAGE")
656
-
657
- The above code will collect the errors, in this case "MY ERROR MESSAGE" and "ANOTHER
658
- ERROR MESSAGE". On leaving the `with` block, the errors will be logged and the code will
659
- exit with the error code 1 (ie. `sys.exit(1)` will be called). If there are no errors,
660
- the code will not exit and execution will continue after the `with` block (ie.
661
- `sys.exit(1)` will not be called).
663
+ errors.add("ERROR MESSAGE", "category 1", "warning")
664
+ errors.add("ANOTHER ERROR MESSAGE", "category 1", "warning")
665
+
666
+ The above code will collect the errors and warnings, in this case
667
+ "MY ERROR MESSAGE", "category 1 - ERROR MESSAGE",
668
+ "category 1 - ANOTHER ERROR MESSAGE" and "category 1 - MY WARNING MESSAGE".
669
+ On leaving the `with` block, the errors and warnings will be logged by category
670
+ and sorted. The code will exit with the error code 1 (ie.`sys.exit(1)` will be
671
+ called) if there are errors and `should_exit_on_error` is True (the default
672
+ for this parameter in the constructor). If there are no errors, the code will
673
+ not exit and execution will continue after the `with` block (ie.`sys.exit(1)`
674
+ will not be called).
662
675
 
663
676
  ## State utility
664
677
 
@@ -785,6 +798,9 @@ Examples:
785
798
 
786
799
  a = "The quick brown fox jumped over the lazy dog. It was so fast!"
787
800
 
801
+ # Normalise text eg. to support name matching
802
+ assert normalise("£^*& ()+-[]<>?|\ Al DhaleZ'eÉ / الضالع,,..1234''#~~### ") == "al dhalezee 1234"
803
+
788
804
  # Remove whitespace and punctuation from end of string
789
805
  assert remove_end_characters('lalala,.,"') == "lalala"
790
806
  assert remove_end_characters('lalala, .\t/,"', f"{punctuation}{whitespace}" == "lalala"
@@ -800,13 +816,35 @@ Examples:
800
816
  assert remove_string("lala, 01/02/2020 ", "01/02/2020", PUNCTUATION_MINUS_BRACKETS) == "lala "
801
817
  assert remove_string("lala,(01/02/2020) ", "01/02/2020", PUNCTUATION_MINUS_BRACKETS) == "lala,() "
802
818
 
819
+ # Extract words from a string sentence into a list
820
+ result = get_words_in_sentence("Korea (Democratic People's Republic of)")
821
+ assert result == ["Korea", "Democratic", "People's", "Republic", "of"]
822
+
823
+ ## Matching utilities
824
+
825
+ Examples:
826
+
827
+ possible_names = ["Al Maharah", "Ad Dali", "Dhamar"]
828
+ phonetics = Phonetics()
829
+ assert phonetics.match(possible_names, "al dali") == 1
830
+
831
+ org_type_lookup = {"Donor": "433", "National NGO": "441", "Other": "443"}
832
+ lookup = {
833
+ normalise(k): v for k, v in org_type_lookup.items()
834
+ }
835
+ assert get_code_from_name("NATIONAL_NGO", lookup, [], fuzzy_match=False) == "441"
836
+
837
+ a = "The quick brown fox jumped over the lazy dog. It was so fast!"
838
+
803
839
  # Replace multiple strings in a string simultaneously
804
840
  result = multiple_replace(a, {"quick": "slow", "fast": "slow", "lazy": "busy"})
805
841
  assert result == "The slow brown fox jumped over the busy dog. It was so slow!"
806
842
 
807
- # Extract words from a string sentence into a list
808
- result = get_words_in_sentence("Korea (Democratic People's Republic of)")
809
- assert result == ["Korea", "Democratic", "People's", "Republic", "of"]
843
+ # Look for template variables in a string (ie. {{XXX}})
844
+ assert match_template_variables("dasdda{{abc}}gff") == ("{{abc}}", "abc")
845
+
846
+ # Search a string for each of a list of strings and return the earliest index
847
+ assert earliest_index(a, ["dog", "lala", "fox", "haha", "quick"]) == 4
810
848
 
811
849
  # Find matching text in strings
812
850
  a = "The quick brown fox jumped over the lazy dog. It was so fast!"
@@ -815,11 +853,6 @@ Examples:
815
853
  result = get_matching_text([a, b, c], match_min_size=10)
816
854
  assert result == " brown fox over the It was so fast!"
817
855
 
818
- # Search a string for each of a list of strings and return the earliest index
819
- assert earliest_index(a, ["dog", "lala", "fox", "haha", "quick"]) == 4
820
-
821
- # Look for template variables in a string (ie. {{XXX}})
822
- assert match_template_variables("dasdda{{abc}}gff") == ("{{abc}}", "abc")
823
856
 
824
857
  ## Encoding utilities
825
858
 
@@ -9,7 +9,7 @@ renderer:
9
9
  output_directory: docs
10
10
  mkdocs_config:
11
11
  site_name: HDX Python Utilities
12
- theme: mkdocs
12
+ theme: material
13
13
  repo_url: "https://github.com/OCHA-DAP/hdx-python-utilities"
14
14
  markdown:
15
15
  source_linker:
@@ -36,7 +36,7 @@ requires-python = ">=3.8"
36
36
  # Extras for frictionless[excel,json] added explicitly
37
37
  # for conda-forge compatibility
38
38
  dependencies = [
39
- "frictionless>=5.16.1",
39
+ "frictionless>=5.18.0",
40
40
  # frictionless[excel]
41
41
  "openpyxl>=3.1.2",
42
42
  "tableschema-to-template>=0.0.13",
@@ -47,10 +47,12 @@ dependencies = [
47
47
  "jsonlines>=4.0.0",
48
48
  # /end frictionless extras
49
49
  "loguru",
50
- "python-dateutil==2.8.2",
50
+ "pyphonetics",
51
+ "python-dateutil>=2.9.0, <2.9.1",
51
52
  "ratelimit",
52
53
  "requests-file",
53
54
  "ruamel.yaml",
55
+ "xlsx2csv",
54
56
  ]
55
57
  dynamic = ["version"]
56
58
 
@@ -91,25 +93,24 @@ version_scheme = "python-simplified-semver"
91
93
 
92
94
  # Tests
93
95
 
94
- [tool.hatch.envs.test]
96
+ [tool.hatch.envs.hatch-test]
95
97
  features = ["html", "email", "test"]
96
98
 
97
- [tool.hatch.envs.test.scripts]
98
- test = """
99
+ [[tool.hatch.envs.hatch-test.matrix]]
100
+ python = ["3.12"]
101
+
102
+ [tool.hatch.envs.hatch-test.scripts]
103
+ run = """
99
104
  pytest -c .config/pytest.ini --rootdir=. --junitxml=test-results.xml \
100
105
  --cov --cov-config=.config/coveragerc --no-cov-on-fail \
101
106
  --cov-report=lcov --cov-report=term-missing
102
107
  """
103
108
 
104
- [[tool.hatch.envs.test.matrix]]
105
- python = ["3.11"]
106
-
107
- [tool.hatch.envs.lint]
108
- detached = true
109
- dependencies = ["ruff"]
109
+ [tool.hatch.envs.hatch-static-analysis]
110
+ dependencies = ["ruff==0.8.6"]
110
111
 
111
- [tool.hatch.envs.lint.scripts]
112
- style = [
113
- "ruff check --config .config/ruff.toml --diff {args:.}",
114
- "ruff format --config .config/ruff.toml --diff {args:.}",
115
- ]
112
+ [tool.hatch.envs.hatch-static-analysis.scripts]
113
+ format-check = ["ruff format --config .config/ruff.toml --check --diff {args:.}",]
114
+ format-fix = ["ruff format --config .config/ruff.toml {args:.}",]
115
+ lint-check = ["ruff check --config .config/ruff.toml {args:.}",]
116
+ lint-fix = ["ruff check --config .config/ruff.toml --fix {args:.}",]
@@ -1,148 +1,151 @@
1
- #
2
- # This file is autogenerated by pip-compile with Python 3.11
3
- # by the following command:
4
- #
5
- # pip-compile --all-extras --output-file=requirements.txt pyproject.toml
6
- #
7
- annotated-types==0.6.0
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
3
+ annotated-types==0.7.0
8
4
  # via pydantic
9
- attrs==23.2.0
5
+ attrs==24.3.0
10
6
  # via
11
7
  # frictionless
12
8
  # jsonlines
13
9
  # jsonschema
10
+ # referencing
14
11
  beautifulsoup4==4.12.3
15
12
  # via hdx-python-utilities (pyproject.toml)
16
- certifi==2024.2.2
13
+ certifi==2024.12.14
17
14
  # via requests
18
15
  cfgv==3.4.0
19
16
  # via pre-commit
20
17
  chardet==5.2.0
21
18
  # via frictionless
22
- charset-normalizer==3.3.2
19
+ charset-normalizer==3.4.1
23
20
  # via requests
24
- click==8.1.7
21
+ click==8.1.8
25
22
  # via typer
26
- colorama==0.4.6
27
- # via typer
28
- coverage[toml]==7.4.4
23
+ coverage==7.6.10
29
24
  # via pytest-cov
30
- distlib==0.3.8
25
+ distlib==0.3.9
31
26
  # via virtualenv
32
- dnspython==2.6.1
27
+ dnspython==2.7.0
33
28
  # via email-validator
34
- email-validator==2.1.1
29
+ email-validator==2.2.0
35
30
  # via hdx-python-utilities (pyproject.toml)
36
- et-xmlfile==1.1.0
31
+ et-xmlfile==2.0.0
37
32
  # via openpyxl
38
- filelock==3.13.1
33
+ filelock==3.16.1
39
34
  # via virtualenv
40
- frictionless==5.16.1
35
+ frictionless==5.18.0
41
36
  # via hdx-python-utilities (pyproject.toml)
42
37
  html5lib==1.1
43
38
  # via hdx-python-utilities (pyproject.toml)
44
- humanize==4.9.0
39
+ humanize==4.11.0
45
40
  # via frictionless
46
- identify==2.5.35
41
+ identify==2.6.5
47
42
  # via pre-commit
48
- idna==3.6
43
+ idna==3.10
49
44
  # via
50
45
  # email-validator
51
46
  # requests
52
- ijson==3.2.3
47
+ ijson==3.3.0
53
48
  # via hdx-python-utilities (pyproject.toml)
54
49
  iniconfig==2.0.0
55
50
  # via pytest
56
- isodate==0.6.1
51
+ isodate==0.7.2
57
52
  # via frictionless
58
- jinja2==3.1.3
53
+ jinja2==3.1.5
59
54
  # via frictionless
60
55
  jsonlines==4.0.0
61
56
  # via hdx-python-utilities (pyproject.toml)
62
- jsonschema==4.17.3
57
+ jsonschema==4.23.0
63
58
  # via
64
59
  # frictionless
65
60
  # tableschema-to-template
66
- loguru==0.7.2
61
+ jsonschema-specifications==2024.10.1
62
+ # via jsonschema
63
+ loguru==0.7.3
67
64
  # via
68
65
  # hdx-python-utilities (pyproject.toml)
69
66
  # pytest-loguru
70
67
  markdown-it-py==3.0.0
71
68
  # via rich
72
- marko==2.0.3
69
+ marko==2.1.2
73
70
  # via frictionless
74
- markupsafe==2.1.5
71
+ markupsafe==3.0.2
75
72
  # via jinja2
76
73
  mdurl==0.1.2
77
74
  # via markdown-it-py
78
- nodeenv==1.8.0
75
+ nodeenv==1.9.1
79
76
  # via pre-commit
80
- openpyxl==3.1.2
77
+ openpyxl==3.1.5
81
78
  # via hdx-python-utilities (pyproject.toml)
82
- packaging==24.0
79
+ packaging==24.2
83
80
  # via pytest
84
81
  petl==1.7.15
85
82
  # via frictionless
86
- platformdirs==4.2.0
83
+ platformdirs==4.3.6
87
84
  # via virtualenv
88
- pluggy==1.4.0
85
+ pluggy==1.5.0
89
86
  # via pytest
90
- pre-commit==3.6.2
87
+ pre-commit==4.0.1
91
88
  # via hdx-python-utilities (pyproject.toml)
92
- pydantic==2.6.4
89
+ pydantic==2.10.5
93
90
  # via frictionless
94
- pydantic-core==2.16.3
91
+ pydantic-core==2.27.2
95
92
  # via pydantic
96
- pygments==2.17.2
93
+ pygments==2.19.1
97
94
  # via rich
98
- pyrsistent==0.20.0
99
- # via jsonschema
100
- pytest==8.1.1
95
+ pyphonetics==0.5.3
96
+ # via hdx-python-utilities (pyproject.toml)
97
+ pytest==8.3.4
101
98
  # via
102
99
  # hdx-python-utilities (pyproject.toml)
103
100
  # pytest-cov
104
- # pytest-loguru
105
- pytest-cov==4.1.0
101
+ pytest-cov==6.0.0
106
102
  # via hdx-python-utilities (pyproject.toml)
107
- pytest-loguru==0.3.0
103
+ pytest-loguru==0.4.0
108
104
  # via hdx-python-utilities (pyproject.toml)
109
- python-dateutil==2.8.2
105
+ python-dateutil==2.9.0.post0
110
106
  # via
111
- # frictionless
112
107
  # hdx-python-utilities (pyproject.toml)
108
+ # frictionless
113
109
  python-slugify==8.0.4
114
110
  # via frictionless
115
- pyyaml==6.0.1
111
+ pyyaml==6.0.2
116
112
  # via
117
113
  # frictionless
118
114
  # pre-commit
119
115
  # tableschema-to-template
120
116
  ratelimit==2.2.1
121
117
  # via hdx-python-utilities (pyproject.toml)
122
- requests==2.31.0
118
+ referencing==0.35.1
119
+ # via
120
+ # jsonschema
121
+ # jsonschema-specifications
122
+ requests==2.32.3
123
123
  # via
124
124
  # frictionless
125
125
  # requests-file
126
- requests-file==2.0.0
126
+ requests-file==2.1.0
127
127
  # via hdx-python-utilities (pyproject.toml)
128
128
  rfc3986==2.0.0
129
129
  # via frictionless
130
- rich==13.7.1
130
+ rich==13.9.4
131
131
  # via typer
132
- ruamel-yaml==0.18.6
132
+ rpds-py==0.22.3
133
+ # via
134
+ # jsonschema
135
+ # referencing
136
+ ruamel-yaml==0.18.10
133
137
  # via hdx-python-utilities (pyproject.toml)
134
- ruamel-yaml-clib==0.2.8
138
+ ruamel-yaml-clib==0.2.12
135
139
  # via ruamel-yaml
136
140
  shellingham==1.5.4
137
141
  # via typer
138
- simpleeval==0.9.13
142
+ simpleeval==1.0.3
139
143
  # via frictionless
140
- six==1.16.0
144
+ six==1.17.0
141
145
  # via
142
146
  # html5lib
143
- # isodate
144
147
  # python-dateutil
145
- soupsieve==2.5
148
+ soupsieve==2.6
146
149
  # via beautifulsoup4
147
150
  stringcase==1.2.0
148
151
  # via frictionless
@@ -152,28 +155,29 @@ tabulate==0.9.0
152
155
  # via frictionless
153
156
  text-unidecode==1.3
154
157
  # via python-slugify
155
- typer[all]==0.9.0
158
+ typer==0.15.1
156
159
  # via frictionless
157
- typing-extensions==4.10.0
160
+ typing-extensions==4.12.2
158
161
  # via
159
162
  # frictionless
160
163
  # pydantic
161
164
  # pydantic-core
162
165
  # typer
163
- urllib3==2.2.1
166
+ unidecode==1.3.8
167
+ # via pyphonetics
168
+ urllib3==2.3.0
164
169
  # via requests
165
- validators==0.22.0
170
+ validators==0.34.0
166
171
  # via frictionless
167
- virtualenv==20.25.1
172
+ virtualenv==20.28.1
168
173
  # via pre-commit
169
174
  webencodings==0.5.1
170
175
  # via html5lib
171
176
  xlrd==2.0.1
172
177
  # via hdx-python-utilities (pyproject.toml)
178
+ xlsx2csv==0.8.4
179
+ # via hdx-python-utilities (pyproject.toml)
173
180
  xlsxwriter==3.2.0
174
181
  # via tableschema-to-template
175
182
  xlwt==1.3.0
176
183
  # via hdx-python-utilities (pyproject.toml)
177
-
178
- # The following packages are considered to be unsafe in a requirements file:
179
- # setuptools
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '3.6.7'
16
- __version_tuple__ = version_tuple = (3, 6, 7)
15
+ __version__ = version = '3.8.2'
16
+ __version_tuple__ = version_tuple = (3, 8, 2)
@@ -177,8 +177,10 @@ class _ymd(list): # pragma: no cover
177
177
  self.ystridx = len(self) - 1
178
178
 
179
179
  def _resolve_from_stridxs(self, strids):
180
- """Try to resolve the identities of year/month/day elements using
181
- ystridx, mstridx, and dstridx, if enough of these are specified."""
180
+ """
181
+ Try to resolve the identities of year/month/day elements using
182
+ ystridx, mstridx, and dstridx, if enough of these are specified.
183
+ """
182
184
  if len(self) == 3 and len(strids) == 2:
183
185
  # we can back out the remaining stridx value
184
186
  missing = [x for x in range(3) if x not in strids.values()]
@@ -301,8 +303,9 @@ class DateParser(dateutil.parser.parser): # pragma: no cover
301
303
  fuzzy=False,
302
304
  fuzzy_with_tokens=False,
303
305
  ):
304
- """Private method which performs the heavy lifting of parsing, called
305
- from ``parse()``, which passes on its ``kwargs`` to this function.
306
+ """
307
+ Private method which performs the heavy lifting of parsing, called from
308
+ ``parse()``, which passes on its ``kwargs`` to this function.
306
309
 
307
310
  :param timestr:
308
311
  The string to parse.
@@ -553,7 +556,8 @@ DEFAULTPARSER = DateParser(parserinfo(dayfirst=True))
553
556
  def parse(
554
557
  timestr, default=None, ignoretz=False, tzinfos=None, **kwargs
555
558
  ): # pragma: no cover
556
- """Parse the date/time string into a :class:`datetime.datetime` object.
559
+ """
560
+ Parse the date/time string into a :class:`datetime.datetime` object.
557
561
 
558
562
  :param timestr:
559
563
  Any date/time string using the supported formats.
@@ -650,6 +654,15 @@ def now_utc() -> datetime:
650
654
  return datetime.now(timezone.utc)
651
655
 
652
656
 
657
+ def now_utc_notz() -> datetime:
658
+ """Return now in UTC but with timezone removed.
659
+
660
+ Returns:
661
+ datetime: Now in UTC but with timezone removed
662
+ """
663
+ return datetime.now(timezone.utc).replace(tzinfo=None)
664
+
665
+
653
666
  def parse_date_range(
654
667
  string: str,
655
668
  date_format: Optional[str] = None,