hdx-python-database 1.3.0__tar.gz → 1.3.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 (39) hide show
  1. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/.config/pre-commit-config.yaml +7 -6
  2. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/.github/workflows/publish.yaml +4 -3
  3. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/.github/workflows/run-python-tests.yaml +6 -5
  4. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/PKG-INFO +3 -4
  5. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/README.md +1 -2
  6. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/documentation/.readthedocs.yaml +1 -0
  7. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/documentation/main.md +49 -11
  8. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/documentation/pydoc-markdown.yaml +1 -1
  9. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/pyproject.toml +12 -16
  10. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/requirements.txt +22 -29
  11. hdx_python_database-1.3.2/src/hdx/database/__init__.py +311 -0
  12. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/src/hdx/database/_version.py +2 -2
  13. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/src/hdx/database/dburi.py +2 -0
  14. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/src/hdx/database/no_timezone.py +1 -0
  15. hdx_python_database-1.3.2/src/hdx/database/postgresql.py +95 -0
  16. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/src/hdx/database/views.py +3 -31
  17. hdx_python_database-1.3.2/tests/hdx/database/conftest.py +117 -0
  18. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/tests/hdx/database/dbtestdate.py +2 -5
  19. hdx_python_database-1.3.2/tests/hdx/database/test_database.py +59 -0
  20. hdx_python_database-1.3.2/tests/hdx/database/test_postgresql.py +30 -0
  21. hdx_python_database-1.3.2/tests/hdx/database/test_recreate.py +8 -0
  22. hdx_python_database-1.3.2/tests/hdx/database/test_reflect.py +47 -0
  23. hdx_python_database-1.3.2/tests/hdx/database/test_ssh.py +80 -0
  24. hdx_python_database-1.3.0/src/hdx/database/__init__.py +0 -152
  25. hdx_python_database-1.3.0/src/hdx/database/postgresql.py +0 -40
  26. hdx_python_database-1.3.0/tests/hdx/database/conftest.py +0 -22
  27. hdx_python_database-1.3.0/tests/hdx/database/test_database.py +0 -150
  28. hdx_python_database-1.3.0/tests/hdx/database/test_postgresql.py +0 -15
  29. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/.config/coveragerc +0 -0
  30. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/.config/pytest.ini +0 -0
  31. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/.config/ruff.toml +0 -0
  32. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/.gitignore +0 -0
  33. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/CONTRIBUTING.md +0 -0
  34. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/LICENSE +0 -0
  35. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/src/hdx/database/utils.py +0 -0
  36. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/src/hdx/database/with_timezone.py +0 -0
  37. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/tests/fixtures/test.db +0 -0
  38. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/tests/hdx/database/__init__.py +0 -0
  39. {hdx_python_database-1.3.0 → hdx_python_database-1.3.2}/tests/hdx/database/test_dburi.py +0 -0
@@ -1,14 +1,14 @@
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: v4.6.0
6
6
  hooks:
7
7
  - id: trailing-whitespace
8
8
  - id: end-of-file-fixer
9
9
  - id: check-ast
10
10
  - repo: https://github.com/astral-sh/ruff-pre-commit
11
- rev: v0.1.14
11
+ rev: v0.5.6
12
12
  hooks:
13
13
  # Run the linter.
14
14
  - id: ruff
@@ -16,10 +16,11 @@ repos:
16
16
  # Run the formatter.
17
17
  - id: ruff-format
18
18
  args: [--config, .config/ruff.toml]
19
- - repo: https://github.com/jazzband/pip-tools
20
- rev: 7.3.0
19
+ - repo: https://github.com/astral-sh/uv-pre-commit
20
+ rev: 0.2.33
21
21
  hooks:
22
+ # Run the pip compile
22
23
  - id: pip-compile
23
24
  name: pip-compile requirements.txt
24
25
  files: pyproject.toml
25
- args: [pyproject.toml, --resolver=backtracking, --all-extras, --upgrade, -q, -o, requirements.txt]
26
+ args: [ pyproject.toml, --resolver=backtracking, --all-extras, --upgrade, -q, -o, requirements.txt ]
@@ -9,19 +9,20 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
 
11
11
  steps:
12
- - uses: actions/checkout@v3
12
+ - uses: actions/checkout@v4
13
13
  - name: Get history and tags for versioning to work
14
14
  run: |
15
15
  git fetch --prune --unshallow
