Skip to content
Merged
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
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

13 changes: 13 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Lint

on:
push:
branches:
- master
pull_request:

jobs:
lint:
uses: trailofbits/.github/.github/workflows/lint.yml@v0.0.2
with:
python-version: "3.7"
13 changes: 0 additions & 13 deletions .github/workflows/ci.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.7"

- run: make dev

- run: make lint

test:
strategy:
matrix:
Expand Down
56 changes: 38 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,60 @@
# Optionally overriden by the user, if they're using a virtual environment manager.
VENV ?= env
VENV_EXISTS := $(VENV)/pyvenv.cfg

# On Windows, venv scripts/shims are under `Scripts` instead of `bin`.
VENV_BIN := $(VENV)/bin
ifeq ($(OS),Windows_NT)
VENV_BIN := $(VENV)/Scripts
endif

# Optionally overridden by the user/CI, to limit the installation to a specific
# subset of development dependencies.
BLIGHT_EXTRA := dev

ALL_PY_SRCS := $(shell find src -name '*.py') \
$(shell find test -name '*.py')

.PHONY: all
all:
@echo "Run my targets individually!"

.PHONY: dev
dev:
test -d env || python -m venv env
. env/bin/activate && \
$(VENV)/pyvenv.cfg: pyproject.toml
python -m venv env
. $(VENV_BIN)/activate && \
pip install --upgrade pip setuptools && \
pip install -e .[dev]
pip install -e .[$(BLIGHT_EXTRA)]

.PHONY: dev
dev: $(VENV)/pyvenv.cfg

.PHONY: lint
lint:
. env/bin/activate && \
black $(ALL_PY_SRCS) && \
isort $(ALL_PY_SRCS) && \
flake8 $(ALL_PY_SRCS) && \
mypy src && \
git diff --exit-code
lint: $(VENV_EXISTS)
. $(VENV_BIN)/activate && \
black --check $(ALL_PY_SRCS) && \
ruff $(ALL_PY_SRCS) && \
mypy src

.PHONY: reformat
reformat: $(VENV_EXISTS)
. $(VENV_BIN)/activate && \
ruff --fix $(ALL_PY_SRCS) && \
black $(ALL_PY_SRCS)

.PHONY: test
test:
. env/bin/activate && \
test: $(VENV_EXISTS)
. $(VENV_BIN)/activate && \
pytest --cov=blight test/ && \
python -m coverage report -m --fail-under 100

.PHONY: doc
doc:
. env/bin/activate && \
doc: $(VENV_EXISTS)
. $(VENV_BIN)/activate && \
PYTHONWARNINGS='error::UserWarning' pdoc --force --html blight

.PHONY: package
package:
. env/bin/activate && \
package: $(VENV_EXISTS)
. $(VENV_BIN)/activate && \
python -m build && \
twine upload --repository pypi dist/*

Expand Down
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ requires-python = ">=3.7"

[project.optional-dependencies]
dev = [
"flake8",
"black",
"isort",
"pytest",
"pytest-cov",
"pretend",
"coverage[toml]",
"twine",
"pdoc3",
"mypy",
"ruff",
]

[project.scripts]
Expand All @@ -56,14 +55,14 @@ Documentation = "https://trailofbits.github.io/blight/"
Issues = "https://github.com/trailofbits/blight/issues"
Source = "https://github.com/trailofbits/blight"

[tool.isort]
line_length = 100
multi_line_output = 3
known_first_party = "blight"

[tool.black]
line-length = 100

[tool.coverage.run]
# don't attempt code coverage for the CLI entrypoints
omit = ["src/blight/cli.py"]

[tool.ruff]
line-length = 100
select = ["E", "F", "W", "UP", "I", "N", "YTT", "BLE", "C4", "SIM"]
target-version = "py37"
2 changes: 1 addition & 1 deletion src/blight/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CompilerAction(CCAction, CXXAction):
"""

def _should_run_on(self, tool: Tool) -> bool:
return isinstance(tool, blight.tool.CC) or isinstance(tool, blight.tool.CXX)
return isinstance(tool, (blight.tool.CC, blight.tool.CXX))


class CPPAction(Action):
Expand Down
2 changes: 1 addition & 1 deletion src/blight/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BuildError(BlightError):
pass


class SkipRun(BlightError):
class SkipRun(BlightError): # noqa: N818
"""
A special error that `before_run` actions can raise to tell the underlying
tool not to actually run.
Expand Down
12 changes: 3 additions & 9 deletions src/blight/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
CompilerStage,
Lang,
OptLevel,
Std
Std,
)
from blight.exceptions import BlightError, BuildError, SkipRun
from blight.protocols import CanonicalizedArgsProtocol, IndexedUndefinesProtocol, LangProtocol
Expand Down Expand Up @@ -580,10 +580,7 @@ def indexed_undefines(self: IndexedUndefinesProtocol) -> Dict[str, int]:
continue

# Both `-Uname` and `-U name` work in GCC and Clang.
if arg == "-U":
undefine = self.canonicalized_args[idx + 1]
else:
undefine = arg[2:]
undefine = self.canonicalized_args[idx + 1] if arg == "-U" else arg[2:]

indexed_undefines[undefine] = idx

Expand All @@ -604,10 +601,7 @@ def defines(self: IndexedUndefinesProtocol) -> List[Tuple[str, str]]:
continue

# Both `-Dname[=value]` and `-D name[=value]` work in GCC and Clang.
if arg == "-D":
define = self.canonicalized_args[idx + 1]
else:
define = arg[2:]
define = self.canonicalized_args[idx + 1] if arg == "-D" else arg[2:]

components = define.split("=", 1)
name = components[0]
Expand Down
1 change: 0 additions & 1 deletion test/actions/test_find_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json

import pytest

from blight.actions import FindOutputs
from blight.actions.find_outputs import OutputKind
from blight.tool import CC, INSTALL
Expand Down
1 change: 0 additions & 1 deletion test/actions/test_skip_strip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from blight.actions import SkipStrip
from blight.exceptions import SkipRun
from blight.tool import CC, STRIP
Expand Down
1 change: 0 additions & 1 deletion test/test_action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from blight import action, tool


Expand Down
1 change: 0 additions & 1 deletion test/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pretend
import pytest

from blight import tool, util
from blight.enums import CodeModel, CompilerFamily, CompilerStage, Lang, OptLevel, Std
from blight.exceptions import BlightError, BuildError
Expand Down
1 change: 0 additions & 1 deletion test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pretend
import pytest

from blight import util
from blight.actions import Record
from blight.exceptions import BlightError
Expand Down