-
Notifications
You must be signed in to change notification settings - Fork 10
Attempt to restore Windows functionality #20
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| __version__ = "22.6.0" | ||
|
|
||
| import sys | ||
| from os.path import isdir | ||
| from pathlib import Path | ||
|
|
||
| import importlib | ||
| import importlib.util | ||
|
|
@@ -31,25 +31,24 @@ class CBlackModuleLoader(type(_real_pathfinder)): | |
| https://stupidpythonideas.blogspot.com/2015/06/hacking-python-without-hacking-python.html | ||
| """ | ||
|
|
||
| # all "black" folders contain the substring "/black-<version>" | ||
| # (e.g "/usr/local/lib/python3.8/site-packages/black-22.3.0-py3.8-linux-x86_64.egg") | ||
| _black_folder = "/black-%s" % __version__ | ||
|
|
||
| # 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 = ( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| # all "black" folders contain the substring "/black-<version>" | ||
| # (e.g "/usr/local/lib/python3.8/site-packages/black-22.3.0-py3.8-linux-x86_64.egg") | ||
| "black-%s" % __version__, | ||
| # local installation of black folder don't necessarily need to contain the | ||
| # version, so the path includes '/black/' | ||
| "black", | ||
| ) | ||
|
|
||
| @classmethod | ||
| def find_module(cls, fullname, path=None): | ||
| """ """ | ||
| spec = _real_pathfinder.find_spec(fullname, path) | ||
| if not spec: | ||
| return spec | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| if ( | ||
| spec | ||
| and ( | ||
| (CBlackModuleLoader._black_folder in spec.origin) | ||
| or (CBlackModuleLoader._black_local_folder in spec.origin) | ||
| ) | ||
| and spec.origin.endswith(".so") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| Path(spec.origin).parent.name in CBlackModuleLoader._black_folder_patterns | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ): | ||
| # replace known dynamic loader module extensions by their "py" counterpart | ||
| location = spec.origin | ||
|
|
@@ -61,8 +60,6 @@ def find_module(cls, fullname, path=None): | |
| # load & replace the spec from the python file | ||
| spec = importlib.util.spec_from_file_location(spec.name, location) | ||
|
|
||
| if not spec: | ||
| return spec | ||
| return spec.loader | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import was unused