-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): Add troubleshooting guide for CairoSVG crash
- Loading branch information
1 parent
51f66fd
commit 78796ad
Showing
4 changed files
with
314 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,100 @@ | ||
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 __get_attribute__(self, name_): | ||
att = super().__getattribute__(name_) | ||
if name_ == "stdout": | ||
print("Subprocess output:") | ||
for line_ in att: | ||
print(os.fsdecode(line_)) | ||
return att | ||
|
||
|
||
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) | ||
|
||
input("Press ENTER to end the script...") |
This file contains 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,51 @@ | ||
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) | ||
|
||
input("Press ENTER to end the script...") |
This file contains 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,33 @@ | ||
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) | ||
|
||
input("Press ENTER to end the script...") |