Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch to ruff format over black #765

Merged
merged 7 commits into from
Jan 24, 2025
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ repos:
hooks:

# note: this is used in lieu of autopep8 and yapf
- id: black
name: black
- id: format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change to generalize this rather than use the tool name

name: format
# note: why not use the official black pre-commit hook? so we can use poetry to control which version of black is used.
entry: make format
pass_filenames: false
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ lint-fix: virtual-env-check ## Fix linting issues (ruff)
ruff check . --fix

.PHONY: format
format: virtual-env-check ## Format all code (black)
black src tests
format: virtual-env-check ## Format all code (ruff format)
ruff format src tests
poetry run python scripts/format-json-snapshots.py

.PHONY: check-types
Expand Down
99 changes: 21 additions & 78 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 22 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ zstandard = ">=0.22,<0.24"
[tool.poetry.group.dev.dependencies]
pytest = ">=7.2.2,<9.0.0"
pre-commit = ">=3.2,<5.0"
black = ">=23.1,<25.0"
jsonschema = "^4.17.3"
pytest-unordered = ">=0.5.2,<0.7.0"
pytest-sugar = ">=0.9.6,<1.1.0"
Expand All @@ -77,7 +76,7 @@ types-requests = "^2.28.11.7"
mypy = "^1.1"
radon = ">=5.1,<7.0"
dunamai = "^1.15.0"
ruff = ">=0.5.1,<0.9.2"
ruff = "^0.9.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed v0.9.2 is latest from 5 days ago

yardstick = {git = "https://github.com/anchore/yardstick", rev = "dd0410273860e765386bc29046cb26dd9d5fda8c"}
# yardstick = {path = "../yardstick", develop=true }
tabulate = "0.9.0"
Expand Down Expand Up @@ -123,32 +122,27 @@ exclude = '''(?x)(
| ^tests/.*$ # any tests
)'''

[tool.black]
line-length = 130
exclude = '''
(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| data
| backup
| src/vunnel/providers/mariner/model # files in here are generated
| tests/quality/vulnerability-match-labels
| tests/quality/.yardstick
| tests/quality/data
| tests/quality/build
| tests/quality/bin
)/
)
'''
[tool.ruff.format]
exclude = [
".eggs", # exclude a few common directories in the
".git", # root of the project
".hg",
".mypy_cache",
".tox",
".venv",
"_build",
"buck-out",
"build",
"dist",
"data",
"backup",
"src/vunnel/providers/mariner/model", # files in here are generated
"tests/quality/vulnerability-match-labels",
"tests/quality/.yardstick",
"tests/quality/data",
"tests/quality/build",
"tests/quality/bin",
]

