Replace black and flake8 with ruff for linting and formatting

- Remove .flake8; add [tool.ruff] and [tool.ruff.format] config in pyproject.toml
  (line-length 120, excludes, ignore list, per-file-ignores, mccabe complexity)
- Update GitHub workflow lint job to run `ruff check .` and `ruff format --check .`
- Swap black and flake8 for ruff in requirements.txt and Pipfile
- Change capnp/__init__.py to ruff-style noqa comment
- Move max-complexity into [tool.ruff.lint.mccabe], lint options into [tool.ruff.lint]
- Add per-file-ignores for capnp/__init__.py (F401, F403, F405), remove inline noqa
- Run ruff format across codebase (24 files) for consistent style
This commit is contained in:
Jacob Alexander
2026-02-25 17:24:24 -08:00
parent a27c849021
commit 162fddbcf6
30 changed files with 89 additions and 203 deletions

View File

@@ -32,7 +32,6 @@ Example Usage::
print(phone.type, ':', phone.number)
"""
# flake8: noqa F401 F403 F405
from .version import version as __version__
from .lib.capnp import *
from .lib.capnp import (

View File

@@ -21,21 +21,13 @@ def main():
code = schema_capnp.CodeGeneratorRequest.read(sys.stdin)
code = code.to_dict()
code["nodes"] = [
node for node in code["nodes"] if "struct" in node and node["scopeId"] != 0
]
code["nodes"] = [node for node in code["nodes"] if "struct" in node and node["scopeId"] != 0]
for node in code["nodes"]:
displayName = node["displayName"]
parent, path = displayName.split(":")
node["module_path"] = (
parent.replace(".", "_")
+ "."
+ ".".join([x[0].upper() + x[1:] for x in path.split(".")])
)
node["module_path"] = parent.replace(".", "_") + "." + ".".join([x[0].upper() + x[1:] for x in path.split(".")])
node["module_name"] = path.replace(".", "_")
node["c_module_path"] = "::".join(
[x[0].upper() + x[1:] for x in path.split(".")]
)
node["c_module_path"] = "::".join([x[0].upper() + x[1:] for x in path.split(".")])
node["schema"] = "_{}_Schema".format(node["module_name"])
is_union = False
for field in node["struct"]["fields"]:
@@ -63,18 +55,12 @@ def main():
filename = f["filename"].replace(".", "_") + "_cython.pyx"
file_code = dict(code)
file_code["nodes"] = [
node
for node in file_code["nodes"]
if node["displayName"].startswith(f["filename"])
]
file_code["nodes"] = [node for node in file_code["nodes"] if node["displayName"].startswith(f["filename"])]
with open(filename, "w") as out:
out.write(module.render(code=file_code, file=f, include_dir=include_dir))
setup = env.get_template("setup.py.tmpl")
with open("setup_capnp.py", "w") as out:
out.write(setup.render(code=code))
print(
"You now need to build the cython module by running `python setup_capnp.py build_ext --inplace`."
)
print("You now need to build the cython module by running `python setup_capnp.py build_ext --inplace`.")
print()