Skip to content

Commit

Permalink
Merge pull request #612 from akaihola/path-resolve-bug-win-py38-py39
Browse files Browse the repository at this point in the history
Work around `Path.resolve` bug in Windows py38/py39
  • Loading branch information
akaihola authored Sep 15, 2024
2 parents e98d2f9 + b60ff62 commit 77ee2fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Fixed
- Pass Graylint version to `~darkgraylib.command_line.make_argument_parser` to make
``--version`` display the correct version number.
- Pass full environment to Git to avoid the "dubious ownership" error.
- Work around a `pathlib.Path.resolve` bug in Python 3.8 and 3.9 on Windows.
The work-around should be removed when Python 3.8 and 3.9 are no longer supported.


2.1.1_ - 2024-04-16
Expand Down
15 changes: 12 additions & 3 deletions src/darker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from darkgraylib.highlighting import colorize, should_use_color
from darkgraylib.log import setup_logging
from darkgraylib.main import resolve_paths
from darkgraylib.utils import GIT_DATEFORMAT, DiffChunk, TextDocument
from darkgraylib.utils import GIT_DATEFORMAT, WINDOWS, DiffChunk, TextDocument
from graylint.linting import run_linters

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -561,9 +561,18 @@ def main( # noqa: C901,PLR0912,PLR0915
msg = f"Path(s) {missing_reprs} do not exist in {rev2_repr}"
raise FileNotFoundError(msg)

common_root_ = (
# On Windows, Python <= 3.9 requires the `filter_python_files` `root` argument
# to be an absolute path. Remove this after dropping support for Python 3.9.
# See https://github.com/python/cpython/issues/82852
common_root.resolve()
if WINDOWS and sys.version_info < (3, 10)
else common_root
)
# These paths are relative to `common_root`:
files_to_process = filter_python_files(paths, common_root, {})
files_to_blacken = filter_python_files(paths, common_root, black_config)
files_to_process = filter_python_files(paths, common_root_, {})
files_to_blacken = filter_python_files(paths, common_root_, black_config)

# Now decide which files to reformat (Black & isort). Note that this doesn't apply
# to linting.
if output_mode == OutputMode.CONTENT or revrange.rev2 == STDIN:
Expand Down

0 comments on commit 77ee2fb

Please sign in to comment.