Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --isort --diff #11

Merged
merged 2 commits into from
Jul 3, 2020
Merged

Allow --isort --diff #11

merged 2 commits into from
Jul 3, 2020

Conversation

akaihola
Copy link
Owner

@akaihola akaihola commented Jul 1, 2020

This is a largish refactoring which was necessary in order to support --isort together with the new --diff option.

The patch ditches the original approach in which git diff was used to get the changes between HEAD and the worktree for all requested files in one go, and the output was parsed into a list of changed line numbers for each file.

Instead, the HEAD, worktree and (optionally) isorted versions of the file are read/generated in Python and compared against each other.

This required quite a bit of changes, and as I did them I also structured the code a bit better into descriptive modules, and did some clean-up.

This should be merged only after #4.

If this turns out too massive for review, I can try to split it up into smaller PRs – it's just that those interim steps will look a bit silly without knowing the ultimate motivation.

The main changes are:

  • --isort and --diff now work together
  • diff original unmodified and user-edited versions of files in the Git directory using Python's difflib, not by parsing git diff output
  • process each edited file individually
  • only run isort for edited files
  • write back isort modifications together with black modifications, and skip writing if there are errors
  • remove code that became unused
  • avoid extra conversions between source code as a string and a list of line strings
  • add some tests for previously untested functions

@akaihola akaihola changed the base branch from master to diff-flag July 1, 2020 21:39
@akaihola akaihola changed the base branch from diff-flag to master July 1, 2020 21:42
@akaihola akaihola changed the base branch from master to diff-flag July 1, 2020 21:42
- `--isort` and `--diff` now work together
- diff original unmodified and user-edited versions of files in the
  Git directory using Python's difflib, not by parsing `git diff`
  output
- process each edited file individually
- only run `isort` for edited files
- write back `isort` modifications together with `black`
  modifications, and skip writing if there are errors
- remove code that became unused
- avoid extra conversions between source code as a string and a list
  of line strings
- add some tests for previously untested functions
@akaihola akaihola merged commit ad45309 into diff-flag Jul 3, 2020
@akaihola akaihola deleted the isort-diff branch July 3, 2020 15:34
@akaihola akaihola mentioned this pull request Jul 8, 2020
@akaihola akaihola added this to the 1.0.0 milestone Jul 11, 2020
@akaihola akaihola added the enhancement New feature or request label Jul 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants