Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump black from 23.3.0 to 24.10.0 in /lib/python #1788

Merged
merged 5 commits into from
Jan 29, 2025
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
2 changes: 1 addition & 1 deletion backend/docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ help:
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
cp -R $(BUILDDIR) $(BACKENDDIR)
cp -R $(BUILDDIR) $(BACKENDDIR)
2 changes: 1 addition & 1 deletion backend/docs/bailo.core.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bailo.core package
==================

*The Bailo core package contains suppport with one to one endpoints with Bailo. It is recommended to use the helper package for most use*
*The Bailo core package contains support with one to one endpoints with Bailo. It is recommended to use the helper package for most use*


.. automodule:: bailo.core.agent
Expand Down
2 changes: 1 addition & 1 deletion backend/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Welcome to Bailo's Python Client documentation!
:caption: Notebooks:
:glob:

notebooks/*
notebooks/*
2 changes: 2 additions & 0 deletions backend/docs/notebooks/set_schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

json_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion backend/docs/pylint.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ confidence=

# file where it should appear only once). You can also use "--disable=all" to

# disable everything first and then reenable specific checks. For example, if
# disable everything first and then re-enable specific checks. For example, if

# you want to run only the similarities checker, you can use "--disable=all

Expand Down
9 changes: 5 additions & 4 deletions lib/modelscan_api/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
rev: 6.0.0
hooks:
- id: isort
args: ['-a', 'from __future__ import annotations']
args: ['-a', 'from __future__ import annotations', '-l', '120']

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py37-plus]
args: ['--py39-plus', '--keep-runtime-typing']

- repo: https://github.com/hadialqattan/pycln
rev: v2.5.0
hooks:
- id: pycln
args: [--config=pyproject.toml]
# use the same config as for /lib/python
args: [--config=../python/pyproject.toml]
stages: [manual]

- repo: https://github.com/codespell-project/codespell
Expand Down
45 changes: 38 additions & 7 deletions lib/modelscan_api/bailo_modelscan_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from modelscan.modelscan import ModelScan
from pydantic import BaseModel

# isort: split

from bailo_modelscan_api.config import Settings
from bailo_modelscan_api.dependencies import safe_join

Expand Down Expand Up @@ -91,13 +93,21 @@ async def info(settings: Annotated[Settings, Depends(get_settings)]) -> ApiInfor
"Normal": {
"value": {
"summary": {
"total_issues_by_severity": {"LOW": 0, "MEDIUM": 0, "HIGH": 0, "CRITICAL": 0},
"total_issues_by_severity": {
"LOW": 0,
"MEDIUM": 0,
"HIGH": 0,
"CRITICAL": 0,
},
"total_issues": 0,
"input_path": "/foo/bar/safe_model.pkl",
"absolute_path": "/foo/bar",
"modelscan_version": "0.8.1",
"timestamp": "2024-11-19T12:00:00.000000",
"scanned": {"total_scanned": 1, "scanned_files": ["safe_model.pkl"]},
"scanned": {
"total_scanned": 1,
"scanned_files": ["safe_model.pkl"],
},
"skipped": {
"total_skipped": 0,
"skipped_files": [],
Expand All @@ -110,14 +120,25 @@ async def info(settings: Annotated[Settings, Depends(get_settings)]) -> ApiInfor
"Issue": {
"value": {
"summary": {
"total_issues_by_severity": {"LOW": 0, "MEDIUM": 1, "HIGH": 0, "CRITICAL": 0},
"total_issues_by_severity": {
"LOW": 0,
"MEDIUM": 1,
"HIGH": 0,
"CRITICAL": 0,
},
"total_issues": 1,
"input_path": "/foo/bar/unsafe_model.h5",
"absolute_path": "/foo/bar",
"modelscan_version": "0.8.1",
"timestamp": "2024-11-19T12:00:00.000000",
"scanned": {"total_scanned": 1, "scanned_files": ["unsafe_model.h5"]},
"skipped": {"total_skipped": 0, "skipped_files": []},
"scanned": {
"total_scanned": 1,
"scanned_files": ["unsafe_model.h5"],
},
"skipped": {
"total_skipped": 0,
"skipped_files": [],
},
},
"issues": [
{
Expand Down Expand Up @@ -153,14 +174,24 @@ async def info(settings: Annotated[Settings, Depends(get_settings)]) -> ApiInfor
},
"timestamp": "2024-11-19T12:00:00.000000",
"total_issues": 0,
"total_issues_by_severity": {"CRITICAL": 0, "HIGH": 0, "LOW": 0, "MEDIUM": 0},
"total_issues_by_severity": {
"CRITICAL": 0,
"HIGH": 0,
"LOW": 0,
"MEDIUM": 0,
},
},
}
},
"Error": {
"value": {
"summary": {
"total_issues_by_severity": {"LOW": 0, "MEDIUM": 0, "HIGH": 0, "CRITICAL": 0},
"total_issues_by_severity": {
"LOW": 0,
"MEDIUM": 0,
"HIGH": 0,
"CRITICAL": 0,
},
"total_issues": 0,
"input_path": "/foo/bar/null.h5",
"absolute_path": "/foo/bar",
Expand Down
1 change: 1 addition & 0 deletions lib/modelscan_api/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r requirements.txt
black==24.10.0
pre_commit==4.1.0
pytest==8.3.4
12 changes: 9 additions & 3 deletions lib/modelscan_api/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
from __future__ import annotations

import itertools
from collections.abc import Iterable
from pathlib import Path
from typing import Any, Iterable
from typing import Any

import pytest

# isort: split

from bailo_modelscan_api.dependencies import parse_path, safe_join, sanitise_unix_filename

# Helpers
Expand Down Expand Up @@ -45,8 +48,11 @@ def type_matrix(data: Iterable[Any], types: Iterable[type]) -> itertools.product
("\n", "-"),
("\r", "-"),
("~", "~"),
("".join(['\\[/\\?%*:|"<>0x7F0x00-0x1F]', chr(0x1F) * 15]), "-[----------0x7F0x00-0x1F]---------------"),
("ad\nbla'{-+\\)(ç?", "ad-bla'{-+-)(ç-"), # type: ignore
(
"".join(['\\[/\\?%*:|"<>0x7F0x00-0x1F]', chr(0x1F) * 15]),
"-[----------0x7F0x00-0x1F]---------------",
),
("ad\nbla'{-+\\)(ç?", "ad-bla'{-+-)(ç-"),
],
)
def test_sanitise_unix_filename(path: str, output: str) -> None:
Expand Down
37 changes: 32 additions & 5 deletions lib/modelscan_api/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import pytest
from fastapi.testclient import TestClient

# isort: split

from bailo_modelscan_api.config import Settings
from bailo_modelscan_api.main import app, get_settings

Expand Down Expand Up @@ -57,7 +59,12 @@ def get_settings_override():
},
"timestamp": ANY,
"total_issues": 0,
"total_issues_by_severity": {"CRITICAL": 0, "HIGH": 0, "LOW": 0, "MEDIUM": 0},
"total_issues_by_severity": {
"CRITICAL": 0,
"HIGH": 0,
"LOW": 0,
"MEDIUM": 0,
},
},
},
),
Expand All @@ -67,7 +74,12 @@ def get_settings_override():
H5_MIME_TYPE,
{
"summary": {
"total_issues_by_severity": {"LOW": 0, "MEDIUM": 0, "HIGH": 0, "CRITICAL": 0},
"total_issues_by_severity": {
"LOW": 0,
"MEDIUM": 0,
"HIGH": 0,
"CRITICAL": 0,
},
"total_issues": 0,
"input_path": str(Path().cwd().absolute().joinpath("null.h5")),
"absolute_path": str(Path().cwd().absolute()),
Expand Down Expand Up @@ -101,7 +113,12 @@ def get_settings_override():
OCTET_STREAM_TYPE,
{
"summary": {
"total_issues_by_severity": {"LOW": 0, "MEDIUM": 0, "HIGH": 0, "CRITICAL": 0},
"total_issues_by_severity": {
"LOW": 0,
"MEDIUM": 0,
"HIGH": 0,
"CRITICAL": 0,
},
"total_issues": 0,
"input_path": str(Path().cwd().absolute().joinpath("safe.pkl")),
"absolute_path": str(Path().cwd().absolute()),
Expand All @@ -123,7 +140,12 @@ def get_settings_override():
OCTET_STREAM_TYPE,
{
"summary": {
"total_issues_by_severity": {"LOW": 0, "MEDIUM": 0, "HIGH": 0, "CRITICAL": 1},
"total_issues_by_severity": {
"LOW": 0,
"MEDIUM": 0,
"HIGH": 0,
"CRITICAL": 1,
},
"total_issues": 1,
"input_path": str(Path().cwd().absolute().joinpath("unsafe.pkl")),
"absolute_path": str(Path().cwd().absolute()),
Expand All @@ -150,7 +172,12 @@ def get_settings_override():
),
],
)
def test_scan_file(file_name: str, file_content: Path | bytes, file_mime_type: str, expected_response: dict) -> None:
def test_scan_file(
file_name: str,
file_content: Path | bytes,
file_mime_type: str,
expected_response: dict,
) -> None:
# allow passing in a Path to read the file's contents for specific data types
if isinstance(file_content, Path):
with open(file_content, "rb") as f:
Expand Down
16 changes: 8 additions & 8 deletions lib/modelscan_api/tests/test_integration/generate_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ def __init__(self, file, protocol, inj_objs):

def dump(self, obj):
"Pickle data, inject object before or after"
if self.proto >= 2: # type: ignore
self.write(pickle.PROTO + struct.pack("<B", self.proto)) # type: ignore
if self.proto >= 4: # type: ignore
self.framer.start_framing() # type: ignore
if self.proto >= 2:
self.write(pickle.PROTO + struct.pack("<B", self.proto))
if self.proto >= 4:
self.framer.start_framing()
for inj_obj in self.inj_objs:
self.save(inj_obj) # type: ignore
self.save(obj) # type: ignore
self.write(pickle.STOP) # type: ignore
self.framer.end_framing() # type: ignore
self.save(inj_obj)
self.save(obj)
self.write(pickle.STOP)
self.framer.end_framing()


class _PickleInject:
Expand Down
7 changes: 6 additions & 1 deletion lib/modelscan_api/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import pytest
from fastapi.testclient import TestClient

# isort: split

from bailo_modelscan_api.config import Settings
from bailo_modelscan_api.dependencies import parse_path
from bailo_modelscan_api.main import app, get_settings
Expand Down Expand Up @@ -91,7 +93,10 @@ def test_scan_file_exception(mock_scan: Mock, file_name: str, file_content: Any,
mock_scan.assert_called_once()

# Manually cleanup as FastAPI won't trigger background_tasks on Exception due to using TestClient.
Path.unlink(Path.joinpath(parse_path(get_settings().download_dir), "foo.h5"), missing_ok=True)
Path.unlink(
Path.joinpath(parse_path(get_settings().download_dir), "foo.h5"),
missing_ok=True,
)


@pytest.mark.parametrize(
Expand Down
18 changes: 10 additions & 8 deletions lib/python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ ci:
autoupdate_commit_msg: 'chore: update pre-commit hooks'
autofix_commit_msg: 'style: pre-commit fixes'

files: ^(backend/docs/|lib/python/)

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -18,26 +20,26 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 6.0.0
hooks:
- id: isort
args: ['-a', 'from __future__ import annotations']
args: ['-a', 'from __future__ import annotations', '-l', '120']

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py37-plus]
args: [--py39-plus]

- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
rev: v2.5.0
hooks:
- id: pycln
args: [--config=pyproject.toml]
stages: [manual]

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.4.0
hooks:
- id: codespell

Expand All @@ -54,7 +56,7 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
rev: 24.10.0
hooks:
- id: black
args: [--line-length=120]
6 changes: 3 additions & 3 deletions lib/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies = [

[project.optional-dependencies]
test = [
"black==23.3.0",
"black==24.10.0",
"check-manifest==0.49",
"mlflow>2.11.0",
"pre-commit==4.1.0",
Expand Down Expand Up @@ -64,12 +64,12 @@ exclude = [
"**/node_modules",
"**/__pycache__",
]
venv = "env37"
venv = "env39"

reportMissingImports = true
reportMissingTypeStubs = false

pythonVersion = "3.7"
pythonVersion = "3.9"
pythonPlatform = "Linux"

executionEnvironments = [
Expand Down
Loading
Loading