hapi-schema 0.7.0__tar.gz → 0.7.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 (81) hide show
  1. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/.config/ruff.toml +4 -1
  2. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/PKG-INFO +1 -1
  3. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/changelog.md +11 -1
  4. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/contributing.md +16 -0
  5. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/requirements.txt +11 -9
  6. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/_version.py +2 -2
  7. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_food_security.py +0 -4
  8. hapi_schema-0.7.2/src/hapi_schema/db_patch.py +45 -0
  9. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/conftest.py +4 -0
  10. hapi_schema-0.7.2/tests/sample_data/data_patch.py +31 -0
  11. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_food_security.py +1 -39
  12. hapi_schema-0.7.2/tests/test_patch.py +41 -0
  13. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/.config/coveragerc +0 -0
  14. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/.config/pre-commit-config.yaml +0 -0
  15. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/.config/pytest.ini +0 -0
  16. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/.github/workflows/publish.yaml +0 -0
  17. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/.github/workflows/run-python-tests.yaml +0 -0
  18. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/.gitignore +0 -0
  19. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/LICENSE +0 -0
  20. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/README.md +0 -0
  21. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/pyproject.toml +0 -0
  22. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/__init__.py +0 -0
  23. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_admin1.py +0 -0
  24. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_admin2.py +0 -0
  25. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_age_range.py +0 -0
  26. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_dataset.py +0 -0
  27. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_gender.py +0 -0
  28. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_humanitarian_needs.py +0 -0
  29. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_ipc_phase.py +0 -0
  30. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_ipc_type.py +0 -0
  31. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_location.py +0 -0
  32. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_national_risk.py +0 -0
  33. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_operational_presence.py +0 -0
  34. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_org.py +0 -0
  35. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_org_type.py +0 -0
  36. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_population.py +0 -0
  37. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_population_group.py +0 -0
  38. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_population_status.py +0 -0
  39. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_resource.py +0 -0
  40. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/db_sector.py +0 -0
  41. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/utils/__init__.py +0 -0
  42. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/utils/base.py +0 -0
  43. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/src/hapi_schema/utils/view_params.py +0 -0
  44. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/__init__.py +0 -0
  45. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_admin1.py +0 -0
  46. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_admin2.py +0 -0
  47. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_age_range.py +0 -0
  48. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_dataset.py +0 -0
  49. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_food_security.py +0 -0
  50. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_gender.py +0 -0
  51. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_humanitarian_needs.py +0 -0
  52. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_ipc_phase.py +0 -0
  53. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_ipc_type.py +0 -0
  54. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_location.py +0 -0
  55. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_national_risk.py +0 -0
  56. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_operational_presence.py +0 -0
  57. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_org.py +0 -0
  58. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_org_type.py +0 -0
  59. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_population.py +0 -0
  60. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_population_group.py +0 -0
  61. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_population_status.py +0 -0
  62. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_resource.py +0 -0
  63. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/sample_data/data_sector.py +0 -0
  64. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_admin1.py +0 -0
  65. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_admin2.py +0 -0
  66. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_age_range.py +0 -0
  67. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_dataset.py +0 -0
  68. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_gender.py +0 -0
  69. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_humanitarian_needs.py +0 -0
  70. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_ipc_phase.py +0 -0
  71. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_ipc_type.py +0 -0
  72. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_location.py +0 -0
  73. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_national_risk.py +0 -0
  74. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_operational_presence.py +0 -0
  75. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_org.py +0 -0
  76. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_org_type.py +0 -0
  77. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_population.py +0 -0
  78. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_population_group.py +0 -0
  79. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_population_status.py +0 -0
  80. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_resource.py +0 -0
  81. {hapi_schema-0.7.0 → hapi_schema-0.7.2}/tests/test_sector.py +0 -0
@@ -9,7 +9,10 @@ select = [
9
9
  "I" # isort
10
10
  ]
11
11
  ignore = [
12
- "E501" # Line too long
12
+ "E501", # Line too long
13
+ "D100", # missing-module-docstring
14
+ "D101", # missing-class-docstring
15
+ "D103" # missing-function-docstring
13
16
  ]
14
17
 
15
18
  [lint.isort]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hapi-schema
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: HAPI database schema specified in SQLAlchemy
5
5
  Project-URL: Homepage, https://github.com/OCHA-DAP/hapi-schemas
