fix 1631 and add test (#1641)
This commit is contained in:
parent
7fe19fac5b
commit
2b75f8870e
@ -7,6 +7,8 @@
|
|||||||
- `Black` now respects `--skip-string-normalization` when normalizing multiline
|
- `Black` now respects `--skip-string-normalization` when normalizing multiline
|
||||||
docstring quotes (#1637)
|
docstring quotes (#1637)
|
||||||
|
|
||||||
|
- fixed a crash when PWD=/ on POSIX (#1631)
|
||||||
|
|
||||||
### 20.8b1
|
### 20.8b1
|
||||||
|
|
||||||
#### _Packaging_
|
#### _Packaging_
|
||||||
|
@ -5831,7 +5831,8 @@ def normalize_path_maybe_ignore(
|
|||||||
`report` is where "path ignored" output goes.
|
`report` is where "path ignored" output goes.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
normalized_path = path.resolve().relative_to(root).as_posix()
|
abspath = path if path.is_absolute() else Path.cwd() / path
|
||||||
|
normalized_path = abspath.resolve().relative_to(root).as_posix()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
report.path_ignored(path, f"cannot be read because {e}")
|
report.path_ignored(path, f"cannot be read because {e}")
|
||||||
return None
|
return None
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
from io import BytesIO, TextIOWrapper
|
from io import BytesIO, TextIOWrapper
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from platform import system
|
||||||
import regex as re
|
import regex as re
|
||||||
import sys
|
import sys
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
@ -1939,6 +1940,23 @@ def test_find_project_root(self) -> None:
|
|||||||
self.assertEqual(black.find_project_root((src_dir,)), src_dir.resolve())
|
self.assertEqual(black.find_project_root((src_dir,)), src_dir.resolve())
|
||||||
self.assertEqual(black.find_project_root((src_python,)), src_dir.resolve())
|
self.assertEqual(black.find_project_root((src_python,)), src_dir.resolve())
|
||||||
|
|
||||||
|
def test_bpo_33660_workaround(self) -> None:
|
||||||
|
if system() == "Windows":
|
||||||
|
return
|
||||||
|
|
||||||
|
# https://bugs.python.org/issue33660
|
||||||
|
|
||||||
|
old_cwd = Path.cwd()
|
||||||
|
try:
|
||||||
|
root = Path("/")
|
||||||
|
os.chdir(str(root))
|
||||||
|
path = Path("workspace") / "project"
|
||||||
|
report = black.Report(verbose=True)
|
||||||
|
normalized_path = black.normalize_path_maybe_ignore(path, root, report)
|
||||||
|
self.assertEqual(normalized_path, "workspace/project")
|
||||||
|
finally:
|
||||||
|
os.chdir(str(old_cwd))
|
||||||
|
|
||||||
|
|
||||||
class BlackDTestCase(AioHTTPTestCase):
|
class BlackDTestCase(AioHTTPTestCase):
|
||||||
async def get_application(self) -> web.Application:
|
async def get_application(self) -> web.Application:
|
||||||
|
Loading…
Reference in New Issue
Block a user