File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,29 +5,65 @@ const nodecallspython = require("./build/Release/nodecallspython");
55
66class Interpreter
77{
8+ loadPython ( dir )
9+ {
10+ let found = false ;
11+ const debug = process . env . NODECALLSPYTHON_DEBUG !== undefined ;
12+ if ( debug )
13+ console . log ( "Loading python from " + dir ) ;
14+
15+ if ( fs . existsSync ( dir ) )
16+ {
17+ fs . readdirSync ( dir ) . forEach ( file => {
18+ if ( file . match ( / l i b p y t h o n .* \. s o / ) )
19+ {
20+ try
21+ {
22+ const filename = path . join ( dir , file ) ;
23+ if ( debug )
24+ console . log ( "Running fixlink on " + filename ) ;
25+
26+ this . fixlink ( filename ) ;
27+ found = true ;
28+ }
29+ catch ( e )
30+ {
31+ console . error ( e ) ;
32+ }
33+ }
34+ } ) ;
35+ }
36+
37+ if ( ! found && debug )
38+ console . log ( "Not found" ) ;
39+
40+ return found ;
41+ }
42+
843 constructor ( )
944 {
1045 this . py = new nodecallspython . PyInterpreter ( ) ;
1146 if ( process . platform === "linux" )
1247 {
1348 const stdout = execSync ( "python3-config --configdir" ) ;
49+ let found = false ;
1450 if ( stdout )
1551 {
1652 const dir = stdout . toString ( ) . trim ( ) ;
17- if ( fs . existsSync ( dir ) )
53+ const res = this . loadPython ( dir ) ;
54+ if ( res )
55+ found = true ;
56+ }
57+
58+ if ( ! found )
59+ {
60+ const stdout = execSync ( "python3-config --ldflags" ) ;
61+ if ( stdout )
1862 {
19- fs . readdirSync ( dir ) . forEach ( file => {
20- if ( file . match ( / l i b p y t h o n .* \. s o / ) )
21- {
22- try
23- {
24- this . fixlink ( path . join ( dir , file ) ) ;
25- }
26- catch ( e )
27- {
28- console . error ( e ) ;
29- }
30- }
63+ const split = stdout . toString ( ) . trim ( ) . split ( " " ) ;
64+ split . forEach ( s => {
65+ if ( s . startsWith ( "-L" ) )
66+ this . loadPython ( s . substring ( 2 ) ) ;
3167 } ) ;
3268 }
3369 }
Original file line number Diff line number Diff line change 11{
22 "name" : " node-calls-python" ,
3- "version" : " 1.7.2 " ,
3+ "version" : " 1.7.3 " ,
44 "license" : " MIT" ,
55 "description" : " This module lets you run python code inside node without spawning new processes" ,
66 "authors" : [
You can’t perform that action at this time.
0 commit comments