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

remove regex dependency #2663

Merged
merged 6 commits into from Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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",
Copy link
Collaborator

Choose a reason for hiding this comment

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

So nice.

"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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will never have unicode to match right so we should be safe ... :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As far as I can tell the missing unicode support is just about character classes, so some "word" characters don't match \w in re but do in regex. That doesn't apply here.


NSS = make_naked(SS, next_prefix)

Expand Down