Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

"""Cross-platform compatibility routines and wrappers.""" 

 

#***************************************************************************** 

# Copyright (C) 2017 William Stein <wstein@gmail.com> 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 2 of the License, or 

# (at your option) any later version. 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

 

import os 

import subprocess 

import sys 

 

from sage.env import SAGE_LOCAL 

 

 

################################################################# 

# Replacements (as needed) for Python stdlib functions to provide 

# better platform compatibility 

################################################################# 

if sys.platform == 'cygwin': 

# find_library that works in cygwin adapted from 

# http://cygwin-ports.svn.sourceforge.net/viewvc/cygwin-ports/ports/trunk/lang/python/2.5.2-ctypes-util-find_library.patch?revision=8245&view=markup 

def _find_library(name): 

for libdir in [os.path.join(SAGE_LOCAL, 'lib'), 

'/usr/local/lib', '/usr/lib']: 

for libext in ['dll.a', 'a']: 

implib = os.path.join(libdir, 

'lib{0}.{1}'.format(name, libext)) 

if not os.path.exists(implib): 

continue 

 

cmd = ['dlltool', '-I', implib] 

 

p = subprocess.Popen(cmd, stdout=subprocess.PIPE, 

stderr=subprocess.PIPE, 

universal_newlines=True) 

 

stdout, stderr = p.communicate() 

 

if p.returncode == 0: 

return stdout.strip() 

elif sys.platform == 'darwin': 

# On OSX non-standard library paths are not automatically found by the 

# find_library implementation without setting DYLD_LIBRARY_PATH; see 

# https://trac.sagemath.org/ticket/21399#comment:25 

from ctypes.util import find_library as _orig_find_library 

 

def _find_library(name): 

sage_local_lib = os.path.join(SAGE_LOCAL, 'lib') 

orig_dyld_library_path = os.environ.get('DYLD_LIBRARY_PATH') 

try: 

if orig_dyld_library_path: 

os.environ['DYLD_LIBRARY_PATH'] = '%s:%s' % ( 

sage_local_lib, orig_dyld_library_path) 

else: 

os.environ['DYLD_LIBRARY_PATH'] = sage_local_lib 

 

return _orig_find_library(name) 

finally: 

# Set os.environ back to what it was 

if orig_dyld_library_path is not None: 

os.environ['DYLD_LIBRARY_PATH'] = orig_dyld_library_path 

else: 

os.environ.pop('DYLD_LIBRARY_PATH', None) 

else: 

# On other Unix-like platforms, at least where gcc is available, 

# ctypes.util.find_library works, because it takes into account where gcc 

# finds the library as if were being linked with 

from ctypes.util import find_library as _find_library 

 

 

def find_library(name): 

""" 

Returns the shared library filename for a given library. 

 

The library name is given without any prefixes or suffixes--(e.g. 

just "Singular", not "libSingular", as shared library naming is 

platform-specific. 

 

This does ''not'' currently return the absolute path of the file on most 

platforms; see https://bugs.python.org/issue21042 

 

EXAMPLES:: 

 

sage: from sage.misc.compat import find_library 

sage: find_library('Singular') 

'...Singular...' 

 

""" 

 

return _find_library(name)