Skip to content

Add a way to choose line endings in compiled files #1448

@Jackenmen

Description

@Jackenmen

What's the problem this feature will solve?

I'm trying to use the pip-compile hook with my existing pre-commit configuration but one of the hooks I have is a mixed line ending auto-fixer (which I use to ensure all files in the repository use LF for line endings):

repos:
  - repo: https://github.com/jazzband/pip-tools
    rev: 6.2.0
    hooks:
      - id: pip-compile
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.4.0
    hooks:
      - id: mixed-line-ending
        args:
          - "--fix=lf"

This configuration causes issues whenever I try to touch a requirements file.

Describe the solution you'd like

A way to set the line endings used for the generated requirements.txt file. The alternative would be for pip-compile to always use \n but then I'm guessing someone else might complain about it in the future like I'm doing now :)

Alternative Solutions

I can work around this issue by excluding requirement files from the check but this doesn't really solve it as I still end up with requirements files ending with CRLF, it just allows me to continue to use both hooks.

Another solution would be a way for --dry-run to return non-zero exit code when the file would have any dependencies changed (like what #882 and #1215 suggest) but this doesn't fully solve it either as then you lose the benefit of pip-compile auto-fixing the issue during pre-commit run.

Additional context

I'm using on Windows - os.linesep is equal to "\r\n" there

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureRequest for a new featurewriterRelated to results output writer component

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions