# Path: pre_commit_hooks/requirements_txt_fixer.py
# FAIL = 1
# 
# Path: pre_commit_hooks/requirements_txt_fixer.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument('filenames', nargs='*', help='Filenames to fix')
#     args = parser.parse_args(argv)
# 
#     retv = PASS
# 
#     for arg in args.filenames:
#         with open(arg, 'rb+') as file_obj:
#             ret_for_file = fix_requirements(file_obj)
# 
#             if ret_for_file:
#                 print(f'Sorting {arg}')
# 
#             retv |= ret_for_file
# 
#     return retv
# 
# Path: pre_commit_hooks/requirements_txt_fixer.py
# PASS = 0
# 
# Path: pre_commit_hooks/requirements_txt_fixer.py
# class Requirement:
#     UNTIL_COMPARISON = re.compile(b'={2,3}|!=|~=|>=?|<=?')
#     UNTIL_SEP = re.compile(rb'[^;\s]+')
# 
#     def __init__(self) -> None:
#         self.value: bytes | None = None
#         self.comments: list[bytes] = []
# 
#     @property
#     def name(self) -> bytes:
#         assert self.value is not None, self.value
#         name = self.value.lower()
#         for egg in (b'#egg=', b'&egg='):
#             if egg in self.value:
#                 return name.partition(egg)[-1]
# 
#         m = self.UNTIL_SEP.match(name)
#         assert m is not None
# 
#         name = m.group()
#         m = self.UNTIL_COMPARISON.search(name)
#         if not m:
#             return name
# 
#         return name[:m.start()]
# 
#     def __lt__(self, requirement: Requirement) -> bool:
#         # \n means top of file comment, so always return True,
#         # otherwise just do a string comparison with value.
#         assert self.value is not None, self.value
#         if self.value == b'\n':
#             return True
#         elif requirement.value == b'\n':
#             return False
#         else:
#             return self.name < requirement.name
# 
#     def is_complete(self) -> bool:
#         return (
#             self.value is not None and
#             not self.value.rstrip(b'\r\n').endswith(b'\\')
#         )
# 
#     def append_value(self, value: bytes) -> None:
#         if self.value is not None:
#             self.value += value
#         else:
#             self.value = value


import pytest
from pre_commit_hooks.requirements_txt_fixer import FAIL
from pre_commit_hooks.requirements_txt_fixer import main
from pre_commit_hooks.requirements_txt_fixer import PASS
from pre_commit_hooks.requirements_txt_fixer import Requirement
        (b'foo\npkg-resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
        (
            b'git+ssh://git_url@tag#egg=ocflib\nDjango\nijk\n',
            FAIL,
            b'Django\nijk\ngit+ssh://git_url@tag#egg=ocflib\n',
        ),
        (
            b'b==1.0.0\n'
            b'c=2.0.0 \\\n'
            b' --hash=sha256:abcd\n'
            b'a=3.0.0 \\\n'
            b'  --hash=sha256:a1b1c1d1',
            FAIL,
            b'a=3.0.0 \\\n'
            b'  --hash=sha256:a1b1c1d1\n'
            b'b==1.0.0\n'
            b'c=2.0.0 \\\n'
            b' --hash=sha256:abcd\n',
        ),
        (
            b'a=2.0.0 \\\n --hash=sha256:abcd\nb==1.0.0\n',
            PASS,
            b'a=2.0.0 \\\n --hash=sha256:abcd\nb==1.0.0\n',
        ),
    ),
)
def test_integration(input_s, expected_retval, output, tmpdir):
    path = tmpdir.join('file.txt')
    path.write_binary(input_s)


# Path: pre_commit_hooks/requirements_txt_fixer.py
# FAIL = 1
# 
# Path: pre_commit_hooks/requirements_txt_fixer.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument('filenames', nargs='*', help='Filenames to fix')
#     args = parser.parse_args(argv)
# 
#     retv = PASS
# 
#     for arg in args.filenames:
#         with open(arg, 'rb+') as file_obj:
#             ret_for_file = fix_requirements(file_obj)
# 
#             if ret_for_file:
#                 print(f'Sorting {arg}')
# 
#             retv |= ret_for_file
# 
#     return retv
# 
# Path: pre_commit_hooks/requirements_txt_fixer.py
# PASS = 0
# 
# Path: pre_commit_hooks/requirements_txt_fixer.py
# class Requirement:
#     UNTIL_COMPARISON = re.compile(b'={2,3}|!=|~=|>=?|<=?')
#     UNTIL_SEP = re.compile(rb'[^;\s]+')
# 
#     def __init__(self) -> None:
#         self.value: bytes | None = None
#         self.comments: list[bytes] = []
# 
#     @property
#     def name(self) -> bytes:
#         assert self.value is not None, self.value
#         name = self.value.lower()
#         for egg in (b'#egg=', b'&egg='):
#             if egg in self.value:
#                 return name.partition(egg)[-1]
# 
#         m = self.UNTIL_SEP.match(name)
#         assert m is not None
# 
#         name = m.group()
#         m = self.UNTIL_COMPARISON.search(name)
#         if not m:
#             return name
# 
#         return name[:m.start()]
# 
#     def __lt__(self, requirement: Requirement) -> bool:
#         # \n means top of file comment, so always return True,
#         # otherwise just do a string comparison with value.
#         assert self.value is not None, self.value
#         if self.value == b'\n':
#             return True
#         elif requirement.value == b'\n':
#             return False
#         else:
#             return self.name < requirement.name
# 
#     def is_complete(self) -> bool:
#         return (
#             self.value is not None and
#             not self.value.rstrip(b'\r\n').endswith(b'\\')
#         )
# 
#     def append_value(self, value: bytes) -> None:
#         if self.value is not None:
#             self.value += value
#         else:
#             self.value = value


# Path: tests/requirements_txt_fixer_test.py
import pytest
from pre_commit_hooks.requirements_txt_fixer import FAIL
from pre_commit_hooks.requirements_txt_fixer import main
from pre_commit_hooks.requirements_txt_fixer import PASS
from pre_commit_hooks.requirements_txt_fixer import Requirement

        (b'foo\npkg-resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
        (
            b'git+ssh://git_url@tag#egg=ocflib\nDjango\nijk\n',
            FAIL,
            b'Django\nijk\ngit+ssh://git_url@tag#egg=ocflib\n',
        ),
        (
            b'b==1.0.0\n'
            b'c=2.0.0 \\\n'
            b' --hash=sha256:abcd\n'
            b'a=3.0.0 \\\n'
            b'  --hash=sha256:a1b1c1d1',
            FAIL,
            b'a=3.0.0 \\\n'
            b'  --hash=sha256:a1b1c1d1\n'
            b'b==1.0.0\n'
            b'c=2.0.0 \\\n'
            b' --hash=sha256:abcd\n',
        ),
        (
            b'a=2.0.0 \\\n --hash=sha256:abcd\nb==1.0.0\n',
            PASS,
            b'a=2.0.0 \\\n --hash=sha256:abcd\nb==1.0.0\n',
        ),
    ),
)
def test_integration(input_s, expected_retval, output, tmpdir):
    path = tmpdir.join('file.txt')
    path.write_binary(input_s)


    output_retval = main([str(path)])