pipreqs icon indicating copy to clipboard operation
pipreqs copied to clipboard

Alphabetically ordered output flag

Open PatMyron opened this issue 6 years ago • 2 comments

Requesting a flag to generate requirements.txt in deterministic order for easier reviews / diffs

https://github.com/bndr/pipreqs/issues/133

PatMyron avatar Apr 30 '19 01:04 PatMyron

+1. Is it furthermore feasible to make that a default?

katrinleinweber avatar Jul 16 '19 12:07 katrinleinweber

First, it would be good to add the word 'sort' somewhere in the title of this issue so it's easier to find. I wanted to raise the same thing because it's a pain to have complex diffs when committing requirements.txt updates to repos.

To do this, I think all that's needed is in pipreqs/pipreqs.py generate_requirements_file() the file write could become:

output_lines = sorted([fmt.format(**item) if item['version'] else '{name}'.format(**item) for item in imports]) out_file.write('\n'.join(output_lines) + '\n')

If there's currently no defined behaviour for the order, I'd avoid making it an option, seems like unnecessary complexity.

Obviously you'd also need to write a test and update the docs.

isaacnorman82 avatar Apr 14 '20 16:04 isaacnorman82