[tool.coverage.run]
omit = [
Expand All @@ -172,7 +166,6 @@ dirty = true

[tool.ruff]
cache-dir = ".cache/ruff"
# allow for a wide-birth relative to what black will correct to
line-length = 150

extend-exclude = [
Expand Down
1 change: 0 additions & 1 deletion src/vunnel/providers/alpine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Config:


class Provider(provider.Provider):

__schema__ = schema.OSSchema()
__distribution_version__ = int(__schema__.major_version)

Expand Down
1 change: 0 additions & 1 deletion src/vunnel/providers/amazon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def __post_init__(self) -> None:


class Provider(provider.Provider):

__schema__ = schema.OSSchema()
__distribution_version__ = int(__schema__.major_version)

Expand Down
1 change: 0 additions & 1 deletion src/vunnel/providers/chainguard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Config:


class Provider(provider.Provider):

__schema__ = schema.OSSchema()
__distribution_version__ = int(__schema__.major_version)

Expand Down
1 change: 0 additions & 1 deletion src/vunnel/providers/debian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __post_init__(self) -> None:


class Provider(provider.Provider):

__schema__ = schema.OSSchema()
__distribution_version__ = int(__schema__.major_version)

Expand Down
18 changes: 4 additions & 14 deletions src/vunnel/providers/debian/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,7 @@ def _normalize_json(self, ns_cve_dsalist=None): # noqa: PLR0912,PLR0915,C901
else:
sev = "Unknown"

if (
sev
and vulnerability.severity_order[sev]
> vulnerability.severity_order[vuln_record["Vulnerability"]["Severity"]]
):
if sev and vulnerability.severity_order[sev] > vulnerability.severity_order[vuln_record["Vulnerability"]["Severity"]]:
vuln_record["Vulnerability"]["Severity"] = sev

# add fixedIn
Expand Down Expand Up @@ -404,22 +400,16 @@ def _normalize_json(self, ns_cve_dsalist=None): # noqa: PLR0912,PLR0915,C901
"AdvisorySummary": [{"ID": x.dsa, "Link": x.link} for x in matched_dsas],
}
# all_matched_dsas |= set([x.dsa for x in matched_dsas])
adv_mets[met_ns][met_sev]["dsa"][
"notfixed" if fixed_el["Version"] == "None" else "fixed"
] += 1
adv_mets[met_ns][met_sev]["dsa"]["notfixed" if fixed_el["Version"] == "None" else "fixed"] += 1
elif "nodsa" in distro_record:
fixed_el["VendorAdvisory"] = {"NoAdvisory": True}
adv_mets[met_ns][met_sev]["nodsa"][
"notfixed" if fixed_el["Version"] == "None" else "fixed"
] += 1
adv_mets[met_ns][met_sev]["nodsa"]["notfixed" if fixed_el["Version"] == "None" else "fixed"] += 1
else:
fixed_el["VendorAdvisory"] = {
"NoAdvisory": False,
"AdvisorySummary": [],
}
adv_mets[met_ns][met_sev]["neither"][
"notfixed" if fixed_el["Version"] == "None" else "fixed"
] += 1
adv_mets[met_ns][met_sev]["neither"]["notfixed" if fixed_el["Version"] == "None" else "fixed"] += 1

# append fixed in record to vulnerability
vuln_record["Vulnerability"]["FixedIn"].append(fixed_el)
Expand Down
1 change: 0 additions & 1 deletion src/vunnel/providers/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def __str__(self) -> str:


class Provider(provider.Provider):

__schema__ = schema.GithubSecurityAdvisorySchema()
__distribution_version__ = int(__schema__.major_version)

Expand Down
4 changes: 1 addition & 3 deletions src/vunnel/providers/github/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,7 @@ def graphql_advisories(cursor=None, timestamp=None, vuln_cursor=None):

if vuln_cursor:
vuln_after = f'after: "{vuln_cursor}", '
vulnerabilities = (
f"{vuln_after}classifications: [GENERAL, MALWARE], first: 100, orderBy: {{field: UPDATED_AT, direction: ASC}}"
)
vulnerabilities = f"{vuln_after}classifications: [GENERAL, MALWARE], first: 100, orderBy: {{field: UPDATED_AT, direction: ASC}}"

return f"""
{{
Expand Down
1 change: 0 additions & 1 deletion src/vunnel/providers/mariner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Config:


class Provider(provider.Provider):

__schema__ = schema.OSSchema()
__distribution_version__ = int(__schema__.major_version)

Expand Down
3 changes: 1 addition & 2 deletions src/vunnel/providers/nvd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def __init__(self, root: str, config: Config | None = None):

if self.config.runtime.skip_if_exists and config.runtime.existing_results != result.ResultStatePolicy.KEEP:
raise ValueError(
"if 'skip_if_exists' is set then 'runtime.existing_results' must be 'keep' "
"(otherwise incremental updates will fail)",
"if 'skip_if_exists' is set then 'runtime.existing_results' must be 'keep' (otherwise incremental updates will fail)",
)

if self.config.runtime.result_store != result.StoreStrategy.SQLITE:
Expand Down
Loading
Loading