Skip to content

Setting up pre-commit #1

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 18 additions & 18 deletions .github/workflows/automaticRelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ jobs:
git commit -m "Update translations" --allow-empty
git pull
git push
zip-rules:

zip-rules:
name: zip up the rules directory
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build Rust Library
- name: Build Rust Library
run: |
cargo build --target x86_64-unknown-linux-gnu # doesn't need a release build since all that we want is the Rules dir
- name: create rules.zip
Expand All @@ -42,15 +42,15 @@ jobs:
filename: 'Rules.zip'
directory: 'addon/globalPlugins/MathCAT'
path: 'Rules'
- name: Upload Rules.zip
- name: Upload Rules.zip
uses: actions/upload-artifact@v4
with:
name: 'Rules.zip'
path: 'addon/globalPlugins/MathCAT/Rules.zip'
compression-level: 0
retention-days: 1

rust-32:
rust-32:
name: Build 32 bit windows pyd file
runs-on: windows-latest # needs to run on windows because of bzip2
steps:
Expand All @@ -61,7 +61,7 @@ jobs:
with:
python-version: 3.11
architecture: 'x86'
- name: Build Rust Library
- name: Build Rust Library
run: |
cargo build --target i686-pc-windows-msvc --release
- name: Setup Example dir
Expand All @@ -79,15 +79,15 @@ jobs:
filename: '../libmathcat_py-32-3.11-win.zip'
directory: 'Example'
path: 'libmathcat_py.pyd'
- name: Upload 32 bit pyd file
- name: Upload 32 bit pyd file
uses: actions/upload-artifact@v4
with:
name: libmathcat_py-32-3.11-win.zip
path: libmathcat_py-32-3.11-win.zip
compression-level: 0
retention-days: 1
rust-64:

rust-64:
name: Build 64 bit windows pyd file
runs-on: windows-latest # needs to run on windows because of bzip2
steps:
Expand All @@ -98,7 +98,7 @@ jobs:
with:
python-version: 3.11
architecture: 'x64'
- name: Build Rust Library
- name: Build Rust Library
run: |
cargo build --target x86_64-pc-windows-msvc --release
- name: Setup Example dir
Expand All @@ -116,15 +116,15 @@ jobs:
run: |
cd Example
python test.py
- name: Upload 64 bit pyd file
- name: Upload 64 bit pyd file
uses: actions/upload-artifact@v4
with:
name: libmathcat_py-64-3.11-win.zip
path: libmathcat_py-64-3.11-win.zip
compression-level: 0
retention-days: 1
linux-64:

linux-64:
name: Build linux pyd file (64-bit intel)
runs-on: ubuntu-latest
steps:
Expand All @@ -135,7 +135,7 @@ jobs:
with:
python-version: 3.11
architecture: 'x64'
- name: Build Rust Library
- name: Build Rust Library
run: |
cargo build --target x86_64-unknown-linux-gnu --release
- name: Setup Example dir
Expand All @@ -154,14 +154,14 @@ jobs:
filename: '../libmathcat_py-64-3.11-linux.zip'
directory: 'Example'
path: 'libmathcat_py.so'
- name: Upload 64 bit pyd file
- name: Upload 64 bit pyd file
uses: actions/upload-artifact@v4
with:
name: libmathcat_py-64-3.11-linux.zip
path: libmathcat_py-64-3.11-linux.zip
compression-level: 0
retention-days: 1

build-addon:
name: build-addon
continue-on-error: false
Expand Down Expand Up @@ -202,15 +202,15 @@ jobs:
- name: Run scons to build .addon file
run: |
scons
- name: Upload the addon
- name: Upload the addon
uses: actions/upload-artifact@v4
with:
name: addon
path: "*.nvda-addon"
compression-level: 0
retention-days: 1

pre-release:
pre-release:
name: Pre Release
continue-on-error: false
needs: [zip-rules, rust-32, rust-64, linux-64, build-addon]
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/checkTranslatorsComments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
pip install scons markdown
sudo apt update
sudo apt install gettext

- name: Generate the .pot file
run: scons pot

Expand All @@ -43,7 +43,7 @@ jobs:
# checkPot.EXPECTED_MESSAGES_WITHOUT_COMMENTS = set()
# res = checkPot.checkPot('$(ls *.pot)')
# exit(res)
#shell: python
#shell: python
run: |
python -c "import checkPot;checkPot.EXPECTED_MESSAGES_WITHOUT_COMMENTS = set();exit(checkPot.checkPot('$(ls *.pot)'))"
echo "nb_errors=$?" >> "$GITHUB_OUTPUT"
Expand All @@ -58,4 +58,3 @@ jobs:
echo "Translators comments: FAIL"
exit 1;
fi

