Skip to content

Commit

Permalink
Add auto linting and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
laggykiller committed Mar 9, 2024
1 parent e7c9b75 commit 32276e0
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 13 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/check_and_fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Check and formatting

on:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
check_and_fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
submodules: recursive
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install dependency
run: pip install ruff pyright isort pytest
- name: Ruff check
run: ruff check
- name: Install test
run: pip install .
- name: pyright
run: pyright
- name: isort
run: isort .
- name: ruff format
run: ruff format
- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: Formatting
branch: ${{ steps.extract_branch.outputs.branch }}
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys

sys.path.insert(0, os.path.abspath("../"))
import rlottie_python # type: ignore
import rlottie_python # type: ignore # noqa: F401

project = "rlottie-python"
copyright = "2023, laggykiller"
Expand Down
2 changes: 2 additions & 0 deletions example/example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
import os

from PIL import Image

from rlottie_python import LottieAnimation

file_dir = os.path.split(__file__)[0]
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ env = { "CMAKE_PREFIX_PATH" = "${HOME}/.local" }
config = "Release"

[tool.py-build-cmake.windows.cmake] # Windows-specific options
config = "Release"
config = "Release"

[tool.pyright]
include = ["rlottie_python", "tests", "example"]
strict = ["*"]

[tool.mypy]
python_version = "3.9"
2 changes: 1 addition & 1 deletion rlottie_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

__version__ = "1.3.2"

from .rlottie_wrapper import LottieAnimation # type: ignore
from .rlottie_wrapper import LottieAnimation # type: ignore # noqa: F401
6 changes: 3 additions & 3 deletions rlottie_python/_rlottiecommon.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python3
from ctypes import (
POINTER,
Structure,
c_char,
c_char_p,
c_size_t,
c_float,
c_int,
c_size_t,
c_ubyte,
Structure,
POINTER,
)

# References: rlottie/inc/rlottiecommon.h
Expand Down
9 changes: 5 additions & 4 deletions rlottie_python/rlottie_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import os
import sys
import sysconfig
from typing import Any, Tuple, Union, Optional, Type, TYPE_CHECKING
from types import TracebackType
from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Type, Union

if TYPE_CHECKING:
from PIL import Image

from ._rlottiecommon import LOTLayerNode, LOTMarkerList

# References: rlottie/inc/rlottie.h
Expand Down Expand Up @@ -57,7 +58,7 @@ def _load_lib(self, rlottie_lib_path: Optional[str] = None):

return None

lib_suffixes: "list[str]" = []
lib_suffixes: List[str] = []
shlib_suffix = sysconfig.get_config_var("SHLIB_SUFFIX")
if isinstance(shlib_suffix, str):
lib_suffixes.append(shlib_suffix)
Expand All @@ -71,7 +72,7 @@ def _load_lib(self, rlottie_lib_path: Optional[str] = None):

package_dir = os.path.dirname(__file__)

attempted_lib_paths: "list[str]" = []
attempted_lib_paths: List[str] = []
for lib_prefix in lib_prefixes:
for lib_suffix in lib_suffixes:
rlottie_lib_name = lib_prefix + "rlottie" + lib_suffix
Expand Down Expand Up @@ -813,7 +814,7 @@ def save_animation(
if frame_num_end is None:
frame_num_end = frames

im_list: "list[Image.Image]" = []
im_list: List[Image.Image] = []
for frame in range(frame_num_start, frame_num_end):
pos = frame / frame_num_end
frame_num = self.lottie_animation_get_frame_at_pos(pos)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_all.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env python3
import ctypes
from importlib.util import find_spec
import os
import platform
from importlib.util import find_spec

import pytest
from _pytest._py.path import LocalPath

PILLOW_LOADED = True if find_spec("PIL") else False

from rlottie_python import LottieAnimation
from rlottie_python._rlottiecommon import LOTLayerNode

PILLOW_LOADED = True if find_spec("PIL") else False

file_dir = os.path.split(__file__)[0]
json_file = os.path.join(file_dir, "../samples/sample.json")
tgs_file = os.path.join(file_dir, "../samples/sample.tgs")
Expand Down

0 comments on commit 32276e0

Please sign in to comment.