Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
justinchuby committed Oct 17, 2023
1 parent 2ee032b commit 2bdef99
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions lintrunner_adapters/adapters/requirements_txt_linter.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
from __future__ import annotations

import argparse
import concurrent.futures
import logging
import os
import re
import sys
from typing import IO
import concurrent.futures

from lintrunner_adapters import (
LintMessage,
LintSeverity,
add_default_options,
)

from lintrunner_adapters import LintMessage, LintSeverity, add_default_options

LINTER_CODE = "REQUIREMENTS-TXT"

Expand Down Expand Up @@ -79,7 +74,7 @@ def fix_requirements(f: IO[bytes]) -> bytes:

# If the file is empty (i.e. only whitespace/newlines) exit early
if before_string.strip() == b"":
return PASS
return before_string

for line in before:
# If the most recent requirement object has a value, then it's
Expand All @@ -103,10 +98,7 @@ def fix_requirements(f: IO[bytes]) -> bytes:
requirement.append_value(line)

# if a file ends in a comment, preserve it at the end
if requirements[-1].value is None:
rest = requirements.pop().comments
else:
rest = []
rest = requirements.pop().comments if requirements[-1].value is None else []

# find and remove pkg-resources==0.0.0
# which is automatically added by broken pip package under Debian
Expand All @@ -125,9 +117,7 @@ def fix_requirements(f: IO[bytes]) -> bytes:
return after_string


def check_file(
filename: str
) -> list[LintMessage]:
def check_file(filename: str) -> list[LintMessage]:
with open(filename, "rb") as f:
original = f.read()
with open(filename, "rb") as f:
Expand All @@ -150,6 +140,7 @@ def check_file(
)
]


def main() -> None:
parser = argparse.ArgumentParser(
description=f"add-trailing-comma wrapper linter. Linter code: {LINTER_CODE}",
Expand All @@ -172,10 +163,7 @@ def main() -> None:
max_workers=os.cpu_count(),
thread_name_prefix="Thread",
) as executor:
futures = {
executor.submit(check_file, x): x
for x in args.filenames
}
futures = {executor.submit(check_file, x): x for x in args.filenames}
for future in concurrent.futures.as_completed(futures):
try:
for lint_message in future.result():
Expand Down

0 comments on commit 2bdef99

Please sign in to comment.