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

Use ufmt to unify black and import sort order #515

Merged
merged 1 commit into from
Aug 26, 2021

Conversation

stroxler
Copy link
Contributor

@stroxler stroxler commented Aug 18, 2021

Summary

Use ufmt, which combines black and usort, instead of
directly relying on black and isort which conflict in their
checks.

Test Plan

ufmt format .

and also

python -m libcst.codegen.generate visitors
python -m libcst.codegen.generate matchers
python -m libcst.codegen.generate return_types

then

ufmt check .

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 18, 2021
@codecov-commenter
Copy link

Codecov Report

Merging #515 (397fd95) into master (5928f6a) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #515   +/-   ##
=======================================
  Coverage   94.73%   94.73%           
=======================================
  Files         235      235           
  Lines       23103    23103           
=======================================
  Hits        21886    21886           
  Misses       1217     1217           
Impacted Files Coverage Δ
libcst/__init__.py 91.30% <ø> (ø)
libcst/_add_slots.py 85.71% <ø> (ø)
libcst/_batched_visitor.py 94.54% <ø> (ø)
libcst/_exceptions.py 98.70% <ø> (ø)
libcst/_flatten_sentinel.py 84.61% <ø> (ø)
libcst/_metadata_dependent.py 92.30% <ø> (ø)
libcst/_nodes/base.py 95.40% <ø> (ø)
libcst/_nodes/internal.py 92.70% <ø> (ø)
libcst/_nodes/module.py 96.49% <ø> (ø)
libcst/_nodes/statement.py 96.09% <ø> (ø)
... and 57 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5928f6a...397fd95. Read the comment docs.

@amyreese
Copy link
Member

I would personally prefer switching LibCST to use µfmt, which combines black and µsort, an alternative to isort that was built on top of LibCST. This gives a single, atomic command that both sorts imports and formats sources in a consistent and stable manner, with minimal configuration.

@stroxler
Copy link
Contributor Author

@zsol thoughts on using µsort instead?

@zsol
Copy link
Member

zsol commented Aug 19, 2021

Yeah I'm with @jreese on this one

@stroxler stroxler force-pushed the isort-config-ex2 branch 2 times, most recently from 7c33ae2 to adde8cd Compare August 25, 2021 23:20
Copy link
Contributor

@thatch thatch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, in particular keeping the exact-version constraint on black.

@thatch
Copy link
Contributor

thatch commented Aug 25, 2021

I think it's missing a change to tox.ini in [testenv:lint] and [testenv:autofix]?

@stroxler
Copy link
Contributor Author

stroxler commented Aug 25, 2021

Updated to use ufmt

Still working on making CI run cleanly, I didn't realize tox.ini cared at first

Also sorted requirements-dev.txt, which it looks like we were more-or-less doing but imperfectly

@stroxler stroxler force-pushed the isort-config-ex2 branch 3 times, most recently from 389bbcd to 98a37d0 Compare August 25, 2021 23:30
@stroxler stroxler changed the title Use profile = "black" for isort config. This changes the blank lines after imports. Use ufmt to unify black and import sort order Aug 25, 2021
@stroxler
Copy link
Contributor Author

More updates:

  • update CONTRIBUTING, README, and the tutorial notebook to link to ufmt instead of isort + black
  • update codegen/generate.py to use ufmt rather than isort + black

@stroxler stroxler force-pushed the isort-config-ex2 branch 2 times, most recently from dc9fa8f to eeb419b Compare August 26, 2021 00:19
@stroxler
Copy link
Contributor Author

Looks like I also needed to regenerate some code.

which ensures we won't have inconsistent black-vs-isort errors
going forward. We can always format by running `ufmt format .`
at the root, and check with `ufmt check .` in our CI actions.
@stroxler stroxler merged commit 5e1e3fe into Instagram:master Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants