diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5f362fc --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +--- +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + labels: + - dependabot + - actions + schedule: + interval: daily + groups: + action-dependencies: + patterns: + - '*' + commit-message: + prefix: 'build' diff --git a/.github/workflows/check-code.yml b/.github/workflows/check-code.yml new file mode 100644 index 0000000..4011ced --- /dev/null +++ b/.github/workflows/check-code.yml @@ -0,0 +1,53 @@ +--- +name: Checks +on: + pull_request: + paths: + - '**.py*' + - '.github/workflows/check-code.yml' +jobs: + lint: + strategy: + fail-fast: false + matrix: + linter: [ + {'name': 'flake8', 'format': 'flake8', 'cwd': '.', 'cmd': 'flake8 .'}, + {'name': 'mypy', 'format': 'mypy', 'cwd': '.', 'cmd': 'mypy .'}, + {'name': 'pylint', 'format': 'pylint', 'cwd': '.', 'cmd': 'pylint --load-plugins pylint_pytest $(Get-ChildItem -Filter *.py -Recurse .)'}, + ] + name: ${{ matrix.linter.name }} + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Install Python dependencies + run: python -m pip install -r dev-requirements.txt + - name: Lint + run: cd ${{ matrix.linter.cwd }}; ${{ matrix.linter.cmd }} > lint.log + - name: Convert + uses: bugale/bugalint@v2 + if: always() + with: + inputFile: 'lint.log' + toolName: ${{ matrix.linter.name }} + inputFormat: ${{ matrix.linter.format }} + - name: Upload results + uses: github/codeql-action/upload-sarif@v3 + if: always() + with: + sarif_file: sarif.json + test: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + - uses: FedericoCarboni/setup-ffmpeg@v2 + id: setup-ffmpeg + - name: Install test dependencies + run: python -m pip install -r dev-requirements.txt + - name: Test + run: pytest tests diff --git a/.github/workflows/check-docs.yml b/.github/workflows/check-docs.yml new file mode 100644 index 0000000..a266ab1 --- /dev/null +++ b/.github/workflows/check-docs.yml @@ -0,0 +1,33 @@ +--- +name: Checks +on: + pull_request: + paths: + - '**.md' + - '**mdl*' + - '.github/workflows/check-docs.yml' +jobs: + markdownlint: + name: markdownlint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Lint + uses: avto-dev/markdown-lint@v1 + with: + args: '**/*.md' + output: 'lint.txt' + config: '.mdl.yml' + - name: Convert + uses: bugale/bugalint@v2 + if: always() + with: + inputFile: 'lint.txt' + toolName: 'mdl' + inputFormat: 'mdl' + - name: Upload results + uses: github/codeql-action/upload-sarif@v3 + if: always() + with: + sarif_file: sarif.json diff --git a/.github/workflows/check-general.yml b/.github/workflows/check-general.yml new file mode 100644 index 0000000..9cb72b7 --- /dev/null +++ b/.github/workflows/check-general.yml @@ -0,0 +1,41 @@ +--- +name: Checks +on: + - pull_request +jobs: + required: + name: Required Checks + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: bugale/bugroup-checks@v1 + with: + checks: |- + Check .* + .*[lL]int.* + self: Required Checks + check-commits: + name: Check Commits + runs-on: ubuntu-latest + steps: + - name: Install Dependencies + run: npm install -g @commitlint/cli @commitlint/config-conventional conventional-changelog-conventionalcommits + - name: Get Base + id: get-base + run: |- + count=$(gh api "/repos/${{ github.repository }}/pulls/${{ github.event.number }}/commits" --jq "length") + req=$(($count + 1)) + echo "count: $count, req: $req" + echo "commit-count=$count" >> $GITHUB_OUTPUT + echo "required=$req" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ github.token }} + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: ${{ steps.get-base.outputs.required }} + ref: ${{ github.event.pull_request.head.sha }} + - name: Check Commits + run: |- + commitlint --from ${{ github.event.pull_request.head.sha }}~${{ steps.get-base.outputs.commit-count }} --to ${{ github.event.pull_request.head.sha }} diff --git a/.github/workflows/check-yml.yml b/.github/workflows/check-yml.yml new file mode 100644 index 0000000..58c4dd7 --- /dev/null +++ b/.github/workflows/check-yml.yml @@ -0,0 +1,27 @@ +--- +name: Checks +on: + pull_request: + paths: + - '**.yml' +jobs: + yamllint: + name: yamllint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: yamllint + run: yamllint --strict -f parsable . > lint.txt + - name: Convert + uses: bugale/bugalint@v2 + if: always() + with: + inputFile: 'lint.txt' + toolName: 'yamllint' + inputFormat: 'yamllint' + - name: Upload results + uses: github/codeql-action/upload-sarif@v3 + if: always() + with: + sarif_file: sarif.json diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 0000000..1855519 --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -0,0 +1,18 @@ +--- +name: Dependabot +on: + - pull_request +permissions: write-all +jobs: + auto-merge: + name: Auto-merge + runs-on: ubuntu-latest + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@v1 + - name: Enable auto-merge for Dependabot PRs + run: gh pr merge --auto --rebase "${{github.event.pull_request.html_url}}" + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 233d5ef..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Lint - -on: - pull_request: - branches: [ main ] - -jobs: - lint: - strategy: - fail-fast: false - matrix: - linter: [ - {"name": "flake8", "format": "flake8", "cwd": ".", "cmd": "flake8 ."}, - {"name": "mypy", "format": "mypy", "cwd": ".", "cmd": "mypy ."}, - {"name": "pylint", "format": "pylint-json", "cwd": ".", "cmd": "pylint --load-plugins pylint_pytest $(Get-ChildItem -Filter *.py -Recurse .)"}, - ] - name: ${{ matrix.linter.name }} - runs-on: windows-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - name: Install Python dependencies - run: | - py -3.11 -m pip install --upgrade pip - py -3.11 -m pip install -r dev-requirements.txt - py -3.11 -m pip install git+https://github.com/bugale/Bugalintly.git@bugalintly - - name: Lint - run: | - cd ${{ matrix.linter.cwd }} - ${{ matrix.linter.cmd }} > lint.log - $exitcode = $LASTEXITCODE - type lint.log | Lintly --log --no-request-changes --no-review-body --base-dir . --format=${{ matrix.linter.format }} --comment-tag=${{ matrix.linter.name }} - exit $exitcode - env: - LINTLY_API_KEY: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 74f1fc4..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Test - -on: - pull_request: - branches: [ main ] - -jobs: - test: - runs-on: windows-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - uses: FedericoCarboni/setup-ffmpeg@v2 - id: setup-ffmpeg - - name: Install test dependencies - run: | - py -3.11 -m pip install --upgrade pip - py -3.11 -m pip install -r dev-requirements.txt - - name: Test - run: | - pytest tests diff --git a/.mdl.yml b/.mdl.yml new file mode 100644 index 0000000..9121d63 --- /dev/null +++ b/.mdl.yml @@ -0,0 +1,5 @@ +--- +# MD013/line-length - Line length +MD013: + line_length: 160 + ignore_code_blocks: true diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..4db652a --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,10 @@ +--- +extends: default +ignore: + - 'node_modules/**' +rules: + new-lines: disable + truthy: + check-keys: false + line-length: + max: 160 diff --git a/README.md b/README.md index 1af0a00..b79d71c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Buganime + My personal Anime organizer, that upscales your anime to 4K, burns the subtitles, leaves only Japanese audio, and organizes it in a Plex-friendly tree. diff --git a/buganime/buganime.py b/buganime/buganime.py index 32a2144..8d5fea0 100644 --- a/buganime/buganime.py +++ b/buganime/buganime.py @@ -157,7 +157,7 @@ def process_path(input_path: str) -> None: def main(args: list[str]) -> int: if len(args) != 1: - print("Usage: buganime.py ") + print('Usage: buganime.py ') return 1 input_path = args[0] diff --git a/buganime/transcode.py b/buganime/transcode.py index b5a541d..a50a925 100644 --- a/buganime/transcode.py +++ b/buganime/transcode.py @@ -104,8 +104,8 @@ async def __write_output_frames(self, frames: AsyncIterator[bytes]) -> None: def __gpu_upscale(self, frame: torch.Tensor) -> torch.Tensor: with torch.no_grad(): frame_float = frame.cuda().permute(2, 0, 1).half() / 255 - frame_upscaled_float = cast(torch.Tensor, self.__model(frame_float.unsqueeze(0)).data).squeeze().clamp_(0, 1) - return (frame_upscaled_float * 255.0).round().byte().permute(1, 2, 0).cpu() + frame_upscaled_float = self.__model(frame_float.unsqueeze(0)).data.squeeze().clamp_(0, 1) + return cast(torch.Tensor, (frame_upscaled_float * 255.0).round().byte().permute(1, 2, 0).cpu()) async def __upscale_frame(self, frame: bytes) -> bytes: if self.__video_info.height == self.__height_out: diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..42226d6 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,6 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'body-max-line-length': [0, 'always', 10000] + } +} diff --git a/dev-requirements.txt b/dev-requirements.txt index de29a6c..0469855 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,6 +2,7 @@ pytest pylint pylint-pytest flake8 +flake8-quotes mypy tqdm-stubs types-retry