6
6
  Author-email: Simon Johnson <simon.johnson@un.org>
@@ -5,7 +5,17 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [0.7.0]
8
+ ## [0.7.2]
9
+
10
+ ### Added
11
+
12
+ - Patches table
13
+
14
+ ## [0.7.1]
15
+
16
+ ### Changed
17
+
18
+ - Removed constraint from food security
9
19
 
10
20
  ### Added
11
21
  - Missing constraints
@@ -13,6 +13,10 @@ development by running:
13
13
 
14
14
  pip install -r requirements.txt
15
15
 
16
+ and then make an editable installation of the package:
17
+
18
+ pip install -e .
19
+
16
20
  ## Pre-Commit
17
21
 
18
22
  Also be sure to install `pre-commit`, which is run every time
@@ -58,3 +62,15 @@ Any changes to the dependencies will be automatically reflected in
58
62
  the file without committing by executing:
59
63
 
60
64
  pre-commit run pip-compile --all-files --config=.config/pre-commit-config.yaml
65
+
66
+ ## Adding a new table
67
+
68
+ To add a new table to the schema:
69
+
70
+ 1. Add a `db_[table_name].py` file to `src/hapi_schema` which implements the table as a class derived from `hapi_schema.utils.base.Base`
71
+ 2. Add a file `data_[table_name].py` to `tests/sample_data` which contains three rows of data for the new table as a list of dictionaries.
72
+ 3. Add the table to the `tests/conftest.py` with an import like:
73
+ `from sample_data.data_[table_name] import data_[table_name]`
74
+ and data inserted with:
75
+ `session.execute(insert(DBPatch), data_patch)`
76
+ 4. Add a test file for the new table as `tests/test_[table_name].py`
@@ -6,13 +6,15 @@
6
6
  #
7
7
  cfgv==3.4.0
8
8
  # via pre-commit
9
- coverage[toml]==7.4.3
9
+ colorama==0.4.6
10
+ # via pytest
11
+ coverage[toml]==7.4.4
10
12
  # via
11
13
  # coverage
12
14
  # pytest-cov
13
15
  distlib==0.3.8
14
16
  # via virtualenv
15
- filelock==3.13.1
17
+ filelock==3.13.4
16
18
  # via virtualenv
17
19
  greenlet==3.0.3
18
20
  # via sqlalchemy
@@ -24,29 +26,29 @@ iniconfig==2.0.0
24
26
  # via pytest
25
27
  nodeenv==1.8.0
26
28
  # via pre-commit
27
- packaging==23.2
29
+ packaging==24.0
28
30
  # via pytest
29
31
  platformdirs==4.2.0
30
32
  # via virtualenv
31
33
  pluggy==1.4.0
32
34
  # via pytest
33
- pre-commit==3.6.2
35
+ pre-commit==3.7.0
34
36
  # via hapi-schema (pyproject.toml)
35
- pytest==8.0.2
37
+ pytest==8.1.1
36
38
  # via
37
39
  # hapi-schema (pyproject.toml)
38
40
  # pytest-cov
39
- pytest-cov==4.1.0
41
+ pytest-cov==5.0.0
40
42
  # via hapi-schema (pyproject.toml)
41
43
  pyyaml==6.0.1
42
44
  # via pre-commit
43
- sqlalchemy==2.0.27
45
+ sqlalchemy==2.0.29
44
46
  # via
45
47
  # hapi-schema (pyproject.toml)
46
48
  # hdx-python-database
47
- typing-extensions==4.9.0
49
+ typing-extensions==4.11.0
48
50
  # via sqlalchemy
49
- virtualenv==20.25.1
51
+ virtualenv==20.25.3
50
52
  # via pre-commit
51
53
 
52
54
  # The following packages are considered to be unsafe in a requirements file:
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.7.0'
16
- __version_tuple__ = version_tuple = (0, 7, 0)
15
+ __version__ = version = '0.7.2'
16
+ __version_tuple__ = version_tuple = (0, 7, 2)
@@ -28,10 +28,6 @@ from hapi_schema.utils.view_params import ViewParams
28
28
  class DBFoodSecurity(Base):
29
29
  __tablename__ = "food_security"
