Skip to content

Attempt to restore Windows functionality#20

Draft
sztomi wants to merge 1 commit into
pausan:masterfrom
sztomi:windows
Draft

Attempt to restore Windows functionality#20
sztomi wants to merge 1 commit into
pausan:masterfrom
sztomi:windows

Conversation

@sztomi

@sztomi sztomi commented Sep 2, 2022

Copy link
Copy Markdown
Contributor

The current loader magic doesn't work on Windows. There were some assumptions in the code that seemed easily fixable, but even after these changes, cblack indents to 4-spaces / doesn't reindent 4-spaces to 2-spaces. I'm pretty sure these changes are needed, but why the monkeypatching is not working goes over my head (hence the draft PR).

I can print the module names for the black modules and they are the py modules instead of the binaries. But the patches are not called.

Comment thread cblack.py
# local installation of black folder don't necessarily need to contain the
# version, so the path includes '/black/'
_black_local_folder = "/black/"
_black_folder_patterns = (

@sztomi sztomi Sep 2, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Paths on windows are usually represented with backslashes, so hardcoding the forward slash (even though it is supported on Windows) will filter out the actual module names for black.

Comment thread cblack.py
""" """
spec = _real_pathfinder.find_spec(fullname, path)
if not spec:
return spec

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's OK to short-circuit here because if spec were None, the remaining code would not run.

Comment thread cblack.py
(CBlackModuleLoader._black_folder in spec.origin)
or (CBlackModuleLoader._black_local_folder in spec.origin)
)
and spec.origin.endswith(".so")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hardcoding this extension will filter out Windows dynamic modules (which are usually .pyd, but sometimes .dll). But it also doesn't matter if we filter here, because later it filters on importlib.machinery.EXTENSION_SUFFIXES

Comment thread cblack.py
or (CBlackModuleLoader._black_local_folder in spec.origin)
)
and spec.origin.endswith(".so")
Path(spec.origin).parent.name in CBlackModuleLoader._black_folder_patterns

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rather than looking for an exact string match in the full path string, lean on pathlib to parse the path and check the parent folder name.

Comment thread cblack.py
__version__ = "22.6.0"

import sys
from os.path import isdir

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This import was unused

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant