Attempt to restore Windows functionality#20
Conversation
| # 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 = ( |
There was a problem hiding this comment.
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.
| """ """ | ||
| spec = _real_pathfinder.find_spec(fullname, path) | ||
| if not spec: | ||
| return spec |
There was a problem hiding this comment.
it's OK to short-circuit here because if spec were None, the remaining code would not run.
| (CBlackModuleLoader._black_folder in spec.origin) | ||
| or (CBlackModuleLoader._black_local_folder in spec.origin) | ||
| ) | ||
| and spec.origin.endswith(".so") |
There was a problem hiding this comment.
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
| or (CBlackModuleLoader._black_local_folder in spec.origin) | ||
| ) | ||
| and spec.origin.endswith(".so") | ||
| Path(spec.origin).parent.name in CBlackModuleLoader._black_folder_patterns |
There was a problem hiding this comment.
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.
| __version__ = "22.6.0" | ||
|
|
||
| import sys | ||
| from os.path import isdir |
There was a problem hiding this comment.
This import was unused
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.