Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.ruffPath": "/usr/local/py-utils/bin/ruff",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
Expand Down
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ All Python code must adhere to the style guide used by capa:

1. [PEP8](https://www.python.org/dev/peps/pep-0008/), with clarifications from
2. [Willi's style guide](https://docs.google.com/document/d/1iRpeg-w4DtibwytUyC_dDT7IGhNGBP25-nQfuBa-Fyk/edit?usp=sharing), formatted with
3. [isort](https://pypi.org/project/isort/) (with line width 120 and ordered by line length), and formatted with
3. [ruff](https://docs.astral.sh/ruff/) (with line length 120 and imports ordered by line length), and formatted with
4. [black](https://github.com/psf/black) (with line width 120), and formatted with
5. [dos2unix](https://linux.die.net/man/1/dos2unix)

Expand Down
41 changes: 0 additions & 41 deletions .github/flake8.ini

This file was deleted.

69 changes: 55 additions & 14 deletions .github/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Enable the pycodestyle (`E`) and Pyflakes (`F`) rules by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
lint.select = ["E", "F"]

# Allow autofix for all enabled rules (when `--fix`) is provided.
lint.fixable = ["ALL"]
lint.unfixable = []

# E402 module level import not at top of file
# E722 do not use bare 'except'
# E501 line too long
lint.ignore = ["E402", "E722", "E501"]

line-length = 120

exclude = [
Expand Down Expand Up @@ -41,3 +27,58 @@ exclude = [
"*_pb2.py",
"*_pb2.pyi"
]

# Enable pycodestyle (`E`), Pyflakes (`F`), isort (`I`), Bugbear (`B`),
# Comprehensions (`C4`), Implicit String Concat (`ISC`), Print (`T20`),
# Simplify (`SIM`), and Copyright (`CPY`) for strict parity.
lint.select = [
"E",
"F",
"I",
"B",
"C4",
"ISC",
"T20",
"SIM",
"CPY"
]
Comment thread
mike-hunhoff marked this conversation as resolved.

# Allow autofix for all enabled rules (when `--fix`) is provided.
lint.fixable = ["ALL"]
lint.unfixable = []

# Map existing flake8 ignores to maintain strict formatting parity
lint.ignore = [
"E402",
"E722",
"E501",
"E203",
"E701",
"B010",
"SIM102",
"SIM114",
"SIM117",
"B905",
"SIM300",
"ISC003",
"SIM103",
"SIM108",
"I001",
"SIM118",
"SIM401",
"SIM115",
"B904"
]
Comment thread
mike-hunhoff marked this conversation as resolved.

[lint.per-file-ignores]
# T201 print found schemas for scripts and entrypoints
"scripts/*" = ["T201"]
"capa/main.py" = ["T201"]
"capa/features/extractors/binja/find_binja_api.py" = ["T201"]

[lint.flake8-copyright]
notice-rgx = "Copyright \\d{4} Google LLC"
min-file-size = 1

[lint.isort]
length-sort = true
8 changes: 5 additions & 3 deletions .github/workflows/black-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ jobs:
pip install -r requirements.txt
pip install -e .[dev,scripts]

- name: Run isort
run: pre-commit run isort --all-files
- name: Run ruff/continue
# ruff returns non-zero error code after formatting, which is what we expect
continue-on-error: true
run: pre-commit run ruff --all-files

- name: Run black/continue
# black returns non-zero error code after formatting, which is what we expect
Expand All @@ -58,5 +60,5 @@ jobs:
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
git add -A
git commit -m "style: auto-format with black and isort"
git commit -m "style: auto-format with ruff and black"
git push
4 changes: 0 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ jobs:
pip install -e .[dev,scripts]
- name: Lint with ruff
run: pre-commit run ruff
- name: Lint with isort
run: pre-commit run isort --show-diff-on-failure
- name: Lint with black
run: pre-commit run black --show-diff-on-failure
- name: Lint with flake8
run: pre-commit run flake8 --hook-stage manual
- name: Check types with mypy
run: pre-commit run mypy --hook-stage manual
- name: Check imports against dependencies
Expand Down
8 changes: 0 additions & 8 deletions .justfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
@isort:
pre-commit run isort --show-diff-on-failure --all-files

@black:
pre-commit run black --show-diff-on-failure --all-files

@ruff:
pre-commit run ruff --all-files

@flake8:
pre-commit run flake8 --hook-stage manual --all-files

@mypy:
pre-commit run mypy --hook-stage manual --all-files

@deptry:
pre-commit run deptry --hook-stage manual --all-files

@lint:
-just isort
-just black
-just ruff
Comment thread
mike-hunhoff marked this conversation as resolved.
-just flake8
-just mypy
-just deptry
44 changes: 2 additions & 42 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,16 @@
# run all linters liks:
#
# ❯ pre-commit run --all-files
# isort....................................................................Passed
# black....................................................................Passed
# ruff.....................................................................Passed
# flake8...................................................................Passed
# mypy.....................................................................Passed
#
# run a single linter like:
#
# ❯ pre-commit run --all-files isort
# isort....................................................................Passed
# ❯ pre-commit run --all-files ruff
# ruff.....................................................................Passed

repos:
- repo: local
hooks:
- id: isort
name: isort
stages: [pre-commit, pre-push, manual]
language: system
entry: isort
args:
- "--length-sort"
- "--profile"
- "black"
- "--line-length=120"
- "--skip-glob"
- "*_pb2.py"
- "capa/"
- "scripts/"
- "tests/"
- "web/rules/scripts/"
always_run: true
pass_filenames: false

- repo: local
hooks:
Expand Down Expand Up @@ -78,24 +56,6 @@ repos:
always_run: true
pass_filenames: false

- repo: local
hooks:
- id: flake8
name: flake8
stages: [pre-push, manual]
language: system
entry: flake8
args:
- "--config"
- ".github/flake8.ini"
- "--extend-exclude"
- "capa/render/proto/capa_pb2.py,capa/features/extractors/binexport2/binexport2_pb2.py"
- "capa/"
- "scripts/"
- "tests/"
- "web/rules/scripts/"
always_run: true
pass_filenames: false

- repo: local
hooks:
Expand Down
10 changes: 3 additions & 7 deletions doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ Please install these dependencies before install capa (from source or from PyPI)

We use the following tools to ensure consistent code style and formatting:
- [black](https://github.com/psf/black) code formatter
- [isort](https://pypi.org/project/isort/) code formatter
- [ruff](https://beta.ruff.rs/docs/) code linter
- [flake8](https://flake8.pycqa.org/en/latest/) code linter
- [ruff](https://docs.astral.sh/ruff/) code linter and formatter
- [mypy](https://mypy-lang.org/) type checking
- [capafmt](https://github.com/mandiant/capa/blob/master/scripts/capafmt.py) rule formatter

Expand All @@ -115,17 +113,15 @@ We use [pre-commit](https://pre-commit.com/) so that its trivial to run the same
Run all linters like:

❯ pre-commit run --hook-stage=manual --all-files
isort....................................................................Passed
black....................................................................Passed
ruff.....................................................................Passed
flake8...................................................................Passed
mypy.....................................................................Passed
pytest (fast)............................................................Passed

Or run a single linter like:

❯ pre-commit run --all-files --hook-stage=manual isort
isort....................................................................Passed
❯ pre-commit run --all-files --hook-stage=manual ruff
ruff.....................................................................Passed


Importantly, you can configure pre-commit to run automatically before every commit by running:
Expand Down
27 changes: 2 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,8 @@ dev = [
"pytest==9.0.2",
"pytest-sugar==1.1.1",
"pytest-instafail==0.5.0",
"flake8==7.3.0",
"flake8-bugbear==25.11.29",
"flake8-encodings==0.5.1",
"flake8-comprehensions==3.17.0",
"flake8-logging-format==0.9.0",
"flake8-no-implicit-concat==0.3.5",
"flake8-print==5.0.0",
"flake8-todos==0.3.1",
"flake8-simplify==0.30.0",
"flake8-use-pathlib==0.3.0",
"flake8-copyright==0.2.4",
"ruff==0.15.0",
"black==26.3.0",
"isort==8.0.0",
"mypy==1.19.1",
"mypy-protobuf==5.0.0",
"PyGithub==2.9.0",
Expand All @@ -166,7 +154,7 @@ build = [
# These dependencies are not used in production environments
# and should not conflict with other libraries/tooling.
"pyinstaller==6.19.0",
"setuptools==80.10.1",
"setuptools==82.0.1",
"build==1.4.0"
]
scripts = [
Expand Down Expand Up @@ -222,18 +210,7 @@ DEP002 = [
"build",
"bump-my-version",
"deptry",
"flake8",
"flake8-bugbear",
"flake8-comprehensions",
"flake8-copyright",
"flake8-encodings",
"flake8-logging-format",
"flake8-no-implicit-concat",
"flake8-print",
"flake8-simplify",
"flake8-todos",
"flake8-use-pathlib",
"isort",

"mypy",
"mypy-protobuf",
"pre-commit",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pyyaml==6.0.2
rich==14.3.2
ruamel-yaml==0.19.1
ruamel-yaml-clib==0.2.14
setuptools==80.10.1
setuptools==82.0.1
six==1.17.0
sortedcontainers==2.4.0
viv-utils==0.8.0
Expand Down
2 changes: 1 addition & 1 deletion scripts/profile-memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def display_top(snapshot, key_type="lineno", limit=10):


def main():
# import within main to keep isort happy
# import within main to keep ruff happy
# while also invoking tracemalloc.start() immediately upon start.
import io
import os
Expand Down
Loading