Skip to content

Commit

Permalink
Remove regex dependency (GH-2663)
Browse files Browse the repository at this point in the history
We were no longer using it since GH-2644 and GH-2654. This should hopefully
make using Black easier to use as there's one less compiled dependency.
The core team also doesn't have to deal with the surprisingly frequent fires
the regex packaging setup goes through.

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
  • Loading branch information
JelleZijlstra and ichard26 committed Dec 2, 2021
1 parent 20d7ae0 commit bd9d52b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 131 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Expand Up @@ -8,7 +8,7 @@
cell magics were tokenized, leading to possible indentation errors e.g. with
`%%writefile`. (#2630)
- Fix Python 3.10 support on platforms without ProcessPoolExecutor (#2631)
- Reduce usage of the `regex` dependency (#2644)
- Remove dependency on `regex` (#2644) (#2663)
- Fix `match` statements with open sequence subjects, like `match a, b:` or
`match a, *b:` (#2639) (#2659)
- Fix `match`/`case` statements that contain `match`/`case` soft keywords multiple
Expand Down
1 change: 0 additions & 1 deletion Pipfile
Expand Up @@ -42,7 +42,6 @@ platformdirs= ">=2"
click = ">=8.0.0"
mypy_extensions = ">=0.4.3"
pathspec = ">=0.8.1"
regex = ">=2021.4.4"
tomli = ">=0.2.6, <2.0.0"
typed-ast = "==1.4.3"
typing_extensions = {markers = "python_version < '3.10'", version = ">=3.10.0.0"}
Expand Down
112 changes: 1 addition & 111 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 13 additions & 15 deletions docs/integrations/editors.md
Expand Up @@ -204,30 +204,28 @@ Traceback (most recent call last):
ImportError: /home/gui/.vim/black/lib/python3.7/site-packages/typed_ast/_ast3.cpython-37m-x86_64-linux-gnu.so: undefined symbool: PyExc_KeyboardInterrupt
```

Then you need to install `typed_ast` and `regex` directly from the source code. The
error happens because `pip` will download [Python wheels](https://pythonwheels.com/) if
they are available. Python wheels are a new standard of distributing Python packages and
packages that have Cython and extensions written in C are already compiled, so the
installation is much more faster. The problem here is that somehow the Python
environment inside Vim does not match with those already compiled C extensions and these
kind of errors are the result. Luckily there is an easy fix: installing the packages
from the source code.

The two packages that cause the problem are:

- [regex](https://pypi.org/project/regex/)
Then you need to install `typed_ast` directly from the source code. The error happens
because `pip` will download [Python wheels](https://pythonwheels.com/) if they are
available. Python wheels are a new standard of distributing Python packages and packages
that have Cython and extensions written in C are already compiled, so the installation
is much more faster. The problem here is that somehow the Python environment inside Vim
does not match with those already compiled C extensions and these kind of errors are the
result. Luckily there is an easy fix: installing the packages from the source code.

The package that causes problems is:

- [typed-ast](https://pypi.org/project/typed-ast/)

Now remove those two packages:

```console
$ pip uninstall regex typed-ast -y
$ pip uninstall typed-ast -y
```

And now you can install them with:

```console
$ pip install --no-binary :all: regex typed-ast
$ pip install --no-binary :all: typed-ast
```

The C extensions will be compiled and now Vim's Python environment will match. Note that
Expand All @@ -237,7 +235,7 @@ Ubuntu/Debian do `sudo apt-get install build-essential python3-dev`).
If you later want to update _Black_, you should do it like this:

```console
$ pip install -U black --no-binary regex,typed-ast
$ pip install -U black --no-binary typed-ast
```

### With ALE
Expand Down
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -101,7 +101,6 @@ def find_python_files(base: Path) -> List[Path]:
"platformdirs>=2",
"tomli>=0.2.6,<2.0.0",
"typed-ast>=1.4.2; python_version < '3.8' and implementation_name == 'cpython'",
"regex>=2021.4.4",
"pathspec>=0.9.0, <1",
"dataclasses>=0.6; python_version < '3.7'",
"typing_extensions>=3.10.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/black/trans.py
Expand Up @@ -4,7 +4,7 @@
from abc import ABC, abstractmethod
from collections import defaultdict
from dataclasses import dataclass
import regex as re # We need recursive patterns here (?R)
import re
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -453,7 +453,7 @@ def make_naked(string: str, string_prefix: str) -> str:
# with 'f'...
if "f" in prefix and "f" not in next_prefix:
# Then we must escape any braces contained in this substring.
SS = re.subf(r"(\{|\})", "{1}{1}", SS)
SS = re.sub(r"(\{|\})", r"\1\1", SS)

NSS = make_naked(SS, next_prefix)

Expand Down

0 comments on commit bd9d52b

Please sign in to comment.