Skip to content
Draft
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
16 changes: 12 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ jobs:

steps:
- uses: actions/checkout@v6
- name: Set up Python 3.9
uses: actions/setup-python@v5

- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.9"
- uses: pre-commit/[email protected]
version: 0.9.13
python-version: "3.11"
activate-environment: "true"

- name: Install dependencies from uv.lock
run: uv sync --locked

- name: Run pre-commit
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )

tests:
runs-on: ${{ matrix.os }}
Expand Down
19 changes: 12 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ci:
autoupdate_schedule: monthly
autoupdate_schedule: quarterly
autofix_prs: true
skip: [mypy]

exclude: &exclude_files >
(?x)^(
Expand Down Expand Up @@ -52,10 +53,14 @@ repos:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
- repo: local
hooks:
- id: mypy
additional_dependencies:
- "sqlalchemy[mypy]==1.4.29"
files: ^(disk_objectstore/.*py)$
- id: mypy
name: mypy
entry: mypy
args: [--config-file=pyproject.toml, --pretty, disk_objectstore/]
language: python
types: [python]
require_serial: true
pass_filenames: false
files: ^(disk_objectstore/.*py)$
13 changes: 9 additions & 4 deletions disk_objectstore/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,10 @@ def count_objects(self) -> ObjectCount:
In particular, it returns the number of loose objects,
of packed objects, and the number of pack files."""

# TODO: Remove type: ignore! Do we need to handle number_packed==None?
number_packed = self._get_operation_session().scalar(select(func.count()).select_from(Obj))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy thinks number_packed can be None. I am not sure if it is correct or not.

return ObjectCount(
packed=number_packed,
packed=number_packed, # type: ignore[arg-type]
loose=sum(1 for _ in self._list_loose()),
pack_files=sum(1 for _ in self._list_packs()),
)
Expand Down Expand Up @@ -1095,7 +1096,8 @@ def get_total_size(self) -> TotalSize:
total_size_loose += loose_path.stat().st_size
retval['total_size_loose'] = total_size_loose

return TotalSize(**retval)
# TODO: Handle None?
return TotalSize(**retval) # type: ignore[arg-type]

@contextmanager
def lock_pack(self, pack_id: str, allow_repack_pack: bool = False) -> Iterator[StreamWriteBytesType]:
Expand Down Expand Up @@ -2359,7 +2361,8 @@ def callback(self, action, value):
value={'total': total, 'description': f'Pack {pack_id}'},
)
# Update at most 400 times, avoiding to increase CPU usage; if the list is small: every object.
update_every = max(int(total / 400), 1)
# TODO: Handle total==None?
update_every = max(int(total / 400), 1) # type: ignore[operator]
# Counter of how many objects have been since since the last update.
# A new callback will be performed when this value is > update_every.
since_last_update = 0
Expand Down Expand Up @@ -2727,7 +2730,9 @@ def repack_pack( # pylint: disable=too-many-branches,too-many-statements,too-ma
# At this stage we just have a new pack -1 (_REPACK_PACK_ID) but it is never referenced.
# Let us store the information in the DB.
# We had already checked earlier that this at least one exists.
session.bulk_update_mappings(Obj, obj_dicts)
# TODO: error: Argument 1 to "bulk_update_mappings"
# of "Session" has incompatible type "type[Obj]"; expected "Mapper[Any]"
session.bulk_update_mappings(Obj, obj_dicts) # type: ignore[arg-type]
# I also commit.
session.commit()
# Clean up the cache
Expand Down
2 changes: 1 addition & 1 deletion disk_objectstore/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def do_begin(conn): # pylint: disable=unused-variable

# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine
Base.metadata.bind = engine # type: ignore[attr-defined]

# We set autoflush = False to avoid to lock the DB if just doing queries/reads
session = sessionmaker(bind=engine, autoflush=False, autocommit=False, future=True)()
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ dev = [
'pytest~=8.4',
'pytest-benchmark~=5.2',
'pytest-cov~=7.0',
'mypy~=1.19.0',
"sqlalchemy[mypy]>=1.4.22",
'types-psutil',
'types-tqdm',
]
docs = [
'jinja2<3.1',
Expand Down Expand Up @@ -144,6 +148,13 @@ scripts_are_modules = true
warn_redundant_casts = true
plugins = ['sqlalchemy.ext.mypy.plugin']

[[tool.mypy.overrides]]
ignore_missing_imports = true
module = [
'profilehooks.*',
'memory_profiler.*',
]

[tool.tox]
legacy_tox_ini = """
[tox]
Expand Down
Loading