Skip to content

Commit

Permalink
treewide: switch to ruff format (#811)
Browse files Browse the repository at this point in the history
This speeds up our `lint` and `reformat` targets a bit, and drops
a dev dependency (since we're already using ruff).

Signed-off-by: William Woodruff <william@trailofbits.com>
  • Loading branch information
woodruffw authored Oct 27, 2023
1 parent d761384 commit 9ca8344
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 33 deletions.
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ make lint

`sigstore` is automatically linted and formatted with a collection of tools:

* [`black`](https://github.com/psf/black): Code formatting
* [`isort`](https://github.com/PyCQA/isort): Import sorting, ordering
* [`ruff`](https://github.com/charliermarsh/ruff): PEP-8 linting, style enforcement
* [`ruff`](https://github.com/charliermarsh/ruff): Code formatting, PEP-8 linting, style enforcement
* [`mypy`](https://mypy.readthedocs.io/en/stable/): Static type checking
* [`bandit`](https://github.com/PyCQA/bandit): Security issue scanning
* [`interrogate`](https://interrogate.readthedocs.io/en/latest/): Documentation coverage
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ run: $(VENV)/pyvenv.cfg
.PHONY: lint
lint: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
black --check $(ALL_PY_SRCS) && \
isort --check $(ALL_PY_SRCS) && \
ruff format --check $(ALL_PY_SRCS) && \
ruff $(ALL_PY_SRCS) && \
mypy $(PY_MODULE) && \
bandit -c pyproject.toml -r $(PY_MODULE) && \
Expand All @@ -74,8 +73,7 @@ lint: $(VENV)/pyvenv.cfg
reformat: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
ruff --fix $(ALL_PY_SRCS) && \
black $(ALL_PY_SRCS) && \
isort $(ALL_PY_SRCS)
ruff format $(ALL_PY_SRCS)

.PHONY: test
test: $(VENV)/pyvenv.cfg
Expand Down
11 changes: 2 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ Documentation = "https://sigstore.github.io/sigstore-python/"
test = ["pytest", "pytest-cov", "pretend", "coverage[toml]"]
lint = [
"bandit",
"black",
"isort",
"interrogate",
"mypy ~= 1.1",
# NOTE(ww): ruff is under active development, so we pin conservatively here
# and let Dependabot periodically perform this update.
"ruff < 0.1.2",
"ruff < 0.1.4",
"types-requests",
# TODO(ww): Re-enable once dependency on types-cryptography is dropped.
# See: https://github.com/python/typeshed/issues/8699
Expand All @@ -68,11 +66,6 @@ lint = [
doc = ["pdoc"]
dev = ["build", "bump >= 1.3.2", "sigstore[doc,test,lint]"]

[tool.isort]
multi_line_output = 3
known_first_party = "sigstore"
include_trailing_comma = true

[tool.coverage.run]
# branch coverage in addition to statement coverage.
branch = true
Expand Down Expand Up @@ -129,5 +122,5 @@ exclude_dirs = ["./test"]
ignore = ["E501"]
# TODO: Enable "UP" here once Pydantic allows us to:
# See: https://github.com/pydantic/pydantic/issues/4146
select = ["E", "F", "W"]
select = ["E", "F", "I", "W"]
target-version = "py38"
3 changes: 1 addition & 2 deletions sigstore/verify/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ def rekor_entry(self, client: RekorClient) -> LogEntry:

offline = self._offline
has_inclusion_promise = (
self.has_rekor_entry
and self._rekor_entry.inclusion_promise is not None # type: ignore
self.has_rekor_entry and self._rekor_entry.inclusion_promise is not None # type: ignore
)
has_inclusion_proof = (
self.has_rekor_entry
Expand Down
6 changes: 3 additions & 3 deletions sigstore/verify/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class LogEntryMissing(VerificationFailure):
with additional lookup context.
"""

reason: str = (
"The transparency log has no entry for the given verification materials"
)
reason: (
str
) = "The transparency log has no entry for the given verification materials"

signature: B64Str
"""
Expand Down
27 changes: 15 additions & 12 deletions test/unit/internal/test_sct.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ def test_pack_digitally_signed_precertificate(precert_bytes_len):
_, l1, l2, l3 = struct.unpack("!4c", struct.pack("!I", len(precert_bytes)))

data = sct._pack_digitally_signed(mock_sct, cert, issuer_key_hash)
assert data == (
b"\x00" # version
b"\x00" # signature type
b"\x00\x00\x00\x00\x00\x00\x04\xd2" # timestamp
b"\x00\x01" # entry type
b"iamapublickeyshatwofivesixdigest" # issuer key hash
+ l1
+ l2
+ l3 # tbs cert length
+ precert_bytes # tbs cert
+ b"\x00\x00" # extensions length
+ b"" # extensions
assert (
data
== (
b"\x00" # version
b"\x00" # signature type
b"\x00\x00\x00\x00\x00\x00\x04\xd2" # timestamp
b"\x00\x01" # entry type
b"iamapublickeyshatwofivesixdigest" # issuer key hash
+ l1
+ l2
+ l3 # tbs cert length
+ precert_bytes # tbs cert
+ b"\x00\x00" # extensions length
+ b"" # extensions
)
)

0 comments on commit 9ca8344

Please sign in to comment.