diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..1bf6e4b0 --- /dev/null +++ b/.flake8 @@ -0,0 +1,27 @@ +[flake8] +# Suggested config from pytorch that we can adapt +select = B,C,E,F,N,P,T4,W,B9,TOR0,TOR1,TOR2 +max-line-length = 120 +# C408 ignored because we like the dict keyword argument syntax +# E501 is not flexible enough, we're using B950 instead +# N812 ignored because import torch.nn.functional as F is PyTorch convention +# N817 ignored because importing using acronyms is convention (DistributedDataParallel as DDP) +# E731 allow usage of assigning lambda expressions +ignore = + E203,E305,E402,E501,E721,E741,F405,F821,F841,F999,W503,W504,C408,E302,W291,E303,N812,N817,E731 + # shebang has extra meaning in fbcode lints, so I think it's not worth trying + # to line this up with executable bit + EXE001, + # these ignores are from flake8-bugbear; please fix! + B007,B008, +optional-ascii-coding = True +exclude = + ./.git, + ./docs + ./build + ./scripts, + ./venv, + *.pyi + .pre-commit-config.yaml + *.md + .flake8 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..03d6d555 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,39 @@ +name: Lint + +on: + pull_request: + +concurrency: + group: lint-${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash -l -eo pipefail {0} + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.11'] + steps: + - name: Check out repo + uses: actions/checkout@v3 + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Update pip + run: python -m pip install --upgrade pip + - name: Install lint utilities + run: | + python -m pip install pre-commit + pre-commit install-hooks + - id: file_changes + uses: trilom/file-changes-action@v1.2.4 + with: + prNumber: ${{ github.event.number }} + output: ' ' + - name: Lint modified files + run: pre-commit run --files ${{ steps.file_changes.outputs.files }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..318f7ef2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,51 @@ +exclude: 'build' + +default_language_version: + python: python3 + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: 6306a48f7dae5861702d573c9c247e4e9498e867 + hooks: + - id: trailing-whitespace + - id: check-ast + - id: check-merge-conflict + - id: no-commit-to-branch + args: ['--branch=main'] + - id: check-added-large-files + args: ['--maxkb=500'] + - id: end-of-file-fixer + exclude: '^(.*\.svg)$' + +- repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.5.4 + hooks: + - id: insert-license + files: \.py$ + args: + - --license-filepath + - docs/license_header.txt + +- repo: https://github.com/pycqa/flake8 + rev: 34cbf8ef3950f43d09b85e2e45c15ae5717dc37b + hooks: + - id: flake8 + additional_dependencies: + - flake8-bugbear == 22.4.25 + - pep8-naming == 0.12.1 + - torchfix + args: ['--config=.flake8'] + +- repo: https://github.com/omnilib/ufmt + rev: v2.3.0 + hooks: + - id: ufmt + additional_dependencies: + - black == 22.12.0 + - usort == 1.0.5 + +- repo: https://github.com/jsh9/pydoclint + rev: d88180a8632bb1602a4d81344085cf320f288c5a + hooks: + - id: pydoclint + args: [--config=pyproject.toml] diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 00000000..1f960b0b --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1,3 @@ +pytest +pytest-cov +pre-commit diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..55007a7b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[tool.pydoclint] +style = 'google' +check-return-types = 'False' + +[tool.pytest.ini_options] +addopts = ["--showlocals"] # show local variables in tracebacks