8
8
# nor does it submit to any jurisdiction.
9
9
#
10
10
11
+ import configparser
11
12
import ctypes .util
12
13
import os
13
14
import sys
14
- import configparser
15
15
from pathlib import Path
16
16
17
17
__version__ = "0.0.5"
21
21
"win32" : ".dll" ,
22
22
}
23
23
24
+
24
25
def _get_paths_from_config ():
25
- locations = [Path (p ).expanduser () for p in [
26
- "~/.config/findlibs/findlibs.conf" ,
27
- "~/.findlibs" ,
28
- ]]
26
+ locations = [
27
+ Path (p ).expanduser ()
28
+ for p in [
29
+ "~/.config/findlibs/findlibs.conf" ,
30
+ "~/.findlibs" ,
31
+ ]
32
+ ]
29
33
30
34
locations = [p for p in locations if p .exists ()]
31
35
32
- if len (locations ) == 0 : return []
33
- if len (locations ) > 1 :
34
- raise ValueError (f"There are multiple config files! Delete all but one of { locations } " )
36
+ if len (locations ) == 0 :
37
+ return []
38
+ if len (locations ) > 1 :
39
+ raise ValueError (
40
+ f"There are multiple config files! Delete all but one of { locations } "
41
+ )
35
42
36
- config = configparser .RawConfigParser (allow_no_value = True ) # Allow keys without values
37
- config .optionxform = lambda option : option # Preserve case of keys
38
-
39
- with open (locations [0 ], "r" ) as f :
43
+ config = configparser .RawConfigParser (
44
+ allow_no_value = True
45
+ ) # Allow keys without values
46
+ config .optionxform = lambda option : option # Preserve case of keys
47
+
48
+ with open (locations [0 ], "r" ):
40
49
config .read (locations [0 ])
41
-
42
- if "Paths" not in config : return []
43
- # replace $HOME with ~, expand ~ to full path,
44
- # resolve any relative paths to absolute paths
45
- paths = { Path ( p . replace ( "$HOME" , "~" )). expanduser ()
46
- for p in config ["Paths" ] or []}
47
-
50
+
51
+ if "Paths" not in config :
52
+ return []
53
+ # replace $HOME with ~, expand ~ to full path,
54
+ # resolve any relative paths to absolute paths
55
+ paths = { Path ( p . replace ( "$HOME" , "~" )). expanduser () for p in config ["Paths" ] or []}
56
+
48
57
relative_paths = [p for p in paths if not p .is_absolute ()]
49
58
if relative_paths :
50
- raise ValueError (f"Don't use relative paths in the config file ({ locations [0 ]} ), offending paths are: { relative_paths } " )
51
-
59
+ raise ValueError (
60
+ (
61
+ f"Don't use relative paths in the config file ({ locations [0 ]} ),"
62
+ f" offending paths are: { relative_paths } "
63
+ )
64
+ )
65
+
52
66
files = [p for p in paths if not p .is_dir ()]
53
67
if files :
54
- raise ValueError (f"Don't put files in the config file ({ locations [0 ]} ), offending files are: { files } " )
55
-
68
+ raise ValueError (
69
+ f"Don't put files in the config file ({ locations [0 ]} ), offending files are: { files } "
70
+ )
56
71
57
72
return paths
58
73
@@ -101,18 +116,17 @@ def find(lib_name, pkg_name=None):
101
116
if env in os .environ :
102
117
home = os .path .expanduser (os .environ [env ])
103
118
for lib in ("lib" , "lib64" ):
104
- fullname = os .path .join (
105
- home , lib , libname
106
- )
119
+ fullname = os .path .join (home , lib , libname )
107
120
if os .path .exists (fullname ):
108
121
return fullname
109
122
110
123
config_paths = _get_paths_from_config ()
111
124
112
125
for root in config_paths :
113
- for lib in ("lib" , "lib64" ):
126
+ for lib in ("lib" , "lib64" ):
114
127
filepath = root / lib / f"lib{ lib_name } { extension } "
115
- if filepath .exists (): return str (filepath )
128
+ if filepath .exists ():
129
+ return str (filepath )
116
130
117
131
for path in (
118
132
"LD_LIBRARY_PATH" ,
@@ -123,7 +137,14 @@ def find(lib_name, pkg_name=None):
123
137
if os .path .exists (fullname ):
124
138
return fullname
125
139
126
- for root in ("/" , "/usr/" , "/usr/local/" , "/opt/" , "/opt/homebrew/" , os .path .expanduser ("~/.local" )):
140
+ for root in (
141
+ "/" ,
142
+ "/usr/" ,
143
+ "/usr/local/" ,
144
+ "/opt/" ,
145
+ "/opt/homebrew/" ,
146
+ os .path .expanduser ("~/.local" ),
147
+ ):
127
148
for lib in ("lib" , "lib64" ):
128
149
fullname = os .path .join (root , lib , libname )
129
150
if os .path .exists (fullname ):
0 commit comments