Return the filename that can be used to locate an object's source. Return None if no way can be identified to get the source.
(object)
| 880 | return None |
| 881 | |
| 882 | def getsourcefile(object): |
| 883 | """Return the filename that can be used to locate an object's source. |
| 884 | Return None if no way can be identified to get the source. |
| 885 | """ |
| 886 | filename = getfile(object) |
| 887 | all_bytecode_suffixes = importlib.machinery.BYTECODE_SUFFIXES[:] |
| 888 | if any(filename.endswith(s) for s in all_bytecode_suffixes): |
| 889 | filename = (os.path.splitext(filename)[0] + |
| 890 | importlib.machinery.SOURCE_SUFFIXES[0]) |
| 891 | elif any(filename.endswith(s) for s in |
| 892 | importlib.machinery.EXTENSION_SUFFIXES): |
| 893 | return None |
| 894 | elif filename.endswith(".fwork"): |
| 895 | # Apple mobile framework markers are another type of non-source file |
| 896 | return None |
| 897 | |
| 898 | # return a filename found in the linecache even if it doesn't exist on disk |
| 899 | if filename in linecache.cache: |
| 900 | return filename |
| 901 | if os.path.exists(filename): |
| 902 | return filename |
| 903 | # only return a non-existent filename if the module has a PEP 302 loader |
| 904 | module = getmodule(object, filename) |
| 905 | if getattr(module, '__loader__', None) is not None: |
| 906 | return filename |
| 907 | elif getattr(getattr(module, "__spec__", None), "loader", None) is not None: |
| 908 | return filename |
| 909 | |
| 910 | def getabsfile(object, _filename=None): |
| 911 | """Return an absolute path to the source or compiled file for an object. |
no test coverage detected
searching dependent graphs…