2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
with:
working-directory: code/addon/globalPlugins/MathCAT
python-version: 3.11
pylance-version: latest-release
pylance-version: latest-release
9 changes: 4 additions & 5 deletions .github/workflows/manualRelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Manual release
on:
workflow_dispatch:
inputs:
version:
version:
description: 'Add-on version'
required: true
default: '0.0.0'
Expand All @@ -20,7 +20,7 @@ jobs:
buildAndUpload:
continue-on-error: true
runs-on: ubuntu-latest

permissions:
contents: write

Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
f.seek(0)
f.write(text)
f.truncate()
shell: python
shell: python
- name: Build add-on
run: scons
- name: Push changes
Expand All @@ -67,7 +67,7 @@ jobs:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- if: ${{ inputs.signAddOn }}
name: Sign add-on
name: Sign add-on
run: gpg --detach-sign *.nvda-addon
- name: Calculate sha256
run: sha256sum *.nvda-addon >> sha256.txt
Expand All @@ -82,4 +82,3 @@ jobs:
artifacts: "*.nvda-addon,*.sig,publicKey.asc,sha256.txt"
generateReleaseNotes: true
prerelease: ${{ inputs.prerelease }}

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ manifest.ini
*.nvda-addon
.sconsign.dblite
/[0-9]*.[0-9]*.[0-9]*.json
.venv/
106 changes: 106 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

# https://pre-commit.ci/
# Configuration for Continuous Integration service
ci:
# Can't run Windows scons scripts on Linux.
# unit testing requires our python environment,
# which cannot be configured with pre-commit.ci:
# https://stackoverflow.com/questions/70778806/pre-commit-not-using-virtual-environment .
# Can't run licenseCheck as it relies on telemetry,
# which CI blocks.
skip: [pyrightLocal]
autoupdate_schedule: monthly
autoupdate_commit_msg: "Pre-commit auto-update"
autofix_commit_msg: "Pre-commit auto-fix"
submodules: true

default_language_version:
python: python3.11

repos:
- repo: https://github.com/pre-commit-ci/pre-commit-ci-config
rev: v1.6.1
hooks:
- id: check-pre-commit-ci-config

- repo: meta
hooks:
# ensures that exclude directives apply to any file in the repository.
- id: check-useless-excludes
# ensures that the configured hooks apply to at least one file in the repository.
- id: check-hooks-apply

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
# Prevents commits to certain branches
- id: no-commit-to-branch
args: ["--branch", "master", "--branch", "beta", "--branch", "rc"]
# Checks that large files have not been added. Default cut-off for "large" files is 500kb.
- id: check-added-large-files
# POFiles and TTF fonts can't be made smaller
exclude_types: ["pofile", "ttf"]
# Same applies for NVDA dictionary (.dic) files and Spline Font Database (.SFD) files, but these aren't recognised by the Identify library.
# Checks python syntax
- id: check-ast
# Checks for filenames that will conflict on case insensitive filesystems (the majority of Windows filesystems, most of the time)
- id: check-case-conflict
# Checks for artifacts from resolving merge conflicts.
- id: check-merge-conflict
# Checks Python files for debug statements, such as python's breakpoint function, or those inserted by some IDEs.
- id: debug-statements
# Removes trailing whitespace.
- id: trailing-whitespace
types_or: [python, c, c++, batch, markdown, toml, yaml]
# Ensures all files end in 1 (and only 1) newline.
- id: end-of-file-fixer
types_or: [python, c, c++, batch, markdown, toml, yaml]
# Removes the UTF-8 BOM from files that have it.
# See https://github.com/nvaccess/nvda/blob/master/projectDocs/dev/codingStandards.md#encoding
- id: fix-byte-order-marker
types_or: [python, c, c++, batch, markdown, toml, yaml]
# Validates TOML files.
- id: check-toml
# Validates YAML files.
- id: check-yaml
# Validates XML files.
# Ensures that links to lines in files under version control point to a particular commit.
- id: check-vcs-permalinks
# Avoids using reserved Windows filenames.
- id: check-illegal-windows-names
args: ["--unittest"]

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
# Ruff preserves indent/new-line formatting of function arguments, list items, and similar iterables,
# if a trailing comma is added.
# This adds a trailing comma to args/iterable items in case it was missed.
- id: add-trailing-comma

- repo: https://github.com/astral-sh/ruff-pre-commit
# Matches Ruff version in pyproject.
rev: v0.8.1
hooks:
- id: ruff
name: lint with ruff
args: [ --fix ]
- id: ruff-format
name: format with ruff

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.394
hooks:
- id: pyright
alias: pyrightLocal
name: Check types with pyright

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.396
hooks:
- id: pyright
alias: pyrightCI
name: Check types with pyright
# use nodejs version of pyright and install pyproject.toml for CI
additional_dependencies: [".", "pyright[nodejs]"]
stages: [manual] # Only run from CI manually
Loading