@@ -91,6 +91,22 @@ func (c *PythonSpec) NameSpace(path string) (string, string, error) {
9191 // XXX: hardcoded python path
9292 condaPrefix := "/home/zhenyang/anaconda3/envs/abcoder/lib/python3.11"
9393 if strings .HasPrefix (path , condaPrefix ) {
94+ if strings .HasPrefix (path , condaPrefix + "/site-packages" ) {
95+ // external module
96+ relPath , err := filepath .Rel (condaPrefix + "/site-packages" , path )
97+ if err != nil {
98+ return "" , "" , err
99+ }
100+ relPath = strings .TrimSuffix (relPath , ".py" )
101+ pkgPath := strings .ReplaceAll (relPath , string (os .PathSeparator ), "." )
102+ modPath := strings .Split (pkgPath , "." )
103+ if len (modPath ) >= 1 {
104+ modName := modPath [0 ]
105+ return modName , pkgPath , nil
106+ }
107+ panic (fmt .Sprintf ("Malformed Namespace %s, pkgPath %s" , path , pkgPath ))
108+ }
109+ // builtin module
94110 modName := "builtins"
95111 relPath , err := filepath .Rel (condaPrefix , path )
96112 if err != nil {
@@ -101,7 +117,7 @@ func (c *PythonSpec) NameSpace(path string) (string, string, error) {
101117 return modName , pkgPath , nil
102118 }
103119
104- panic (fmt .Sprintf ("Namespace %s" , path ))
120+ panic (fmt .Sprintf ("Unhandled Namespace %s" , path ))
105121}
106122
107123func (c * PythonSpec ) ShouldSkip (path string ) bool {
0 commit comments