30
30
  __table_args__ = (
31
- CheckConstraint(
32
- "population_fraction_in_phase >= 0 AND population_fraction_in_phase <=1",
33
- name="population_fraction_in_phase",
34
- ),
35
31
  CheckConstraint(
36
32
  "(reference_period_end >= reference_period_start) OR (reference_period_start IS NULL)",
37
33
  name="reference_period",
@@ -0,0 +1,45 @@
1
+ """Patch table"""
2
+
3
+ import enum
4
+ from datetime import datetime
5
+
6
+ from sqlalchemy import DateTime, Enum, Integer, String
7
+ from sqlalchemy.orm import Mapped, mapped_column
8
+
9
+ from hapi_schema.utils.base import Base
10
+
11
+
12
+ class StateEnum(str, enum.Enum):
13
+ discovered = 1
14
+ executed = 2
15
+ failed = 3
16
+ canceled = 4
17
+
18
+
19
+ class DBPatch(Base):
20
+ __tablename__ = "patch"
21
+ # __table_args__ = (
22
+ # Index(None, "patch_sequence_number"),
23
+ # Index(None, "state"),
24
+ # )
25
+
26
+ id: Mapped[int] = mapped_column(Integer, primary_key=True)
27
+ patch_sequence_number: Mapped[int] = mapped_column(
28
+ Integer, nullable=False, index=True
29
+ )
30
+ commit_hash: Mapped[str] = mapped_column(
31
+ String(48), unique=True, nullable=False
32
+ )
33
+ commit_date: Mapped[datetime] = mapped_column(DateTime, nullable=False)
34
+ patch_path: Mapped[str] = mapped_column(String(128), nullable=False)
35
+ permanent_download_url: Mapped[str] = mapped_column(
36
+ String(1024), nullable=False, unique=True
37
+ )
38
+ state: Mapped[StateEnum] = mapped_column(
39
+ Enum(StateEnum), nullable=False, index=True
40
+ )
41
+ # discovered -> it was found in the patch repo
42
+ # executed -> the patch was executed successfully
43
+ # failed -> HWA tried to execute the patch but it failed (either pre-conditions
44
+ # were not met OR the transaction failed and was rolled back)
45
+ # canceled -> it was marked as canceled in the patch repo
@@ -22,6 +22,7 @@ from hapi_schema.db_operational_presence import (
22
22
  )
23
23
  from hapi_schema.db_org import DBOrg
24
24
  from hapi_schema.db_org_type import DBOrgType
25
+ from hapi_schema.db_patch import DBPatch
25
26
  from hapi_schema.db_population import DBPopulation
26
27
  from hapi_schema.db_population_group import DBPopulationGroup
27
28
  from hapi_schema.db_population_status import DBPopulationStatus
@@ -42,6 +43,7 @@ from sample_data.data_national_risk import data_national_risk
42
43
  from sample_data.data_operational_presence import data_operational_presence
43
44
  from sample_data.data_org import data_org
44
45
  from sample_data.data_org_type import data_org_type
46
+ from sample_data.data_patch import data_patch
45
47
  from sample_data.data_population import data_population
46
48
  from sample_data.data_population_group import data_population_group
47
49
  from sample_data.data_population_status import data_population_status
@@ -85,6 +87,8 @@ def engine():
85
87
  session.execute(insert(DBFoodSecurity), data_food_security)
86
88
  session.execute(insert(DBHumanitarianNeeds), data_humanitarian_needs)
87
89
 
90
+ session.execute(insert(DBPatch), data_patch)
91
+
88
92
  session.commit()
89
93
 
90
94
  return engine
@@ -0,0 +1,31 @@
1
+ from datetime import datetime
2
+
3
+ data_patch = [
4
+ dict(
5
+ id=1,
6
+ patch_sequence_number=1,
7
+ commit_hash="66e7e589a1224a1832ba7360817dda7a7d9313cf",
8
+ commit_date=datetime(2023, 1, 1),
9
+ patch_path="2024/01",
10
+ permanent_download_url="https://github.com/OCHA-DAP/hapi-patch-repo/blob/66e7e589a1224a1832ba7360817dda7a7d9313cf/2024/01/hapi_patch_10_hno.json",
11
+ state="executed",
12
+ ),
13
+ dict(
14
+ id=2,
15
+ patch_sequence_number=2,
16
+ commit_hash="554f18a92cf6a23a14e0f29356a6dec150f651ff",
17
+ commit_date=datetime(2023, 1, 2),
18
+ patch_path="2024/01",
19
+ permanent_download_url="https://github.com/OCHA-DAP/hapi-patch-repo/blob/554f18a92cf6a23a14e0f29356a6dec150f651ff/2024/01/hapi_patch_10_hno.json",
20
+ state="failed",
21
+ ),
22
+ dict(
23
+ id=3,
24
+ patch_sequence_number=3,
25
+ commit_hash="35ea27da009e5add8d8d227e02fd2c4bbcc84b76",
26
+ commit_date=datetime(2023, 1, 3),
27
+ patch_path="2024/01",
28
+ permanent_download_url="https://github.com/OCHA-DAP/hapi-patch-repo/blob/35ea27da009e5add8d8d227e02fd2c4bbcc84b76/2024/01/hapi_patch_10_hno.json",
29
+ state="discovered",
30
+ ),
31
+ ]
@@ -34,7 +34,7 @@ def test_reference_period_constraint(run_constraints_test):
34
34
  DBFoodSecurity(
35
35
  resource_ref=3,
36
36
  admin2_ref=4,
37
- ipc_phase_code="all",
37
+ ipc_phase_code="1",
38
38
  ipc_type_code="current",
39
39
  population_in_phase=1_000,
40
40
  population_fraction_in_phase=1,
@@ -45,41 +45,3 @@ def test_reference_period_constraint(run_constraints_test):
45
45
  ],
46
46
  expected_constraint="reference_period",
47
47
  )
48
-
49
-
50
- def test_population_fraction(run_constraints_test):
51
- """Check that pop fraction msut be between 0 and 1"""
52
- # Greater than 1
53
- run_constraints_test(
54
- new_rows=[
55
- DBFoodSecurity(
56
- resource_ref=3,
57
- admin2_ref=4,
58
- ipc_phase_code="all",
59
- ipc_type_code="current",
60
- population_in_phase=1_000,
61
- population_fraction_in_phase=10,
62
- reference_period_start=None,
63
- reference_period_end=None,
64
- source_data="DATA,DATA,DATA",
65
- )
66
- ],
67
- expected_constraint="population_fraction_in_phase",
68
- )
69
- # Less than 0
70
- run_constraints_test(
71
- new_rows=[
72
- DBFoodSecurity(
73
- resource_ref=3,
74
- admin2_ref=4,
75
- ipc_phase_code="all",
76
- ipc_type_code="current",
77
- population_in_phase=1_000,
78
- population_fraction_in_phase=-10,
79
- reference_period_start=None,
80
- reference_period_end=None,
81
- source_data="DATA,DATA,DATA",
82
- )
83
- ],
84
- expected_constraint="population_fraction_in_phase",
85
- )
@@ -0,0 +1,41 @@
1
+ import string
2
+
3
+ from sqlalchemy import create_engine
4
+
5
+ from hapi_schema.utils.base import Base
6
+
7
+
8
+ def test_db_patch(capfd):
9
+ engine = create_engine("sqlite://", echo=True)
10
+ Base.metadata.create_all(engine)
11
+
12
+ sql_table_creation_code = """CREATE TABLE patch (
13
+ id INTEGER NOT NULL,
14
+ patch_sequence_number INTEGER NOT NULL,
15
+ commit_hash VARCHAR(48) NOT NULL,
16
+ commit_date DATETIME NOT NULL,
17
+ patch_path VARCHAR(128) NOT NULL,
18
+ permanent_download_url VARCHAR(1024) NOT NULL,
19
+ state VARCHAR(10) NOT NULL,
20
+ PRIMARY KEY (id),
21
+ UNIQUE (commit_hash),
22
+ UNIQUE (permanent_download_url)
23
+ )
24
+ """
25
+ sql_patch_sequence_number_index_creation = """
26
+ CREATE INDEX ix_patch_patch_sequence_number ON patch (patch_sequence_number)
27
+ """
28
+ sql_state_index_creation = (
29
+ """CREATE INDEX ix_patch_state ON patch (state)"""
30
+ )
31
+
32
+ captured_sql, _ = capfd.readouterr()
33
+
34
+ for sql_statements in [
35
+ sql_table_creation_code,
36
+ sql_patch_sequence_number_index_creation,
37
+ sql_state_index_creation,
38
+ ]:
39
+ assert sql_statements.translate(
40
+ str.maketrans("", "", string.whitespace)
41
+ ) in captured_sql.translate(str.maketrans("", "", string.whitespace))
File without changes
File without changes
File without changes
File without changes