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
33 changes: 33 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
- name: Install dependencies
run: uv sync --locked --no-default-groups --group ci
- name: Run pre-commit checks
run: >-
uv run --frozen --no-sync pre-commit run
--all-files --show-diff-on-failure --color=always
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@ repos:
types_or: [python, pyi, jupyter]
require_serial: true
minimum_pre_commit_version: 2.9.2

- id: ty-check
name: ty check
entry: uv run --frozen --no-sync ty check --error-on-warning
language: system
types_or: [python, pyi, jupyter]
pass_filenames: false
require_serial: true
2 changes: 1 addition & 1 deletion packages/msrtc_rans/python/src/msrtc/rans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from . import _msrtc_rans
from .types import RansVariant

__all__ = ["RansVariant", "RansEncoderStream", "RansDecoderStream", "EntropyEncoder", "EntropyDecoder"]
__all__ = ["EntropyDecoder", "EntropyEncoder", "RansDecoderStream", "RansEncoderStream", "RansVariant"]

RansEncoderStream = _msrtc_rans.RansEncoderStream
RansDecoderStream = _msrtc_rans.RansDecoderStream
Expand Down
19 changes: 5 additions & 14 deletions packages/msrtc_rans/python/src/msrtc/rans/_msrtc_rans.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

from typing import Optional, Any
from typing import Any

from .types import RansVariant

__all__ = ["RansEncoderStream", "RansDecoderStream", "EntropyEncoder", "EntropyDecoder"]
__all__ = ["EntropyDecoder", "EntropyEncoder", "RansDecoderStream", "RansEncoderStream"]

class RansEncoderStream:
"""
Expand All @@ -22,7 +22,6 @@ class RansEncoderStream:
:param initialSize: initial buffer size
:param maxSizeStep: max buffer size step
"""
pass

def flush(self) -> memoryview:
"""
Expand All @@ -31,62 +30,54 @@ class RansEncoderStream:
:return: encoded message
"""

pass

def reset(self) -> None:
"""
Resets the stream
"""
pass

class RansDecoderStream:
"""
rANS decoder stream
"""

def __init__(self, data: Optional[Any] = None, *, variant: RansVariant = RansVariant.RansByte):
def __init__(self, data: Any | None = None, *, variant: RansVariant = RansVariant.RansByte):
"""
Initialize rANS decoder stream

:param data: encoded message data
:param variant: rANS variant
"""
pass

def open(self, data) -> None:
"""
Opens the stream using data

:param data: encoded message data
"""
pass

def close(self) -> None:
"""
Closes the stream
"""
pass

def isOpen(self) -> bool:
"""
Checks whether stream is open

:return: open status
"""
pass

def decodeEOF(self) -> None:
"""
Check that decoding reached end of message and closes stream on success
"""
pass

EntropyEncoder = Any
type EntropyEncoder = Any
"""
Entropy encoder implmentation
"""

EntropyDecoder = Any
type EntropyDecoder = Any
"""
Entropy decoder implmentation
"""
12 changes: 5 additions & 7 deletions packages/msrtc_rans/python/test/test_msrtc_rans.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

import os.path
import zipfile
from typing import Optional

import numpy as np

from msrtc.rans import RansVariant, RansEncoderStream, RansDecoderStream, EntropyEncoder, EntropyDecoder
from msrtc.rans import EntropyDecoder, EntropyEncoder, RansDecoderStream, RansEncoderStream, RansVariant


def test_encode_decode_byte_0():
Expand Down Expand Up @@ -155,9 +153,9 @@ def read_ndarray(self, name, dtype=np.int32):
def run_encode_decode_on_zip_test_bundle(
bundle_name: str,
*,
variant: Optional[RansVariant] = None,
symbolBits: Optional[int] = None,
bypassBits: Optional[int] = None,
variant: RansVariant | None = None,
symbolBits: int | None = None,
bypassBits: int | None = None,
):
with ZipTestBundle(bundle_name) as bundle:
pmfLengths = bundle.read_ndarray("pmf_lengths.np")
Expand All @@ -168,7 +166,7 @@ def run_encode_decode_on_zip_test_bundle(

bitstream = bundle.read_bytes("bitstream.bin")

coderArgs = dict()
coderArgs = {}
if variant is not None:
coderArgs["variant"] = variant
if symbolBits is not None:
Expand Down
83 changes: 73 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ onnxruntime-windowsml = [
[dependency-groups]
ci = [
"pytest",
"pyright",
"ruff==0.15.21",
"ty",
"ruff",
"pre-commit",
"pre-commit-hooks",
"python-dotenv",
Expand Down Expand Up @@ -104,9 +104,36 @@ name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[tool.pyright]
[tool.ruff]
line-length = 120
extend-exclude = ["video/src/vsr", "video/src/metrics/deqa"]

[tool.ruff.lint]
ignore = [
"LOG015", # Root logger is the project convention (the log format has no logger name)
"TRY004", # Invalid config types raise ValueError by design (tests rely on it)
"BLE001", # Broad excepts are deliberate: per-item error handling, cross-thread exception forwarding
]

[tool.ruff.lint.flake8-bugbear]
extend-immutable-calls = ["conversion.types.RuntimeParams", "src.utils.rate_controller.RateModelParams"]

[tool.ruff.lint.isort]
known-first-party = [
"src",
"conversion",
"tests",
"compare_rd_video",
"compute_benchmark_metrics",
"process_P910_results",
"run_basicvsrpp",
"test_conversion",
"train_video",
]
combine-as-imports = true

[tool.ty.src]
include = ["video"]
extraPaths = ["packages/msrtc_rans/python/src"]
exclude = [
"**/node_modules",
"**/__pycache__",
Expand All @@ -119,10 +146,46 @@ exclude = [
"video/src/utils/flow_tester.py",
"packages/msrtc_rans/python/src",
]
ignore = ["packages/msrtc_rans/python/src"]
pythonVersion = "3.12"
typeCheckingMode = "basic"

[tool.ruff]
line-length = 120
extend-exclude = ["video/src/vsr", "video/src/metrics/deqa"]
[tool.ty.environment]
python-platform = "all"
root = ["video"]
extra-paths = ["packages/msrtc_rans/python/src"]

[tool.ty.analysis]
replace-imports-with-any = ["onnxruntime", "onnxruntime.**", "openvino", "openvino.**", "winui3", "winui3.**"]
allowed-unresolved-imports = ["cv2.**", "facer.**", "lpips.**", "skimage.**", "torchvision.**"]

[tool.ty.rules]
incompatible-method-override = "ignore"
incompatible-attribute-override = "ignore"
lost-keyword-for-regular-parameter = "ignore"

[[tool.ty.overrides]]
include = [
"video/conversion/__init__.py",
"video/conversion/_exporter/__init__.py",
"video/conversion/_exporter/_base_exporter.py",
"video/conversion/_scale_decoder.py",
"video/src/utils/common.py",
"video/src/utils/model_factory.py",
"video/train_optic_flow.py",
]

[tool.ty.overrides.analysis]
allowed-unresolved-imports = [
"conversion._exporter._coreml_ext",
"conversion._scale_decoder_ext",
"conversion._types_ext",
"src.models.legacy.video_net",
"src.utils.model_factory_ext",
"src.vsr.auto_avsr.api",
]

[[tool.ty.overrides]]
include = ["video/conversion/_exporter/_coreml_utils.py", "video/notebooks/coreml_act_precision.ipynb"]
rules = { missing-attribute = "ignore" }

[[tool.ty.overrides]]
include = ["video/conversion/_split_model/**"]
rules = { mismatched-type-name = "ignore" }
Loading
Loading