Skip to content

Commit

Permalink
Add Ruff and mypy configuration files (#283)
Browse files Browse the repository at this point in the history
## Summary

I think it's useful that running `ruff check` or `mypy` enforces the configuration we enforce in CI.
  • Loading branch information
charliermarsh authored Jul 22, 2024
1 parent aec9cbf commit dfc282c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
14 changes: 2 additions & 12 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,9 @@ def run():
)
args = parser.parse_args()

# Lints:
# Sort imports
# Unused import
# Unused variable
check_args = ["--select", "I,F401,F841"]
check_args = []
format_args = []
mypy_args = [
"pythonbuild",
"check.py",
"build-linux.py",
"build-macos.py",
"build-windows.py",
]
mypy_args = []

if args.fix:
check_args.append("--fix")
Expand Down
9 changes: 9 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[mypy]
warn_no_return = True
warn_redundant_casts = True
warn_return_any = True
warn_unused_configs = True
warn_unused_ignores = True
warn_unreachable = True

files = pythonbuild,check.py,build-linux.py,build-macos.py,build-windows.py
12 changes: 5 additions & 7 deletions pythonbuild/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def supported_targets(yaml_path: pathlib.Path):
targets = set()

for target, settings in get_targets(yaml_path).items():
for platform in settings["host_platforms"]:
if sys.platform == "linux" and platform == "linux64":
for host_platform in settings["host_platforms"]:
if sys.platform == "linux" and host_platform == "linux64":
targets.add(target)
elif sys.platform == "darwin" and platform == "macos":
elif sys.platform == "darwin" and host_platform == "macos":
targets.add(target)

return targets
Expand Down Expand Up @@ -305,9 +305,7 @@ def download_entry(key: str, dest_path: pathlib.Path, local_name=None) -> pathli
assert isinstance(size, int)
assert isinstance(sha256, str)

local_name = local_name or url[url.rindex("/") + 1 :]

local_path = dest_path / local_name
local_path = dest_path / (local_name or url[url.rindex("/") + 1 :])
download_to_path(url, local_path, size, sha256)

return local_path
Expand Down Expand Up @@ -466,7 +464,7 @@ def add_licenses_to_extension_entry(entry):
if "path_static" in link or "path_dynamic" in link:
have_local_link = True

for key, value in DOWNLOADS.items():
for value in DOWNLOADS.values():
if name not in value.get("library_names", []):
continue

Expand Down
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[lint]
select = ["F", "I", "B"]

0 comments on commit dfc282c

Please sign in to comment.