Skip to content

Commit

Permalink
Add autoflake to Python formatting (#281)
Browse files Browse the repository at this point in the history
Fixes #280
  • Loading branch information
calcmogul committed Jul 20, 2024
1 parent 7e8f8b2 commit ed9e8b4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions wpiformat/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description = "Linters and formatters for ensuring WPILib's source code conforms
dynamic = [ "version" ]
readme = "README.rst"
dependencies = [
"autoflake==2.3.1",
"black==24.3.0",
"clang-format==18.1.1",
"clang-tidy==18.1.1",
Expand Down
1 change: 0 additions & 1 deletion wpiformat/wpiformat/licenseupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import regex
import subprocess
import sys

from wpiformat.config import Config
from wpiformat.task import PipelineTask
Expand Down
6 changes: 0 additions & 6 deletions wpiformat/wpiformat/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
required it to be used as a module.
"""

import os
import sys

from wpiformat import cpplint
Expand All @@ -22,11 +21,6 @@ def should_process_file(config_file, name):

@staticmethod
def run_batch(config_file, names):
# Handle running in either the root or styleguide directories
cpplintPrefix = ""
if os.getcwd().rpartition(os.sep)[2] != "styleguide":
cpplintPrefix = "styleguide/"

# Prepare arguments to cpplint.py
saved_argv = sys.argv

Expand Down
18 changes: 18 additions & 0 deletions wpiformat/wpiformat/pyformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,28 @@ def should_process_file(config_file, name):

@staticmethod
def run_batch(config_file, names):
try:
args = [
sys.executable,
"-m",
"autoflake",
"--remove-all-unused-imports",
"--remove-unused-variables",
"--quiet",
"-i",
]
subprocess.run(args + names)
except FileNotFoundError:
print(
"Error: autoflake not found in PATH. Is it installed?", file=sys.stderr
)
return False

try:
args = [sys.executable, "-m", "black", "-q"]
subprocess.run(args + names)
except FileNotFoundError:
print("Error: black not found in PATH. Is it installed?", file=sys.stderr)
return False

return True
2 changes: 0 additions & 2 deletions wpiformat/wpiformat/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,6 @@ def func_substitute(header, lines):
"""
pos = 0
while pos < len(lines):
old_length = len(lines)

# Check for function starting at "pos"
match = header.func_regex.search(lines, pos)
if not match:
Expand Down
1 change: 0 additions & 1 deletion wpiformat/wpiformat/test/test_licenseupdate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import date
import os
from pathlib import Path
import shutil
import subprocess
import tempfile

Expand Down
2 changes: 0 additions & 2 deletions wpiformat/wpiformat/test/test_usingdeclaration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import io
import os
import sys

from .test_tasktest import *
from wpiformat.usingdeclaration import UsingDeclaration
Expand Down
2 changes: 0 additions & 2 deletions wpiformat/wpiformat/whitespace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""This task removes trailing whitespace from the file."""

import os

from wpiformat.task import PipelineTask


Expand Down

0 comments on commit ed9e8b4

Please sign in to comment.