Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
python-version: ["3.9", "3.14"]

steps:
- uses: actions/checkout@v4

Expand All @@ -38,7 +38,7 @@ jobs:
strategy:
matrix:
python-version: ["3.9", "3.14"]

steps:
- uses: actions/checkout@v4

Expand All @@ -57,7 +57,7 @@ jobs:
run: uv pip install -e ".[dev,lint,test]"

- name: Run type checking
run: uv run make ty
run: make ty

test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -104,4 +104,4 @@ jobs:
DB_TEST_USER: postgres
DB_TEST_PASSWORD: postgres
DB_TEST_HOST: localhost
DB_TEST_PORT: 5433
DB_TEST_PORT: 5433
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Changelog

## [1.0.2]

- Fix issus with sqlalchemy-utils being pinned too strictly.
- Fix tox issues.
- Remove print statements from tests.
- Fix issues with type hints.

## [1.0.0]

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "sqlalchemy-diff"
version = "1.0.1"
version = "1.0.2"
authors = [
{ name = "Fabrizio Romano", email = "gianchub@gmail.com" },
{ name = "Mark McArdle", email = "m.mc4rdle@gmail.com" },
Expand Down Expand Up @@ -32,7 +32,7 @@ maintainers = [
keywords = ["sqlalchemy", "diff", "compare"]
dependencies = [
"sqlalchemy>=1.4,<3",
"sqlalchemy-utils~=0.41.2",
"sqlalchemy-utils>=0.40.0,!=0.42.0",
]

[project.optional-dependencies]
Expand Down
6 changes: 4 additions & 2 deletions src/sqlalchemydiff/comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ def compare(
db_one_info = self._get_db_info(ignore_specs, inspector, self.db_one_engine)
db_two_info = self._get_db_info(ignore_specs, inspector, self.db_two_engine)

if None not in [db_one_info, db_two_info]:
if db_one_info is not None and db_two_info is not None:
result[key] = inspector.diff(db_one_info, db_two_info)

return self.compare_result_class(result, one_alias=one_alias, two_alias=two_alias)

def _filter_inspectors(self, ignore_inspectors: Optional[set[str]]) -> list[str]:
def _filter_inspectors(
self, ignore_inspectors: Optional[set[str]]
) -> list[tuple[str, type[BaseInspector]]]:
if not ignore_inspectors:
ignore_inspectors = set()

Expand Down
2 changes: 1 addition & 1 deletion src/sqlalchemydiff/inspection/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def diff(self, one: dict, two: dict) -> dict: ... # pragma: no cover
@abc.abstractmethod
def _is_supported(self, inspector: Inspector) -> bool: ... # pragma: no cover

def _filter_ignorers(self, specs: list[IgnoreSpecType]) -> IgnoreClauses:
def _filter_ignorers(self, specs: Optional[list[IgnoreSpecType]]) -> IgnoreClauses:
tables, enums, clauses = [], [], []

for spec in specs or []:
Expand Down
13 changes: 7 additions & 6 deletions src/sqlalchemydiff/inspection/ignore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import NamedTuple, Optional, Union


Expand Down Expand Up @@ -60,9 +60,10 @@ def create_specs(

@dataclass
class IgnoreClauses:
tables: Optional[list[str]] = None
enums: Optional[list[str]] = None
clauses: Optional[list[IgnoreSpecType]] = None
tables: list[str] = field(default_factory=list)
enums: list[str] = field(default_factory=list)
clauses: list[IgnoreSpecType] = field(default_factory=list)

def is_clause(self, table_name: str, inspector_key: str, object_name: str) -> bool:
return (table_name, inspector_key, object_name) in self.clauses
def is_clause(self, table_name: str, inspector_key: str, object_name: Optional[str]) -> bool:
clause = TableIgnoreSpec(table_name, inspector_key, object_name)
return clause in self.clauses
6 changes: 3 additions & 3 deletions src/sqlalchemydiff/inspection/inspectors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, cast

from sqlalchemy.engine import Engine

Expand Down Expand Up @@ -209,7 +209,7 @@ def _format_unique_constraint(self, inspector: Inspector, table_name: str) -> li
if not name:
name = f"unique_{table_name}_{'_'.join(constraint.get('column_names'))}"
constraint["name"] = name
return result
return cast(list[dict], result)

def _is_supported(self, inspector: Inspector) -> bool:
return hasattr(inspector, "get_unique_constraints")
Expand Down Expand Up @@ -255,7 +255,7 @@ def inspect(
inspector = self._get_inspector(engine)

ignore_clauses = self._filter_ignorers(ignore_specs)
enums = inspector.get_enums() or []
enums = getattr(inspector, "get_enums", lambda: [])() or []
return [enum for enum in enums if enum["name"] not in ignore_clauses.enums]

def diff(self, one: dict, two: dict) -> dict:
Expand Down
7 changes: 6 additions & 1 deletion src/sqlalchemydiff/inspection/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ class DiffMixin:
Provides methods used by the inspectors to diff the results.
"""

one_alias: str
two_alias: str
one_only_alias: str
two_only_alias: str

def _get_empty_result(self) -> dict:
return {
self.one_only_alias: [],
Expand Down Expand Up @@ -79,7 +84,7 @@ def _listdiff(self, one: Mapping[str, Iterable], two: Mapping[str, Iterable]) ->

return result

def _itemsdiff(self, items_in_one: Iterable[Mapping], items_in_two: Iterable[Mapping]) -> list:
def _itemsdiff(self, items_in_one: Iterable[Mapping], items_in_two: Iterable[Mapping]) -> dict:
"""Diff iterables of items in mapping format.

`items_in_one` and `items_in_two` are iterables of items in mapping format.
Expand Down
1 change: 0 additions & 1 deletion tests/test_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class TestComparerV14(BaseTest):
def test_compare(self, db_engine_one, db_engine_two, compare_result_v14, compare_errors_v14):
comparer = Comparer(db_engine_one, db_engine_two)
result = comparer.compare()
print(result.errors)
assert result.result == compare_result_v14
assert result.errors == compare_errors_v14

Expand Down
6 changes: 3 additions & 3 deletions tox.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ description = "Run unit tests with Python {basepython} and sqlalchemy V1.4"
skip_install = true
deps = [
"sqlalchemy~=1.4",
"sqlalchemy-utils~=0.41.2",
"pytest~=8.3",
"pytest-cov~=6.0",
"sqlalchemy-utils>=0.40.0,!=0.42.0",
"pytest~=8.4.2",
"pytest-cov~=7.0.0",
"psycopg2-binary",
]
allowlist_externals = ["make"]
Expand Down
Loading