16
16
  git fetch --depth=1 origin +refs/tags/*:refs/tags/*
17
17
  - name: Set up Python
18
- uses: actions/setup-python@v4
18
+ uses: actions/setup-python@v5
19
19
  with:
20
20
  python-version: '3.x'
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
@@ -18,22 +18,23 @@ jobs:
18
18
  runs-on: ubuntu-latest
19
19
 
20
20
  steps:
21
- - uses: actions/checkout@v3
21
+ - uses: actions/checkout@v4
22
22
  - name: Set up Python
23
- uses: actions/setup-python@v4
23
+ uses: actions/setup-python@v5
24
24
  with:
25
25
  python-version: '3.x'
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()
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: hdx-python-database
3
- Version: 1.3.0
3
+ Version: 1.3.2
4
4
  Summary: HDX Python database utilities
5
5
  Project-URL: Homepage, https://github.com/OCHA-DAP/hdx-python-database
6
6
  Author-email: Michael Rans <rans@email.com>
@@ -39,8 +39,7 @@ Description-Content-Type: text/markdown
39
39
 
40
40
  [![Build Status](https://github.com/OCHA-DAP/hdx-python-database/actions/workflows/run-python-tests.yaml/badge.svg)](https://github.com/OCHA-DAP/hdx-python-database/actions/workflows/run-python-tests.yaml)
41
41
  [![Coverage Status](https://coveralls.io/repos/github/OCHA-DAP/hdx-python-database/badge.svg?branch=main&ts=1)](https://coveralls.io/github/OCHA-DAP/hdx-python-database?branch=main)
42
- [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
43
- [![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
42
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
44
43
  [![Downloads](https://img.shields.io/pypi/dm/hdx-python-database.svg)](https://pypistats.org/packages/hdx-python-database)
45
44
 
46
45
  The HDX Python Database Library provides utilities for connecting to databases in a standard way including
@@ -1,7 +1,6 @@
1
1
  [![Build Status](https://github.com/OCHA-DAP/hdx-python-database/actions/workflows/run-python-tests.yaml/badge.svg)](https://github.com/OCHA-DAP/hdx-python-database/actions/workflows/run-python-tests.yaml)
2
2
  [![Coverage Status](https://coveralls.io/repos/github/OCHA-DAP/hdx-python-database/badge.svg?branch=main&ts=1)](https://coveralls.io/github/OCHA-DAP/hdx-python-database?branch=main)
3
- [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
4
- [![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
3
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
5
4
  [![Downloads](https://img.shields.io/pypi/dm/hdx-python-database.svg)](https://pypistats.org/packages/hdx-python-database)
6
5
 
7
6
  The HDX Python Database Library provides utilities for connecting to databases in a standard way including
@@ -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
@@ -22,6 +22,13 @@ installed with extra `postgresql`:
22
22
  pip install hdx-python-database[postgresql]
23
23
 
24
24
  ## Breaking changes
25
+ From 1.3.1, Database class refactored. With returns Database not Session
26
+ object and can accept a prepare function called before
27
+ Base.metadata.create_all. get_session can be used to obtain the session.
28
+ get_engine, get_reflected_classes, get_prepare_results methods added.
29
+ build_view, build_views move into Database class and renamed prepare_view and
30
+ prepare_views.
31
+
25
32
  From 1.2.8, the sshtunnel dependency is optional.
26
33
 
27
34
  From 1.2.7, default table names are no longer plural. The camel case class name
@@ -51,8 +58,13 @@ Versions from 1.0.6 no longer support Python 2.7.
51
58
 
52
59
  ## Database
53
60
 
61
+ A fresh schema can be created using the function `recreate_schema`. Any
62
+ existing schema with that name will be dropped eg.
63
+
64
+ Database.recreate_schema(engine, db_uri)
65
+
54
66
  Your SQLAlchemy database tables must inherit from `Base` in
55
- `hdx.database.no_timezone` or `hdx.database.with_timezone` eg. :
67
+ `hdx.database.no_timezone` or `hdx.database.with_timezone` eg.
56
68
 
57
69
  from hdx.database.no_timezone import Base
58
70
  class MyTable(Base):
@@ -70,9 +82,14 @@ tunnel (which requires installing `hdx-python-database[sshtunnel]`):
70
82
  from hdx.database import Database
71
83
  with Database(database="db", host="1.2.3.4", username="user",
72
84
  password="pass", dialect="dialect", driver="driver",
85
+
73
86
  ssh_host="5.6.7.8", ssh_port=2222, ssh_username="sshuser",
74
87
  ssh_private_key="path_to_key", db_has_tz=True,
75
- reflect=False) as session:
88
+ reflect=True, prepare_fn=prepare_views) as database:
89
+ engine = database.get_engine()
90
+ session = database.get_session()
91
+ reflected_classes = database.get_reflected_classes()
92
+ views = database.get_prepare_results()
76
93
  session.query(...)
77
94
 
78
95
  `db_has_tz` which defaults to `False` indicates whether database datetime
@@ -83,11 +100,24 @@ between Python datetimes with timezones to timezoneless database columns.
83
100
 
84
101
  If `reflect` (which defaults to `False`) is `True`, classes will be reflected
85
102
  from an existing database and the reflected classes are returned in a variable
86
- `reflected_classes` in the returned Session object. Note that type annotation
103
+ `reflected_classes` in the Database object. Note that type annotation
87
104
  maps don't work with reflection and hence `db_has_tz` will be ignored ie.
88
105
  there will be no conversion between Python datetimes with timezones to
89
106
  timezoneless database columns.
90
107
 
108
+ A PostgreSQL database can be restored from a file generated by the `pg_dump`
109
+ command line utility by supplying `pg_restore_file` with the path to the file
110
+ to be restored.
111
+
112
+ There is an option to wipe and create an empty schema in the database by
113
+ setting `recreate_schema` to `True` and setting a `schema_name` ("public" is
114
+ the default).
115
+
116
+ If a prepare function is supplied in prepare_fn, it will be executed before
117
+ Base.metadata.create_all and the results of it returned in instance variable
118
+ prepare_results.
119
+
120
+
91
121
  ## Connection URI
92
122
 
93
123
  There are functions to handle converting from connection URIs to parameters and
@@ -117,10 +147,9 @@ URI that contains both dialect and driver.
117
147
 
118
148
  ## Views
119
149
 
120
- The method to make views described [here](https://github.com/sqlalchemy/sqlalchemy/wiki/Views#sqlalchemy-14-20-version)
121
- is available in this library.
150
+ The method to prepare views described [here](https://github.com/sqlalchemy/sqlalchemy/wiki/Views#sqlalchemy-14-20-version) is available in this library.
122
151
 
123
- This allows creating views like this:
152
+ This allows preparing views like this:
124
153
  ```
125
154
  class DBOrgType(Base):
126
155
  __tablename__ = "org_type"
@@ -144,16 +173,25 @@ date_view_params = {
144
173
  "selectable": select(*DBTestDate.__table__.columns),
145
174
  }
146
175
 
147
- date_view = build_view(date_view_params)
176
+ date_view = Database.prepare_view(date_view_params)
148
177
 
149
- date_view = build_views([date_view_params])[0]
178
+ date_view = Database.prepare_views([date_view_params])[0]
150
179
  ```
151
180
 
181
+ View preparation must be done before calling Base.metadata.create_all.
182
+
152
183
  ## PostgreSQL specific
153
184
 
154
- There is a PostgreSQL specific call that only returns when the PostgreSQL database
155
- is available:
185
+ There is a PostgreSQL specific call that only returns when the PostgreSQL
186
+ database becomes available:
156
187
 
157
188
  # Wait until PostgreSQL is up
158
189
  # Library should be installed with hdx-python-database[postgresql]
159
- wait_for_postgresql("mydatabase", "myserver", 5432, "myuser", "mypass")
190
+ db_uri = "postgresql+psycopg://myuser:mypass@1.2.3.4:12345/mydatabase"
191
+ wait_for_postgresql(db_uri)
192
+
193
+ The database can be restored from a file generated by `pg_dump` like this:
194
+
195
+ db_uri = "postgresql+psycopg://myuser:mypass@1.2.3.4:12345/mydatabase"
196
+ pg_restore_file = "backup.pg_restore"
197
+ assert restore_from_pgfile(db_uri, pg_restore_file) == "WORKED!"
@@ -9,7 +9,7 @@ renderer:
9
9
  output_directory: docs
10
10
  mkdocs_config:
11
11
  site_name: HDX Python Database
12
- theme: mkdocs
12
+ theme: material
13
13
  repo_url: "https://github.com/OCHA-DAP/hdx-python-database"
14
14
  markdown:
15
15
  source_linker:
@@ -75,25 +75,21 @@ version_scheme = "python-simplified-semver"
75
75
 
76
76
  # Tests
77
77
 
78
- [tool.hatch.envs.test]
78
+ [tool.hatch.envs.hatch-test]
79
79
  features = ["sshtunnel", "postgresql", "test"]
80
80
 
81
- [tool.hatch.envs.test.scripts]
82
- test = """
81
+ [[tool.hatch.envs.hatch-test.matrix]]
82
+ python = ["3.12"]
83
+
84
+ [tool.hatch.envs.hatch-test.scripts]
85
+ run = """
83
86
  pytest -c .config/pytest.ini --rootdir=. --junitxml=test-results.xml \
84
87
  --cov --cov-config=.config/coveragerc --no-cov-on-fail \
85
- --cov-report=lcov --cov-report=term-missing
88
+ --cov-report=lcov --cov-report=term-missing -p no:randomly
86
89
  """
87
90
 
88
- [[tool.hatch.envs.test.matrix]]
89
- python = ["3.12"]
90
-
91
- [tool.hatch.envs.lint]
92
- detached = true
93
- dependencies = ["ruff"]
94
-
95
- [tool.hatch.envs.lint.scripts]
96
- style = [
97
- "ruff check --config .config/ruff.toml --diff {args:.}",
98
- "ruff format --config .config/ruff.toml --diff {args:.}",
99
- ]
91
+ [tool.hatch.envs.hatch-static-analysis.scripts]
92
+ format-check = ["ruff format --config .config/ruff.toml --check --diff {args:.}",]
93
+ format-fix = ["ruff format --config .config/ruff.toml {args:.}",]
94
+ lint-check = ["ruff check --config .config/ruff.toml {args:.}",]
95
+ lint-fix = ["ruff check --config .config/ruff.toml --fix {args:.}",]
@@ -1,69 +1,62 @@
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 --resolver=backtracking pyproject.toml
6
- #
7
- bcrypt==4.1.2
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
+ bcrypt==4.2.0
8
4
  # via paramiko
9
- cffi==1.16.0
5
+ cffi==1.17.0
10
6
  # via
11
7
  # cryptography
12
8
  # pynacl
13
9
  cfgv==3.4.0
14
10
  # via pre-commit
15
- coverage[toml]==7.4.1
11
+ coverage==7.6.1
16
12
  # via pytest-cov
17
- cryptography==42.0.2
13
+ cryptography==43.0.0
18
14
  # via paramiko
19
15
  distlib==0.3.8
20
16
  # via virtualenv
21
- filelock==3.13.1
17
+ filelock==3.15.4
22
18
  # via virtualenv
23
19
  greenlet==3.0.3
24
20
  # via sqlalchemy
25
- identify==2.5.34
21
+ identify==2.6.0
26
22
  # via pre-commit
27
23
  iniconfig==2.0.0
28
24
  # via pytest
29
- nodeenv==1.8.0
25
+ nodeenv==1.9.1
30
26
  # via pre-commit
31
- packaging==23.2
27
+ packaging==24.1
32
28
  # via pytest
33
29
  paramiko==3.4.0
34
30
  # via sshtunnel
35
- platformdirs==4.2.0
31
+ platformdirs==4.2.2
36
32
  # via virtualenv
37
- pluggy==1.4.0
33
+ pluggy==1.5.0
38
34
  # via pytest
39
- pre-commit==3.6.1
35
+ pre-commit==3.8.0
40
36
  # via hdx-python-database (pyproject.toml)
41
- psycopg[binary]==3.1.18
37
+ psycopg==3.2.1
42
38
  # via hdx-python-database (pyproject.toml)
43
- psycopg-binary==3.1.18
39
+ psycopg-binary==3.2.1
44
40
  # via psycopg
45
- pycparser==2.21
41
+ pycparser==2.22
46
42
  # via cffi
47
43
  pynacl==1.5.0
48
44
  # via paramiko
49
- pytest==8.0.0
45
+ pytest==8.3.2
50
46
  # via
51
47
  # hdx-python-database (pyproject.toml)
52
48
  # pytest-cov
53
- pytest-cov==4.1.0
49
+ pytest-cov==5.0.0
54
50
  # via hdx-python-database (pyproject.toml)
55
- pyyaml==6.0.1
51
+ pyyaml==6.0.2
56
52
  # via pre-commit
57
- sqlalchemy==2.0.27
53
+ sqlalchemy==2.0.32
58
54
  # via hdx-python-database (pyproject.toml)
59
55
  sshtunnel==0.4.0
60
56
  # via hdx-python-database (pyproject.toml)
61
- typing-extensions==4.9.0
57
+ typing-extensions==4.12.2
62
58
  # via
63
59
  # psycopg
64
60
  # sqlalchemy
65
- virtualenv==20.25.0
61
+ virtualenv==20.26.3
66
62
  # via pre-commit
67
-
68
- # The following packages are considered to be unsafe in a requirements file:
69
- # setuptools