-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: handle OSError importing cairosvg to avoid build crash because of missing system dependencies #6818
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
Merged
Merged
fix: handle OSError importing cairosvg to avoid build crash because of missing system dependencies #6818
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import inspect | ||
import os | ||
import shutil | ||
import subprocess | ||
from ctypes import util | ||
|
||
|
||
class CustomPopen(subprocess.Popen): | ||
|
||
def __init__(self, *args, **kwargs): | ||
print(f"Subprocess command:\n {' '.join(args[0])}") | ||
super().__init__(*args, **kwargs) | ||
|
||
def communicate(self, *args, **kwargs): | ||
out, _ = super().communicate(*args, **kwargs) | ||
out = out.rstrip() | ||
print("Subprocess output:") | ||
if out: | ||
print(f" {os.fsdecode(out)}") | ||
else: | ||
print(f" Output is empty") | ||
return out, _ | ||
|
||
def __getattribute__(self, name_): | ||
att = super().__getattribute__(name_) | ||
if name_ == "stdout" and att is not None: | ||
att.read = self.read_wrapper(att.read) | ||
return att | ||
|
||
@staticmethod | ||
def read_wrapper(func): | ||
|
||
if func.__name__ == "wrapper": | ||
return func | ||
|
||
def wrapper(*args, **kwargs): | ||
output = func(*args, **kwargs) | ||
print("Subprocess output:") | ||
for line_ in os.fsdecode(output).split("\n"): | ||
print(line_) | ||
return output | ||
|
||
return wrapper | ||
|
||
|
||
subprocess.Popen = CustomPopen | ||
|
||
print("ctypes.util script with the find_library:") | ||
print(inspect.getsourcefile(util.find_library), end="\n\n") | ||
|
||
print("find_library function:") | ||
func_lines = list(map(str.rstrip, inspect.getsourcelines(util.find_library)[0])) | ||
indent = len(func_lines[0]) - len(func_lines[0].lstrip()) | ||
for line in func_lines: | ||
print(line.replace(" " * indent, "", 1)) | ||
|
||
library_names = ("cairo-2", "cairo", "libcairo-2") | ||
filenames = ("libcairo.so.2", "libcairo.2.dylib", "libcairo-2.dll") | ||
c_compiler = shutil.which("gcc") or shutil.which("cc") | ||
ld_env = os.environ.get("LD_LIBRARY_PATH") | ||
first_found = "" | ||
|
||
print("\nLD_LIBRARY_PATH =", ld_env, end="\n\n") | ||
|
||
for name in library_names: | ||
if hasattr(util, "_findSoname_ldconfig"): | ||
result = util._findSoname_ldconfig(name) | ||
print(f"_findSoname_ldconfig({name}) ->", result) | ||
if result: | ||
print(f"Found {result}") | ||
if not first_found: | ||
first_found = result | ||
print("---") | ||
if c_compiler and hasattr(util, "_findLib_gcc"): | ||
result = util._findLib_gcc(name) | ||
print(f"_findLib_gcc({name}) ->", result) | ||
if result and hasattr(util, "_get_soname"): | ||
result = util._get_soname(result) | ||
if result: | ||
print(f"Found {result}") | ||
if not first_found: | ||
first_found = result | ||
print("---") | ||
if hasattr(util, "_findLib_ld"): | ||
result = util._findLib_ld(name) | ||
print(f"_findLib_ld({name}) ->", result) | ||
if result and hasattr(util, "_get_soname"): | ||
result = util._get_soname(result) | ||
if result: | ||
print(f"Found {result}") | ||
if not first_found: | ||
first_found = result | ||
print("---") | ||
if hasattr(util, "_findLib_crle"): | ||
result = util._findLib_crle(name, False) | ||
print(f"_findLib_crle({name}) ->", result) | ||
if result and hasattr(util, "_get_soname"): | ||
result = util._get_soname(result) | ||
if result: | ||
print(f"Found {result}") | ||
if not first_found: | ||
first_found = result | ||
print("---") | ||
|
||
if first_found: | ||
filenames = (first_found,) + filenames | ||
|
||
print(f"The path is {first_found or 'not found'}") | ||
print("List of files that FFI will try to load:") | ||
for filename in filenames: | ||
print("-", filename) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
from ctypes.macholib import dyld | ||
from itertools import chain | ||
|
||
library_names = ("cairo-2", "cairo", "libcairo-2") | ||
filenames = ("libcairo.so.2", "libcairo.2.dylib", "libcairo-2.dll") | ||
first_found = "" | ||
names = [] | ||
|
||
for name in library_names: | ||
names += [ | ||
"lib%s.dylib" % name, | ||
"%s.dylib" % name, | ||
"%s.framework/%s" % (name, name), | ||
] | ||
|
||
for name in names: | ||
for path in dyld.dyld_image_suffix_search( | ||
chain( | ||
dyld.dyld_override_search(name), | ||
dyld.dyld_executable_path_search(name), | ||
dyld.dyld_default_search(name), | ||
) | ||
): | ||
if os.path.isfile(path): | ||
print(f"Found: {path}") | ||
if not first_found: | ||
first_found = path | ||
continue | ||
|
||
try: | ||
if dyld._dyld_shared_cache_contains_path(path): | ||
print(f"Found: {path}") | ||
if not first_found: | ||
first_found = path | ||
continue | ||
except NotImplementedError: | ||
pass | ||
|
||
print(f"Doesn't exist: {path}") | ||
print("---") | ||
|
||
if first_found: | ||
filenames = (first_found,) + filenames | ||
|
||
print(f"The path is {first_found or 'not found'}") | ||
print("List of files that FFI will try to load:") | ||
for filename in filenames: | ||
print("-", filename) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
library_names = ("cairo-2", "cairo", "libcairo-2") | ||
filenames = ("libcairo.so.2", "libcairo.2.dylib", "libcairo-2.dll") | ||
first_found = "" | ||
names = [] | ||
|
||
for name in library_names: | ||
if name.lower().endswith(".dll"): | ||
names += [name] | ||
else: | ||
names += [name, name + ".dll"] | ||
|
||
for name in names: | ||
for path in os.environ["PATH"].split(os.pathsep): | ||
resolved_path = os.path.join(path, name) | ||
if os.path.exists(resolved_path): | ||
print(f"Found: {resolved_path}") | ||
if not first_found: | ||
first_found = resolved_path | ||
continue | ||
print(f"Doesn't exist: {resolved_path}") | ||
print("---") | ||
|
||
if first_found: | ||
filenames = (first_found,) + filenames | ||
|
||
print(f"The path is {first_found or 'not found'}") | ||
print("List of files that FFI will try to load:") | ||
for filename in filenames: | ||
print("-", filename) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.