hdx-python-database 1.3.3__tar.gz → 1.3.5__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_database-1.3.3 → hdx_python_database-1.3.5}/.config/pre-commit-config.yaml +3 -3
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/PKG-INFO +2 -2
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/pyproject.toml +4 -1
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/requirements.txt +18 -18
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/src/hdx/database/__init__.py +3 -1
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/src/hdx/database/_version.py +2 -2
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/src/hdx/database/postgresql.py +1 -1
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/src/hdx/database/views.py +8 -17
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/test_database.py +9 -14
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/test_reflect.py +10 -17
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/.config/coveragerc +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/.config/pytest.ini +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/.config/ruff.toml +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/.github/workflows/publish.yaml +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/.github/workflows/run-python-tests.yaml +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/.gitignore +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/CONTRIBUTING.md +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/LICENSE +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/README.md +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/documentation/.readthedocs.yaml +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/documentation/main.md +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/documentation/pydoc-markdown.yaml +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/src/hdx/database/dburi.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/src/hdx/database/no_timezone.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/src/hdx/database/utils.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/src/hdx/database/with_timezone.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/fixtures/test.db +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/__init__.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/conftest.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/dbtestdate.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/test_dburi.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/test_postgresql.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/test_recreate.py +0 -0
- {hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/test_ssh.py +0 -0
|
@@ -2,13 +2,13 @@ default_language_version:
|
|
|
2
2
|
python: python3.12
|
|
3
3
|
repos:
|
|
4
4
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
5
|
-
rev:
|
|
5
|
+
rev: v5.0.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.
|
|
11
|
+
rev: v0.9.6
|
|
12
12
|
hooks:
|
|
13
13
|
# Run the linter.
|
|
14
14
|
- id: ruff
|
|
@@ -17,7 +17,7 @@ repos:
|
|
|
17
17
|
- id: ruff-format
|
|
18
18
|
args: [--config, .config/ruff.toml]
|
|
19
19
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
20
|
-
rev: 0.
|
|
20
|
+
rev: 0.5.29
|
|
21
21
|
hooks:
|
|
22
22
|
# Run the pip compile
|
|
23
23
|
- id: pip-compile
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: hdx-python-database
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.5
|
|
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>
|
|
@@ -85,9 +85,12 @@ python = ["3.12"]
|
|
|
85
85
|
run = """
|
|
86
86
|
pytest -c .config/pytest.ini --rootdir=. --junitxml=test-results.xml \
|
|
87
87
|
--cov --cov-config=.config/coveragerc --no-cov-on-fail \
|
|
88
|
-
--cov-report=lcov --cov-report=term-missing
|
|
88
|
+
--cov-report=lcov --cov-report=term-missing
|
|
89
89
|
"""
|
|
90
90
|
|
|
91
|
+
[tool.hatch.envs.hatch-static-analysis]
|
|
92
|
+
dependencies = ["ruff==0.9.6"]
|
|
93
|
+
|
|
91
94
|
[tool.hatch.envs.hatch-static-analysis.scripts]
|
|
92
95
|
format-check = ["ruff format --config .config/ruff.toml --check --diff {args:.}",]
|
|
93
96
|
format-fix = ["ruff format --config .config/ruff.toml {args:.}",]
|
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
# This file was autogenerated by uv via the following command:
|
|
2
2
|
# uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
|
|
3
|
-
bcrypt==4.2.
|
|
3
|
+
bcrypt==4.2.1
|
|
4
4
|
# via paramiko
|
|
5
|
-
cffi==1.17.
|
|
5
|
+
cffi==1.17.1
|
|
6
6
|
# via
|
|
7
7
|
# cryptography
|
|
8
8
|
# pynacl
|
|
9
9
|
cfgv==3.4.0
|
|
10
10
|
# via pre-commit
|
|
11
|
-
coverage==7.6.
|
|
11
|
+
coverage==7.6.11
|
|
12
12
|
# via pytest-cov
|
|
13
|
-
cryptography==
|
|
13
|
+
cryptography==44.0.0
|
|
14
14
|
# via paramiko
|
|
15
|
-
distlib==0.3.
|
|
15
|
+
distlib==0.3.9
|
|
16
16
|
# via virtualenv
|
|
17
|
-
filelock==3.
|
|
17
|
+
filelock==3.17.0
|
|
18
18
|
# via virtualenv
|
|
19
|
-
greenlet==3.
|
|
19
|
+
greenlet==3.1.1
|
|
20
20
|
# via sqlalchemy
|
|
21
|
-
identify==2.6.
|
|
21
|
+
identify==2.6.7
|
|
22
22
|
# via pre-commit
|
|
23
23
|
iniconfig==2.0.0
|
|
24
24
|
# via pytest
|
|
25
25
|
nodeenv==1.9.1
|
|
26
26
|
# via pre-commit
|
|
27
|
-
packaging==24.
|
|
27
|
+
packaging==24.2
|
|
28
28
|
# via pytest
|
|
29
|
-
paramiko==3.
|
|
29
|
+
paramiko==3.5.1
|
|
30
30
|
# via sshtunnel
|
|
31
|
-
platformdirs==4.
|
|
31
|
+
platformdirs==4.3.6
|
|
32
32
|
# via virtualenv
|
|
33
33
|
pluggy==1.5.0
|
|
34
34
|
# via pytest
|
|
35
|
-
pre-commit==
|
|
35
|
+
pre-commit==4.1.0
|
|
36
36
|
# via hdx-python-database (pyproject.toml)
|
|
37
|
-
psycopg==3.2.
|
|
37
|
+
psycopg==3.2.4
|
|
38
38
|
# via hdx-python-database (pyproject.toml)
|
|
39
|
-
psycopg-binary==3.2.
|
|
39
|
+
psycopg-binary==3.2.4
|
|
40
40
|
# via psycopg
|
|
41
41
|
pycparser==2.22
|
|
42
42
|
# via cffi
|
|
43
43
|
pynacl==1.5.0
|
|
44
44
|
# via paramiko
|
|
45
|
-
pytest==8.3.
|
|
45
|
+
pytest==8.3.4
|
|
46
46
|
# via
|
|
47
47
|
# hdx-python-database (pyproject.toml)
|
|
48
48
|
# pytest-cov
|
|
49
|
-
pytest-cov==
|
|
49
|
+
pytest-cov==6.0.0
|
|
50
50
|
# via hdx-python-database (pyproject.toml)
|
|
51
51
|
pyyaml==6.0.2
|
|
52
52
|
# via pre-commit
|
|
53
|
-
sqlalchemy==2.0.
|
|
53
|
+
sqlalchemy==2.0.38
|
|
54
54
|
# via hdx-python-database (pyproject.toml)
|
|
55
55
|
sshtunnel==0.4.0
|
|
56
56
|
# via hdx-python-database (pyproject.toml)
|
|
@@ -58,5 +58,5 @@ typing-extensions==4.12.2
|
|
|
58
58
|
# via
|
|
59
59
|
# psycopg
|
|
60
60
|
# sqlalchemy
|
|
61
|
-
virtualenv==20.
|
|
61
|
+
virtualenv==20.29.1
|
|
62
62
|
# via pre-commit
|
|
@@ -258,7 +258,9 @@ class Database:
|
|
|
258
258
|
engine = create_engine(db_uri, poolclass=NullPool, echo=False)
|
|
259
259
|
if reflect:
|
|
260
260
|
Base = automap_base(declarative_base=table_base)
|
|
261
|
-
Base.prepare(
|
|
261
|
+
Base.prepare(
|
|
262
|
+
autoload_with=engine, reflection_options={"views": True}
|
|
263
|
+
)
|
|
262
264
|
table_base = Base
|
|
263
265
|
else:
|
|
264
266
|
table_base.metadata.create_all(engine)
|
|
@@ -87,7 +87,7 @@ def restore_from_pgfile(db_uri: str, pg_restore_file: str) -> str:
|
|
|
87
87
|
except subprocess.CalledProcessError as ex:
|
|
88
88
|
command = " ".join(subprocess_params)
|
|
89
89
|
raise PostgresError(
|
|
90
|
-
f"{command} failed. Return code: {process.returncode}"
|
|
90
|
+
f"{command} failed. Return code: {process.returncode}. Error: {process.stderr}"
|
|
91
91
|
) from ex
|
|
92
92
|
|
|
93
93
|
for line in process.stdout.splitlines():
|
|
@@ -7,10 +7,8 @@ https://github.com/sqlalchemy/sqlalchemy/wiki/Views#sqlalchemy-14-20-version
|
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
import sqlalchemy as sa
|
|
10
|
-
from sqlalchemy import MetaData, Selectable, TableClause
|
|
11
10
|
from sqlalchemy.ext import compiler
|
|
12
11
|
from sqlalchemy.schema import DDLElement
|
|
13
|
-
from sqlalchemy.sql import table
|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
class CreateView(DDLElement):
|
|
@@ -45,22 +43,15 @@ def view_doesnt_exist(ddl, target, connection, **kw):
|
|
|
45
43
|
return not view_exists(ddl, target, connection, **kw)
|
|
46
44
|
|
|
47
45
|
|
|
48
|
-
def view(name
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Returns:
|
|
57
|
-
TableClause: SQLAlchemy View
|
|
58
|
-
"""
|
|
59
|
-
t = table(name)
|
|
60
|
-
|
|
61
|
-
t._columns._populate_separate_keys(
|
|
62
|
-
col._make_proxy(t) for col in selectable.selected_columns
|
|
46
|
+
def view(name, metadata, selectable):
|
|
47
|
+
t = sa.table(
|
|
48
|
+
name,
|
|
49
|
+
*(
|
|
50
|
+
sa.Column(c.name, c.type, primary_key=c.primary_key)
|
|
51
|
+
for c in selectable.selected_columns
|
|
52
|
+
),
|
|
63
53
|
)
|
|
54
|
+
t.primary_key.update(c for c in t.c if c.primary_key)
|
|
64
55
|
|
|
65
56
|
sa.event.listen(
|
|
66
57
|
metadata,
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from datetime import datetime, timezone
|
|
4
4
|
from os import remove
|
|
5
|
-
from os.path import join
|
|
5
|
+
from os.path import exists, join
|
|
6
|
+
from tempfile import gettempdir
|
|
6
7
|
|
|
7
8
|
import pytest
|
|
8
9
|
from sqlalchemy import select
|
|
@@ -13,30 +14,23 @@ from hdx.database.no_timezone import Base as NoTZBase
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class TestDatabase:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@pytest.fixture(scope="function")
|
|
19
|
-
def nodatabase(self):
|
|
20
|
-
try:
|
|
21
|
-
remove(TestDatabase.dbpath)
|
|
22
|
-
except OSError:
|
|
23
|
-
pass
|
|
24
|
-
return f"sqlite:///{TestDatabase.dbpath}"
|
|
25
|
-
|
|
26
|
-
def test_get_session(self, nodatabase):
|
|
17
|
+
def test_get_session(self):
|
|
27
18
|
assert DBTestDate.__tablename__ == "db_test_date"
|
|
28
19
|
|
|
29
20
|
def prepare_fn():
|
|
30
21
|
return Database.prepare_views([date_view_params])
|
|
31
22
|
|
|
23
|
+
dbpath = join(gettempdir(), "test_database.db")
|
|
24
|
+
if exists(dbpath):
|
|
25
|
+
remove(dbpath)
|
|
32
26
|
with Database(
|
|
33
|
-
database=
|
|
27
|
+
database=dbpath,
|
|
34
28
|
port=None,
|
|
35
29
|
dialect="sqlite",
|
|
36
30
|
prepare_fn=prepare_fn,
|
|
37
31
|
) as dbdatabase:
|
|
38
32
|
dbsession = dbdatabase.get_session()
|
|
39
|
-
assert str(dbsession.bind.engine.url) ==
|
|
33
|
+
assert str(dbsession.bind.engine.url) == f"sqlite:///{dbpath}"
|
|
40
34
|
assert dbdatabase.base == NoTZBase
|
|
41
35
|
now = datetime(2022, 10, 20, 22, 35, 55, tzinfo=timezone.utc)
|
|
42
36
|
input_dbtestdate = DBTestDate()
|
|
@@ -48,6 +42,7 @@ class TestDatabase:
|
|
|
48
42
|
date_view = dbdatabase.get_prepare_results()[0]
|
|
49
43
|
dbtestdate = dbsession.execute(select(date_view)).scalar_one()
|
|
50
44
|
assert dbtestdate == now
|
|
45
|
+
remove(dbpath)
|
|
51
46
|
|
|
52
47
|
def test_errors(self):
|
|
53
48
|
with pytest.raises(DatabaseError):
|
|
@@ -4,8 +4,8 @@ from datetime import datetime
|
|
|
4
4
|
from os import remove
|
|
5
5
|
from os.path import join
|
|
6
6
|
from shutil import copyfile
|
|
7
|
+
from tempfile import gettempdir
|
|
7
8
|
|
|
8
|
-
import pytest
|
|
9
9
|
from sqlalchemy import select
|
|
10
10
|
from sqlalchemy.orm.decl_api import DeclarativeAttributeIntercept
|
|
11
11
|
|
|
@@ -13,30 +13,22 @@ from hdx.database import Database
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class TestReflect:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def database_to_reflect(self):
|
|
21
|
-
try:
|
|
22
|
-
remove(TestReflect.dbpath)
|
|
23
|
-
copyfile(TestReflect.testdb, TestReflect.dbpath)
|
|
24
|
-
except OSError:
|
|
25
|
-
pass
|
|
26
|
-
return f"sqlite:///{TestReflect.dbpath}"
|
|
27
|
-
|
|
28
|
-
def test_get_reflect_session(self, database_to_reflect):
|
|
16
|
+
def test_get_reflect_session(self):
|
|
17
|
+
dbpath = join(gettempdir(), "test_reflect.db")
|
|
18
|
+
testdb = join("tests", "fixtures", "test.db")
|
|
19
|
+
copyfile(testdb, dbpath)
|
|
29
20
|
with Database(
|
|
30
|
-
database=
|
|
21
|
+
database=dbpath,
|
|
31
22
|
port=None,
|
|
32
23
|
dialect="sqlite",
|
|
33
24
|
reflect=True,
|
|
34
25
|
) as dbdatabase:
|
|
35
26
|
dbengine = dbdatabase.get_engine()
|
|
36
|
-
|
|
27
|
+
dburi = f"sqlite:///{dbpath}"
|
|
28
|
+
assert str(dbengine.url) == dburi
|
|
37
29
|
dbsession = dbdatabase.get_session()
|
|
38
30
|
assert isinstance(dbdatabase.base, DeclarativeAttributeIntercept)
|
|
39
|
-
assert str(dbsession.bind.engine.url) ==
|
|
31
|
+
assert str(dbsession.bind.engine.url) == dburi
|
|
40
32
|
Table1 = dbdatabase.get_reflected_classes().table1
|
|
41
33
|
row = dbsession.execute(select(Table1)).scalar_one()
|
|
42
34
|
assert row.id == "1"
|
|
@@ -44,3 +36,4 @@ class TestReflect:
|
|
|
44
36
|
# with reflection, type annotation maps do not work and hence
|
|
45
37
|
# we don't have a timezone here
|
|
46
38
|
assert row.date1 == datetime(1993, 9, 23, 14, 12, 56, 111000)
|
|
39
|
+
remove(dbpath)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/.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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hdx_python_database-1.3.3 → hdx_python_database-1.3.5}/tests/hdx/database/test_postgresql.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|