diff --git a/.gitattributes b/.gitattributes index d9bd16b09..61d299b53 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ *.py text eol=lf +*.sh text eol=lf diff --git a/.github/workflows/precommit.yml b/.github/workflows/precommit.yml new file mode 100644 index 000000000..ec91487c8 --- /dev/null +++ b/.github/workflows/precommit.yml @@ -0,0 +1,16 @@ +on: + pull_request: + +jobs: + main: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.8", "3.12" ] # Lowest and highest. + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: "pip" # caching pip dependencies + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/typing.yml b/.github/workflows/typing.yml deleted file mode 100644 index e92850f57..000000000 --- a/.github/workflows/typing.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Static typing hint test - -on: - push: - pull_request: - workflow_dispatch: # Allows you to run this workflow manually from the Actions tab - -jobs: - # Build job - typing: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] - - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - cache: "pip" # caching pip dependencies - - - name: Install dependencies - run: | - pip install -r requirements.txt - pip install mypy - pip install types-Markdown - - - name: Run typing test - run: | - mypy --ignore-missing-imports ./boxes/ - mypy --ignore-missing-imports ./scripts/boxes - mypy --ignore-missing-imports ./scripts/boxes2inkscape - mypy --ignore-missing-imports ./scripts/boxes2pot - mypy --ignore-missing-imports ./scripts/boxesserver - mypy --ignore-missing-imports ./documentation/src/boxes2rst.py - mypy --ignore-missing-imports ./setup.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..905984aa5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,101 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +ci: + autofix_prs: true + autoupdate_schedule: quarterly +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-toml + - id: check-added-large-files + - id: requirements-txt-fixer + - id: check-case-conflict + - id: detect-private-key + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 # Use the ref you want to point at + hooks: + - id: python-use-type-annotations + - id: python-no-eval + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal + + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: [ --py38-plus ] + + - repo: https://github.com/PyCQA/autoflake + rev: v2.2.1 + hooks: + - id: autoflake + args: [ --remove-all-unused-imports, --in-place, --ignore-pass-statements, ] + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + + # A lot todo to pass test. + #- repo: https://github.com/PyCQA/flake8 + # rev: 6.1.0 + # hooks: + # - id: flake8 + # additional_dependencies: [ flake8-bugbear ] + # args: [ '--extend-ignore=E402,E501,E201,E202,E203,E221,E225,E231,E261,E266,E302,E305' ] + # # additional_dependencies: [ flake8-bugbear, flake8-docstrings ] + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.6.1 + hooks: + - id: mypy + args: [ '--ignore-missing-imports' ] + files: '^boxes/.*\.py$' + - id: mypy + args: [ '--ignore-missing-imports' ] + files: '^documentation/src/boxes2rst.py$' + - id: mypy + args: [ '--ignore-missing-imports' ] + files: '^scripts/boxes$' + - id: mypy + args: [ '--ignore-missing-imports' ] + files: '^scripts/boxes2inkscape$' + - id: mypy + args: [ '--ignore-missing-imports' ] + files: '^scripts/boxes2pot$' + - id: mypy + args: [ '--ignore-missing-imports' ] + files: '^scripts/boxes_proxy.py$' + - id: mypy + args: [ '--ignore-missing-imports' ] + additional_dependencies: [ 'types-Markdown' ] + files: '^scripts/boxesserver$' + - id: mypy + args: [ '--ignore-missing-imports' ] + files: '^setup.py$' + + - repo: https://github.com/rstcheck/rstcheck + rev: v6.2.0 + hooks: + - id: rstcheck + args: [ "--report-level=warning", "--ignore-directives=autoclass,automethod,automodule" ] + additional_dependencies: [ sphinx ] + + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.9.0.6 + hooks: + - id: shellcheck + + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + exclude: ^(boxes|locale|po|static)/ # todo folder boxes diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index e5b46653f..022b0fb6d 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -54,6 +54,19 @@ If you want feed back on you code feel free to open a PR. State that this is work in progress in the PR message. It's OK if it does not follow the guidelines (yet). +Check Code +.......... + +The `pre-commit `_ tool is used to verify the code style. +When installed, it automatically checks and corrects the code before each commit. + +* Install *pre-commit*, e.g. :code:`pip install pre-commit` +* Install githook :code:`pre-commit install` + +For manual check use :code:`pre-commit run --all-files`. + +To remove githook use :code:`pre-commit uninstall`. + Writing new Generators ...................... diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 000000000..ba521cb0f --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,4 @@ +inkex +mypy +pre-commit +types-Markdown diff --git a/scripts/boxes_proxy.py b/scripts/boxes_proxy.py index 65b067757..93fc451c7 100755 --- a/scripts/boxes_proxy.py +++ b/scripts/boxes_proxy.py @@ -12,16 +12,18 @@ License: GNU GPL v3 """ -import inkex -import sys import os -from lxml import etree +import sys import tempfile from shlex import quote +from inkex.extensions import GenerateExtension +from lxml import etree + +import inkex -class boxesPyWrapper(inkex.GenerateExtension): +class boxesPyWrapper(GenerateExtension): def add_arguments(self, pars): args = sys.argv[1:] for arg in args: