Skip to content

Commit

Permalink
Update from add-on template
Browse files Browse the repository at this point in the history
  • Loading branch information
abdnh committed Aug 20, 2023
1 parent 4a93382 commit da95afc
Show file tree
Hide file tree
Showing 29 changed files with 604 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = src/forms/*,src/vendor/*
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github: abdnh
patreon: abdnh
custom: ["https://www.buymeacoffee.com/abdnh"]
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: Run checks & tests

on:
push:
branches:
- "master"
- "main"
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install dependencies
run: .github/workflows/install_deps.sh

- name: Run checks
run: SKIP=pip-compile pre-commit run --all-files

- name: Run tests
run: make test
42 changes: 42 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Create Release

on:
create:
tags:
- "*"
permissions:
contents: write
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install dependencies
run: .github/workflows/install_deps.sh

- name: Create packages
run: make

- name: Extract changes
shell: bash
run: |
python .github/workflows/extract_changes.py ${{ github.ref }} > build/RELEASE.md
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: build/*.ankiaddon
body_path: build/RELEASE.md
15 changes: 15 additions & 0 deletions .github/workflows/extract_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"Print relevant changes from CHANGELOG.md given a version"

import re
import sys
from pathlib import Path

changelog = Path("CHANGELOG.md").read_text(encoding="utf-8")

version = sys.argv[1].replace("refs/tags/", "")
m = re.search(r"\[%s\].*?\n(.*)" % re.escape(version), changelog, re.DOTALL)
if not m:
sys.exit(0)
else:
changes = m.group(1).split("\n## ")[0]
print(changes)
4 changes: 4 additions & 0 deletions .github/workflows/install_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

pip install -r requirements/base.txt
pip-sync requirements/dev.txt
16 changes: 12 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
__pycache__/
venv/
*.pyc
vendor/
.mypy_cache/
.pytest_cache/
htmlcov/
.coverage
ankidata/
build/
src/manifest.json
src/meta.json
src/forms/
src/user_files/*/
src/user_files/config.json
*.ankiaddon
TODO.md
vendor/
node_modules/
TODO.md
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[settings]
profile=black
skip=vendor,venv,ankidata
skip=venv,ankidata,vendor,forms,user_files
74 changes: 74 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
exclude: "venv|vendor|build"
default_stages: [commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
exclude: ".vscode(.dist)?/.*"
- id: pretty-format-json
args: ["--autofix", "--indent", "4", "--no-ensure-ascii"]
exclude: ".vscode.dist/launch.json"
- id: check-yaml
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-shebang-scripts-are-executable
- id: mixed-line-ending
- id: detect-private-key

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: local
hooks:
- id: pylint
name: pylint
entry: python -m pylint src tests
language: system
types: [python]
- id: mypy
name: mypy
entry: python -m mypy
language: system
types: [python]
- id: pip-compile
name: pip-compile base
entry: python -m ankiscripts.update_deps --type base
language: system
files: ^(requirements/base\.(in|txt))$
pass_filenames: false
- id: pip-compile
name: pip-compile bundle
entry: python -m ankiscripts.update_deps --type bundle
language: system
files: ^(requirements/bundle\.(in|txt))$
pass_filenames: false
- id: pip-compile
name: pip-compile dev
entry: python -m ankiscripts.update_deps --type dev
language: system
files: ^(requirements/dev\.(in|txt))$
pass_filenames: false

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.1
hooks:
- id: prettier
args: ["--tab-width", "4", "--write"]
exclude: "ankiweb_page.html"

ci:
autoupdate_schedule: weekly
skip: []
submodules: false
27 changes: 21 additions & 6 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
[MASTER]
extension-pkg-whitelist=PyQt6,PyQt5
ignore-paths=ankidata,venv
ignore = venv,ankidata,vendor,forms,user_files

[REPORTS]
output-format=colorized

[MESSAGES CONTROL]
disable=
line-too-long,
too-many-lines,
missing-function-docstring,
missing-module-docstring,
missing-class-docstring,
missing-function-docstring,
import-outside-toplevel,
wrong-import-position,
wrong-import-order,
fixme,
unused-wildcard-import,
attribute-defined-outside-init,
redefined-builtin,
wildcard-import,
broad-except,
bare-except,
unused-argument,

[BASIC]
good-names =
mw
unused-variable,
redefined-outer-name,
global-statement,
protected-access,
arguments-renamed,
consider-using-f-string,
invalid-name
10 changes: 10 additions & 0 deletions .vscode.dist/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"ms-python.python",
"ms-python.pylint",
"ms-python.black-formatter",
"ms-python.isort",
"matangover.mypy",
"abdo.ankiwebify"
]
}
13 changes: 13 additions & 0 deletions .vscode.dist/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Run add-on",
"type": "python",
"request": "launch",
"module": "ankiscripts.run",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
12 changes: 12 additions & 0 deletions .vscode.dist/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"[html]": {
"editor.formatOnSave": false
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnSave": true
}
30 changes: 16 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
.PHONY: all zip clean mypy pylint fix vendor
all: zip
.PHONY: all zip ankiweb vendor fix mypy pylint test clean

PACKAGE_NAME := create_sub2srs_cards_with_mpv
all: zip ankiweb

zip: $(PACKAGE_NAME).ankiaddon
zip:
python -m ankiscripts.build --type package --qt all --exclude user_files/*.json

$(PACKAGE_NAME).ankiaddon: src/*
rm -f $@
find -L src/ -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
( cd src/; zip -r ../$@ * -x user_files/config.json )
ankiweb:
python -m ankiscripts.build --type ankiweb --qt all --exclude user_files/*.json

vendor:
pip install -r requirements.txt -t src/vendor
python -m ankiscripts.vendor

fix:
python -m black src --exclude="vendor"
python -m isort src
python -m black src tests --exclude="forms|vendor"
python -m isort src tests

mypy:
python -m mypy src
python -m mypy src tests

pylint:
python -m pylint src
python -m pylint src tests

test:
python -m pytest --cov=src --cov-config=.coveragerc

clean:
rm -f $(PACKAGE_NAME).ankiaddon
rm -rf build/
Loading

0 comments on commit da95afc

Please sign in to comment.