Commit Graph

12 Commits

Author SHA1 Message Date
Hong Minhee (洪 民憙)
ef6e079901
Let string splitters respect East_Asian_Width property (#3445)
This patch changes the preview style so that string splitters respect
Unicode East Asian Width[^1] property.  If you are not familiar to CJK
languages it is not clear immediately.  Let me elaborate with some
examples.

Traditionally, East Asian characters (including punctuation) have
taken up space twice than European letters and stops when they are
rendered in monospace typeset.  Compare the following characters:

```
abcdefg.
글、字。
```

The characters at the first line are half-width, and the second line
are full-width.  (Also note that the last character with a small
circle, the East Asian period, is also full-width.)  Therefore, if we
want to prevent those full-width characters to exceed the maximum
columns per line, we need to count their *width* rather than the number
of characters.  Again, the following characters:

```
글、字。
```

These are just 4 characters, but their total width is 8.

Suppose we want to maintain up to 4 columns per line with the following
text:

```
abcdefg.
글、字。
```

How should it be then?  We want it to look like:

```
abcd
efg.
글、
字。
```

However, Black currently turns it into like this:

```
abcd
efg.
글、字。
```

It's because Black currently counts the number of characters in the line
instead of measuring their width. So, how could we measure the width?
How can we tell if a character is full- or half-width? What if half-width
characters and full-width ones are mixed in a line? That's why Unicode
defined an attribute named `East_Asian_Width`. Unicode grouped every
single character according to their width in fixed-width typeset.

This partially addresses #1197, but only for string splitters. The other
parts need to be fixed as well in future patches.

This was implemented by copying rich's own approach to handling wide
characters: generate a table using wcwidth, check it into source
control, and use in to drive helper functions in Black's logic. This
gets us the best of both worlds: accuracy and performance (and let's us
update as per our stability policy too!).

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-03-19 19:09:57 -04:00
Holger Brunn
72a25591b0
[FIX] migrate-black.py: don't fail on binary files (#3266) 2022-09-13 20:06:54 -07:00
Shantanu
2c90480e1a
Use strict mypy checking (#3222)
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2022-08-30 20:46:46 -07:00
Richard Si
ca0dbb8fa6
Move fuzz.py to scripts/ (#3199) 2022-07-31 07:34:29 -07:00
Richard Si
44d5da00b5 Reformat codebase with isort 2022-07-27 17:19:28 -04:00
Vivek Vashist
f51e53726b
Fix minor typo (#3096) 2022-06-03 15:59:26 -07:00
Holger Brunn
436e12f290
Add script to ease migration to black (#3038)
* Add script to ease migration to black

* Update CHANGES.md

Co-authored-by: Cooper Lees <me@cooperlees.com>
2022-06-01 11:20:02 -07:00
Richard Si
f239d227c0
Enforce no formatting changes for PRs via CI (GH-2951)
Now PRs will run two diff-shades jobs, "preview-changes" which formats
all projects with preview=True, and "assert-no-changes" which formats
all projects with preview=False. The latter also fails if any changes
were made.

Pushes to main will only run "preview-changes"

Also the workflow_dispatch feature was dropped since it was
complicating everything for little gain.
2022-03-26 17:22:38 -04:00
Richard Si
9bd4134f31
Fix and speedup diff-shades integration (#2773) 2022-01-19 19:05:58 -08:00
Richard Si
565f9c92b7
CI: add diff-shades integration (#2725)
Hopefully this makes it much easier to gauge the impacts of future
changes!
2022-01-13 18:50:02 -08:00
Marco Edward Gorelli
0540591e25
add check for version in the-basics example (#2459) 2021-09-18 20:24:09 -07:00
Marco Edward Gorelli
8b06805334
Document jupyter hook (#2416)
This also introduces a script so we can reference the latest version in
the example pre-commit configuration in the docs without forgetting to
update it when doing a release!

Commit history before merge:

* document jupyter hook
* note minimum version
* add check for pre-commit version
* use git tag
* curl api during ci
* parse version from changes file
* fixup script
* rename variables
* Tweak the docs & magical script
* fix couple of typos
* pin additional dependencies in hook
* Add types-PyYAML to lockfile

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2021-08-27 16:21:08 -04:00