From: Charlie G. <cha...@gm...> - 2007-02-11 04:34:35
|
Hi Alan, On 2/9/07, Alan Field <Ala...@sa...> wrote: > So I am trying to run an existing package that I developed with Jython 2.1, and I am getting ImportErrors. I know that the semantics of import have changed in the 2.2 release, but I am not exactly sure how these changes could affect my code. I know that Jython 2.2 has a PEP 302 implementation, but I am not exactly sure what those changes mean in the context of Jython. > > Any hints on how to go about determining if this is (a) a problem with my code, or (b) a problem with Jython? I am using some code to dynamically add JAR files to the Jython classpath. I suspect that this might be the problem, but I am not sure. Does Jython 2.2 support this? And if so, how do I access this functionality in my code? 2.2 supports adding jars at runtime, but it may have changed from how you did it under 2.1. Posting the code you use to add jars dynamically would help in tracking down the problem. I'd like to see how you did it under 2.1 so I can document the change if need be. In the future, please post to only one of the jython lists with a question. This is a usage question, so I'd say it should have been to jython-users alone. Thanks, Charlie |
From: Charlie G. <cha...@gm...> - 2007-02-13 07:13:38
|
On 2/11/07, Alan Field <Ala...@sa...> wrote: > I have also been able to use a JAR file in 2.2 just by adding it to system.path. I thought that this was going to be the way that Jython supported dynamically using JAR files. I am going to start deleting lines from my modules to try and see how far the import is getting, but I was just looking for some other clues to try and track this down. I'm going to look at your code more closely later to see how things have changed between 2.1 and now, but until I do that could you tell me what kind of errors you're getting after adding a jar to sys.path? Thanks, Charlie |
From: Alan F. <Ala...@sa...> - 2007-02-13 15:24:42
|
Charlie, Well, this has gotten much more interesting. For some reason, if I move = my Python package to Jython's Lib directory, it executes correctly. (I = have some changes to make, but the import behavior is correct.) I have = also been able to verify that the following code will work correctly to = add JAR files dynamically in the 2.2 beta. (The method now adds JAR = files to the sys.path, and the directory to sys.path and = packageManager.addClassPath()) I have not completely tested this = approach, but it seems to work in my preliminary testing. def add_module_jars(jar_path): """ This function makes every JAR files in the supplied path dynamically loadable without being on the CLASSPATH environment = variable. Do not add the entry to the CLASSPATH if it already exists. """ if exists(jar_path): print "Adding jars from directory =3D '" + jar_path + "'" =20 all_urls =3D list(ClassLoader.getSystemClassLoader().getURLs()) =20 #Add the directory to the Classpath try: if File(jar_path).toURL() not in all_urls: path.append(jar_path) packageManager.addClassPath(jar_path) except IOException:=20 print "Unable to add '" + jar_path + "' to Classpath" =20 #Add the jars in the directory to the Classpath for jar in glob(jar_path + sep + "*.jar"): try: =20 if File(jar).toURL() not in all_urls: path.append(jar) except IOException:=20 print "Unable to add '" + jar + "' to Classpath" =20 However, what is really strange is that if my package is not in the = Jython Lib directory, then the imports fail. What is really strange = about this failure is that the import does not execute code in the = __init__.py or module files. I have deleted the class files, and they = are not regenerated. This is the part of the directory structure of my = package: SAS | -> __init__.py (contains various utility routines including = add_module_jars) -> DIServer -> __init__.py (contains a class called MDOContext) -> support -> CreditRisk -> MAClient Normally, I can execute a statement like this in the console to import = MDOContext: from SAS.DIServer import MDOContext However, in the 2.2 beta, this produces an error: Jython 2.2b1 on java1.4.2_09 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append("C:\\SASJythonPackage") >>> from SAS.DIServer import MDOContext Traceback (innermost last): File "<console>", line 1, in ? ImportError: no module named DIServer If I step back and try to import SAS directly, then I can see that even = though the console has not generated an error, the import did not work = correctly. Jython 2.2b1 on java1.4.2_09 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append("C:\\SASJythonPackage") >>> import SAS >>> dir() ['SAS', '__doc__', '__name__', 'sys'] >>> dir(SAS) ['CreditRisk', 'DIServer', 'MAClient', '__name__', 'support'] >>> When I execute the dir(SAS) command, it should look something like this: Jython 2.1 on java1.4.2_09 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append("C:\\SASJythonPackage") >>> import SAS >>> dir(SAS) ['Class', 'ClassLoader', 'ConfigParser', 'File', 'Hashtable', = 'IOException', 'SASJythonPackagePath', 'SAS_TIME_OFFSET', 'ST_ATIME', = 'System', '__all__', '__doc__', '__file__', '__name__', '__path__', = '_read_users', '_write_users', 'add_module_jars', 'array', 'choice', = 'client_stats_path', 'copyfile', 'exists', 'get_key_list', 'get_user', = 'getcwd', 'glob', 'global_locks_path', 'local_stat_path', 'lock', 'log', = 'makedirs', 'my_name_is', 'normcase', 'olderthan', 'packageManager', = 'path', 'permute', 'printCP', 'read_config_file', 'remove', = 'remove_list_duplicates', 'restore_user', 'rmdir', = 'sasjythonpackage_path', 'sep', 'setup_users', 'sleep', 'stat', = 'stub_client_side_job', 'stub_job_class', 'stub_tracker', 'system', = 'time'] I have tried stepping through the import code, and it appears that SAS = is loaded as a module of type "java", instead of coming from a .py file. = Here is the sys.modules output from Jython 2.2 beta: >>> sys.modules {'__builtin__': <module '__builtin__' from 'null'>, 'SAS': <java package = SAS 1>, 'java': <java package java 2>, 'sys': sys module, 'os': <jclass = org.python.modules.os 3>, 'stat': <module 'stat' from = 'C:\jython2.2b1\Lib\stat.py'>, 'sitecustomize': <module 'sitecustomize' = from 'C:\jython2.2b1\Lib\sitecustomize.py'>, 'site': <module 'site' from = 'C:\jython2.2b1\Lib\site.py'>, 'javapath': <module 'javapath' from = 'C:\jython2.2b1\Lib\javapath.py'>, 'javaos': <module 'javaos' from = 'C:\jython2.2b1\Lib\javaos.py'>, 'java.io': <java package java.io 4>, = 'UserDict': <module 'UserDict' from 'C:\jython2.2b1\Lib\UserDict.py'>, = '__main__': <module '__main__' from 'null'>, 'java.lang': <java package = java.lang 5>, 'exceptions': <jclass org.python.core.exceptions 6>} And here is the output from Jython 2.1: {'__main__': <module __main__ at 10276870>, 'os': <jclass = org.python.modules.os at 18707897>, 'java.lang': <java package java.lang = at 18610053>, 'fnmatch': <module fnmatch at 18304709>, 'strop': None, = 'sre': <module sre at 20211730>, 'SAS.glob': None, 'glob': <module glob = at 27035333>, 'javaos': <module javaos at 22293724>, 'copy_reg': <module = copy_reg at 21840659>, '__builtin__': <module __builtin__ at 24027487>, = 'types': <jclass org.python.modules.types at 2389016>, 'SAS.java': None, = 'SAS.os': None, 'SAS.random': None, 'SAS.stat': None, 'SAS.sys': None, = 'random': <module random at 21094410>, 'ConfigParser': <module = ConfigParser at 31174955>, 'time': <jclass org.python.modules.time at = 5014562>, 'shutil': <module shutil at 24565346>, 'SAS': <module SAS at = 16046701>, 'java.io': <java package java.io at 19949342>, 'SAS.time': = None, 'sre_parse': <module sre_parse at 12715534>, 'jarray': <jclass = org.python.modules.jarray at 1816810>, 'sitecustomize': <module = sitecustomize at 599654>, 'stat': <module stat at 12066474>, 'SAS.jarray': None, = 'thread': <jclass org.python.modules.thread at 31811005>, 'java': <java = package java at 24798854>, 'site': <module site at 14740287>, 'sys': sys = module, 'java.util': <java package java.util at 7647499>, = 'SAS.ConfigParser': None, 'math': <jclass org.python.modules.math at = 18053010>, '_sre': <jclass org.python.modules._sre at 17769531>, = 'UserDict': <module UserDict at 18073623>, 'string': <module string at = 28664226>, 'SAS.shutil': None, 'sre_compile': <module sre_compile at = 18670846>, 'os.path': <module javapath at 33426790>, 're': <module re at = 2220309>, 'javapath': <module javapath at 33426790>, 'exceptions': = <jclass org.python.core.exceptions at 4214450>, 'sre_constants': <module = sre_constants at 32414915>} I will keep trying to figure out what is going on, and sorry for the = length of this reply. I was just really confused when moving the package = to the Lib directory worked. Thanks, Alan -----Original Message----- From: Charlie Groves [mailto:cha...@gm...]=20 Sent: Tuesday, February 13, 2007 2:14 AM To: Alan Field Cc: jython users Subject: Re: [Jython-dev] Problems with import and Jython 2.2 Beta1... On 2/11/07, Alan Field <Ala...@sa...> wrote: > I have also been able to use a JAR file in 2.2 just by adding it to = system.path. I thought that this was going to be the way that Jython = supported dynamically using JAR files. I am going to start deleting = lines from my modules to try and see how far the import is getting, but = I was just looking for some other clues to try and track this down. I'm going to look at your code more closely later to see how things have = changed between 2.1 and now, but until I do that could you tell me what = kind of errors you're getting after adding a jar to sys.path? Thanks, Charlie |
From: Charlie G. <cha...@gm...> - 2007-02-15 06:41:29
|
Hmm, could there be an incomplete SAS package somewhere in your classpath? That could account for all of the symptoms here. The package in your classpath gets imported before the one you append to the end of sys.path. When you move the package to the Lib directory, it's tried before the classpath so it works. Could you try inserting your package directory at the head of sys.path or printing out SAS.__file__ to see where it's living? Charlie On 2/13/07, Alan Field <Ala...@sa...> wrote: > Charlie, > > Well, this has gotten much more interesting. For some reason, if I move my Python package to Jython's Lib directory, it executes correctly. (I have some changes to make, but the import behavior is correct.) I have also been able to verify that the following code will work correctly to add JAR files dynamically in the 2.2 beta. (The method now adds JAR files to the sys.path, and the directory to sys.path and packageManager.addClassPath()) I have not completely tested this approach, but it seems to work in my preliminary testing. > > def add_module_jars(jar_path): > """ > This function makes every JAR files in the supplied path > dynamically loadable without being on the CLASSPATH environment variable. > Do not add the entry to the CLASSPATH if it already exists. > """ > if exists(jar_path): > print "Adding jars from directory = '" + jar_path + "'" > > all_urls = list(ClassLoader.getSystemClassLoader().getURLs()) > > #Add the directory to the Classpath > try: > if File(jar_path).toURL() not in all_urls: > path.append(jar_path) > packageManager.addClassPath(jar_path) > except IOException: > print "Unable to add '" + jar_path + "' to Classpath" > > #Add the jars in the directory to the Classpath > for jar in glob(jar_path + sep + "*.jar"): > try: > if File(jar).toURL() not in all_urls: > path.append(jar) > except IOException: > print "Unable to add '" + jar + "' to Classpath" > > However, what is really strange is that if my package is not in the Jython Lib directory, then the imports fail. What is really strange about this failure is that the import does not execute code in the __init__.py or module files. I have deleted the class files, and they are not regenerated. This is the part of the directory structure of my package: > > SAS > | > -> __init__.py (contains various utility routines including add_module_jars) > -> DIServer > -> __init__.py (contains a class called MDOContext) > -> support > -> CreditRisk > -> MAClient > > Normally, I can execute a statement like this in the console to import MDOContext: > > from SAS.DIServer import MDOContext > > However, in the 2.2 beta, this produces an error: > > Jython 2.2b1 on java1.4.2_09 (JIT: null) > Type "copyright", "credits" or "license" for more information. > >>> import sys > >>> sys.path.append("C:\\SASJythonPackage") > >>> from SAS.DIServer import MDOContext > Traceback (innermost last): > File "<console>", line 1, in ? > ImportError: no module named DIServer > > If I step back and try to import SAS directly, then I can see that even though the console has not generated an error, the import did not work correctly. > > Jython 2.2b1 on java1.4.2_09 (JIT: null) > Type "copyright", "credits" or "license" for more information. > >>> import sys > >>> sys.path.append("C:\\SASJythonPackage") > >>> import SAS > >>> dir() > ['SAS', '__doc__', '__name__', 'sys'] > >>> dir(SAS) > ['CreditRisk', 'DIServer', 'MAClient', '__name__', 'support'] > >>> > > When I execute the dir(SAS) command, it should look something like this: > Jython 2.1 on java1.4.2_09 (JIT: null) > Type "copyright", "credits" or "license" for more information. > >>> import sys > >>> sys.path.append("C:\\SASJythonPackage") > >>> import SAS > >>> dir(SAS) > ['Class', 'ClassLoader', 'ConfigParser', 'File', 'Hashtable', 'IOException', 'SASJythonPackagePath', 'SAS_TIME_OFFSET', 'ST_ATIME', 'System', '__all__', '__doc__', '__file__', '__name__', '__path__', '_read_users', '_write_users', 'add_module_jars', 'array', 'choice', 'client_stats_path', 'copyfile', 'exists', 'get_key_list', 'get_user', 'getcwd', 'glob', 'global_locks_path', 'local_stat_path', 'lock', 'log', 'makedirs', 'my_name_is', 'normcase', 'olderthan', 'packageManager', 'path', 'permute', 'printCP', 'read_config_file', 'remove', 'remove_list_duplicates', 'restore_user', 'rmdir', 'sasjythonpackage_path', 'sep', 'setup_users', 'sleep', 'stat', 'stub_client_side_job', 'stub_job_class', 'stub_tracker', 'system', 'time'] > > I have tried stepping through the import code, and it appears that SAS is loaded as a module of type "java", instead of coming from a .py file. Here is the sys.modules output from Jython 2.2 beta: > > >>> sys.modules > {'__builtin__': <module '__builtin__' from 'null'>, 'SAS': <java package SAS 1>, 'java': <java package java 2>, 'sys': sys module, 'os': <jclass org.python.modules.os 3>, 'stat': <module 'stat' from 'C:\jython2.2b1\Lib\stat.py'>, 'sitecustomize': <module 'sitecustomize' from 'C:\jython2.2b1\Lib\sitecustomize.py'>, 'site': <module 'site' from 'C:\jython2.2b1\Lib\site.py'>, 'javapath': <module 'javapath' from 'C:\jython2.2b1\Lib\javapath.py'>, 'javaos': <module 'javaos' from 'C:\jython2.2b1\Lib\javaos.py'>, 'java.io': <java package java.io 4>, 'UserDict': <module 'UserDict' from 'C:\jython2.2b1\Lib\UserDict.py'>, '__main__': <module '__main__' from 'null'>, 'java.lang': <java package java.lang 5>, 'exceptions': <jclass org.python.core.exceptions 6>} > > And here is the output from Jython 2.1: > > {'__main__': <module __main__ at 10276870>, 'os': <jclass org.python.modules.os at 18707897>, 'java.lang': <java package java.lang at 18610053>, 'fnmatch': <module fnmatch at 18304709>, 'strop': None, 'sre': <module sre at 20211730>, 'SAS.glob': None, 'glob': <module glob at 27035333>, 'javaos': <module javaos at 22293724>, 'copy_reg': <module copy_reg at 21840659>, '__builtin__': <module __builtin__ at 24027487>, 'types': <jclass org.python.modules.types at 2389016>, 'SAS.java': None, 'SAS.os': None, 'SAS.random': None, 'SAS.stat': None, 'SAS.sys': None, 'random': <module random at 21094410>, 'ConfigParser': <module ConfigParser at 31174955>, 'time': <jclass org.python.modules.time at 5014562>, 'shutil': <module shutil at 24565346>, 'SAS': <module SAS at 16046701>, 'java.io': <java package java.io at 19949342>, 'SAS.time': None, 'sre_parse': <module sre_parse at 12715534>, 'jarray': <jclass org.python.modules.jarray at 1816810>, 'sitecustomize': <module sitecustomize at > 599654>, 'stat': <module stat at 12066474>, 'SAS.jarray': None, 'thread': <jclass org.python.modules.thread at 31811005>, 'java': <java package java at 24798854>, 'site': <module site at 14740287>, 'sys': sys module, 'java.util': <java package java.util at 7647499>, 'SAS.ConfigParser': None, 'math': <jclass org.python.modules.math at 18053010>, '_sre': <jclass org.python.modules._sre at 17769531>, 'UserDict': <module UserDict at 18073623>, 'string': <module string at 28664226>, 'SAS.shutil': None, 'sre_compile': <module sre_compile at 18670846>, 'os.path': <module javapath at 33426790>, 're': <module re at 2220309>, 'javapath': <module javapath at 33426790>, 'exceptions': <jclass org.python.core.exceptions at 4214450>, 'sre_constants': <module sre_constants at 32414915>} > > I will keep trying to figure out what is going on, and sorry for the length of this reply. I was just really confused when moving the package to the Lib directory worked. > > Thanks, > Alan > > > -----Original Message----- > From: Charlie Groves [mailto:cha...@gm...] > Sent: Tuesday, February 13, 2007 2:14 AM > To: Alan Field > Cc: jython users > Subject: Re: [Jython-dev] Problems with import and Jython 2.2 Beta1... > > On 2/11/07, Alan Field <Ala...@sa...> wrote: > > I have also been able to use a JAR file in 2.2 just by adding it to system.path. I thought that this was going to be the way that Jython supported dynamically using JAR files. I am going to start deleting lines from my modules to try and see how far the import is getting, but I was just looking for some other clues to try and track this down. > > I'm going to look at your code more closely later to see how things have changed between 2.1 and now, but until I do that could you tell me what kind of errors you're getting after adding a jar to sys.path? > > Thanks, > Charlie > |
From: Alan F. <Ala...@sa...> - 2007-02-15 15:14:14
|
Charlie, I was actually pursuing that as the problem, but in my batch file that I = use to start Jython I clear the CLASSPATH. The jython.jar file is the = only entry on my CLASSPATH in either case. (Whether the package is = inside or outside the Lib directory.) SAS.__file__ is None when the = package is outside the Lib directory and has the path to the __init__.py = file if the package is inside the Lib directory. Thanks, Alan -----Original Message----- From: Charlie Groves [mailto:cha...@gm...]=20 Sent: Thursday, February 15, 2007 1:41 AM To: Alan Field Cc: jython users Subject: Re: Problems with import and Jython 2.2 Beta1... Hmm, could there be an incomplete SAS package somewhere in your = classpath? That could account for all of the symptoms here. The = package in your classpath gets imported before the one you append to the = end of sys.path. When you move the package to the Lib directory, it's = tried before the classpath so it works. Could you try inserting your = package directory at the head of sys.path or printing out SAS.__file__ = to see where it's living? Charlie On 2/13/07, Alan Field <Ala...@sa...> wrote: > Charlie, > > Well, this has gotten much more interesting. For some reason, if I = move my Python package to Jython's Lib directory, it executes correctly. = (I have some changes to make, but the import behavior is correct.) I = have also been able to verify that the following code will work = correctly to add JAR files dynamically in the 2.2 beta. (The method now = adds JAR files to the sys.path, and the directory to sys.path and = packageManager.addClassPath()) I have not completely tested this = approach, but it seems to work in my preliminary testing. > > def add_module_jars(jar_path): > """ > This function makes every JAR files in the supplied path > dynamically loadable without being on the CLASSPATH environment = variable. > Do not add the entry to the CLASSPATH if it already exists. > """ > if exists(jar_path): > print "Adding jars from directory =3D '" + jar_path + "'" > > all_urls =3D = list(ClassLoader.getSystemClassLoader().getURLs()) > > #Add the directory to the Classpath > try: > if File(jar_path).toURL() not in all_urls: > path.append(jar_path) > packageManager.addClassPath(jar_path) > except IOException: > print "Unable to add '" + jar_path + "' to Classpath" > > #Add the jars in the directory to the Classpath > for jar in glob(jar_path + sep + "*.jar"): > try: > if File(jar).toURL() not in all_urls: > path.append(jar) > except IOException: > print "Unable to add '" + jar + "' to Classpath" > > However, what is really strange is that if my package is not in the = Jython Lib directory, then the imports fail. What is really strange = about this failure is that the import does not execute code in the = __init__.py or module files. I have deleted the class files, and they = are not regenerated. This is the part of the directory structure of my = package: > > SAS > | > -> __init__.py (contains various utility routines including=20 > -> add_module_jars) DIServer > -> __init__.py (contains a class called MDOContext) > -> support > -> CreditRisk > -> MAClient > > Normally, I can execute a statement like this in the console to import = MDOContext: > > from SAS.DIServer import MDOContext > > However, in the 2.2 beta, this produces an error: > > Jython 2.2b1 on java1.4.2_09 (JIT: null) Type "copyright", "credits"=20 > or "license" for more information. > >>> import sys > >>> sys.path.append("C:\\SASJythonPackage") > >>> from SAS.DIServer import MDOContext > Traceback (innermost last): > File "<console>", line 1, in ? > ImportError: no module named DIServer > > If I step back and try to import SAS directly, then I can see that = even though the console has not generated an error, the import did not = work correctly. > > Jython 2.2b1 on java1.4.2_09 (JIT: null) Type "copyright", "credits"=20 > or "license" for more information. > >>> import sys > >>> sys.path.append("C:\\SASJythonPackage") > >>> import SAS > >>> dir() > ['SAS', '__doc__', '__name__', 'sys'] > >>> dir(SAS) > ['CreditRisk', 'DIServer', 'MAClient', '__name__', 'support'] > >>> > > When I execute the dir(SAS) command, it should look something like = this: > Jython 2.1 on java1.4.2_09 (JIT: null) Type "copyright", "credits" or=20 > "license" for more information. > >>> import sys > >>> sys.path.append("C:\\SASJythonPackage") > >>> import SAS > >>> dir(SAS) > ['Class', 'ClassLoader', 'ConfigParser', 'File', 'Hashtable',=20 > 'IOException', 'SASJythonPackagePath', 'SAS_TIME_OFFSET', 'ST_ATIME',=20 > 'System', '__all__', '__doc__', '__file__', '__name__', '__path__',=20 > '_read_users', '_write_users', 'add_module_jars', 'array', 'choice',=20 > 'client_stats_path', 'copyfile', 'exists', 'get_key_list', 'get_user', = > 'getcwd', 'glob', 'global_locks_path', 'local_stat_path', 'lock',=20 > 'log', 'makedirs', 'my_name_is', 'normcase', 'olderthan',=20 > 'packageManager', 'path', 'permute', 'printCP', 'read_config_file',=20 > 'remove', 'remove_list_duplicates', 'restore_user', 'rmdir',=20 > 'sasjythonpackage_path', 'sep', 'setup_users', 'sleep', 'stat',=20 > 'stub_client_side_job', 'stub_job_class', 'stub_tracker', 'system',=20 > 'time'] > > I have tried stepping through the import code, and it appears that SAS = is loaded as a module of type "java", instead of coming from a .py file. = Here is the sys.modules output from Jython 2.2 beta: > > >>> sys.modules > {'__builtin__': <module '__builtin__' from 'null'>, 'SAS': <java=20 > package SAS 1>, 'java': <java package java 2>, 'sys': sys module,=20 > 'os': <jclass org.python.modules.os 3>, 'stat': <module 'stat' from=20 > 'C:\jython2.2b1\Lib\stat.py'>, 'sitecustomize': <module=20 > 'sitecustomize' from 'C:\jython2.2b1\Lib\sitecustomize.py'>, 'site':=20 > <module 'site' from 'C:\jython2.2b1\Lib\site.py'>, 'javapath': <module = > 'javapath' from 'C:\jython2.2b1\Lib\javapath.py'>, 'javaos': <module=20 > 'javaos' from 'C:\jython2.2b1\Lib\javaos.py'>, 'java.io': <java=20 > package java.io 4>, 'UserDict': <module 'UserDict' from=20 > 'C:\jython2.2b1\Lib\UserDict.py'>, '__main__': <module '__main__' from = > 'null'>, 'java.lang': <java package java.lang 5>, 'exceptions':=20 > <jclass org.python.core.exceptions 6>} > > And here is the output from Jython 2.1: > > {'__main__': <module __main__ at 10276870>, 'os': <jclass=20 > org.python.modules.os at 18707897>, 'java.lang': <java package=20 > java.lang at 18610053>, 'fnmatch': <module fnmatch at 18304709>,=20 > 'strop': None, 'sre': <module sre at 20211730>, 'SAS.glob': None,=20 > 'glob': <module glob at 27035333>, 'javaos': <module javaos at=20 > 22293724>, 'copy_reg': <module copy_reg at 21840659>, '__builtin__':=20 > <module __builtin__ at 24027487>, 'types': <jclass=20 > org.python.modules.types at 2389016>, 'SAS.java': None, 'SAS.os':=20 > None, 'SAS.random': None, 'SAS.stat': None, 'SAS.sys': None, 'random': = > <module random at 21094410>, 'ConfigParser': <module ConfigParser at=20 > 31174955>, 'time': <jclass org.python.modules.time at 5014562>,=20 > 'shutil': <module shutil at 24565346>, 'SAS': <module SAS at=20 > 16046701>, 'java.io': <java package java.io at 19949342>, 'SAS.time':=20 > None, 'sre_parse': <module sre_parse at 12715534>, 'jarray': <jclass=20 > org.python.modules.jarray at 1816810>, 'sitecustomize': <module=20 > sitecustomize at > 599654>, 'stat': <module stat at 12066474>, 'SAS.jarray': None,=20 > 599654>'thread': <jclass org.python.modules.thread at 31811005>,=20 > 599654>'java': <java package java at 24798854>, 'site': <module site=20 > 599654>at 14740287>, 'sys': sys module, 'java.util': <java package=20 > 599654>java.util at 7647499>, 'SAS.ConfigParser': None, 'math':=20 > 599654><jclass org.python.modules.math at 18053010>, '_sre': <jclass=20 > 599654>org.python.modules._sre at 17769531>, 'UserDict': <module=20 > 599654>UserDict at 18073623>, 'string': <module string at 28664226>,=20 > 599654>'SAS.shutil': None, 'sre_compile': <module sre_compile at=20 > 599654>18670846>, 'os.path': <module javapath at 33426790>, 're':=20 > 599654><module re at 2220309>, 'javapath': <module javapath at=20 > 599654>33426790>, 'exceptions': <jclass org.python.core.exceptions at=20 > 599654>4214450>, 'sre_constants': <module sre_constants at 32414915>} > > I will keep trying to figure out what is going on, and sorry for the = length of this reply. I was just really confused when moving the package = to the Lib directory worked. > > Thanks, > Alan > > > -----Original Message----- > From: Charlie Groves [mailto:cha...@gm...] > Sent: Tuesday, February 13, 2007 2:14 AM > To: Alan Field > Cc: jython users > Subject: Re: [Jython-dev] Problems with import and Jython 2.2 Beta1... > > On 2/11/07, Alan Field <Ala...@sa...> wrote: > > I have also been able to use a JAR file in 2.2 just by adding it to = system.path. I thought that this was going to be the way that Jython = supported dynamically using JAR files. I am going to start deleting = lines from my modules to try and see how far the import is getting, but = I was just looking for some other clues to try and track this down. > > I'm going to look at your code more closely later to see how things = have changed between 2.1 and now, but until I do that could you tell me = what kind of errors you're getting after adding a jar to sys.path? > > Thanks, > Charlie > |
From: Charlie G. <cha...@gm...> - 2007-02-15 16:16:05
|
Did you try sys.path.insert(0, "C:\\SASJythonPackage")? It's getting to be more of a longshot, but the offending package could still be in your JVM's ext or you could have a site file that adds it to your sys.path. Charlie On 2/15/07, Alan Field <Ala...@sa...> wrote: > Charlie, > > I was actually pursuing that as the problem, but in my batch file that I use to start Jython I clear the CLASSPATH. The jython.jar file is the only entry on my CLASSPATH in either case. (Whether the package is inside or outside the Lib directory.) SAS.__file__ is None when the package is outside the Lib directory and has the path to the __init__.py file if the package is inside the Lib directory. > > Thanks, > Alan > > -----Original Message----- > From: Charlie Groves [mailto:cha...@gm...] > Sent: Thursday, February 15, 2007 1:41 AM > To: Alan Field > Cc: jython users > Subject: Re: Problems with import and Jython 2.2 Beta1... > > Hmm, could there be an incomplete SAS package somewhere in your classpath? That could account for all of the symptoms here. The package in your classpath gets imported before the one you append to the end of sys.path. When you move the package to the Lib directory, it's tried before the classpath so it works. Could you try inserting your package directory at the head of sys.path or printing out SAS.__file__ to see where it's living? > > Charlie > > On 2/13/07, Alan Field <Ala...@sa...> wrote: > > Charlie, > > > > Well, this has gotten much more interesting. For some reason, if I move my Python package to Jython's Lib directory, it executes correctly. (I have some changes to make, but the import behavior is correct.) I have also been able to verify that the following code will work correctly to add JAR files dynamically in the 2.2 beta. (The method now adds JAR files to the sys.path, and the directory to sys.path and packageManager.addClassPath()) I have not completely tested this approach, but it seems to work in my preliminary testing. > > > > def add_module_jars(jar_path): > > """ > > This function makes every JAR files in the supplied path > > dynamically loadable without being on the CLASSPATH environment variable. > > Do not add the entry to the CLASSPATH if it already exists. > > """ > > if exists(jar_path): > > print "Adding jars from directory = '" + jar_path + "'" > > > > all_urls = list(ClassLoader.getSystemClassLoader().getURLs()) > > > > #Add the directory to the Classpath > > try: > > if File(jar_path).toURL() not in all_urls: > > path.append(jar_path) > > packageManager.addClassPath(jar_path) > > except IOException: > > print "Unable to add '" + jar_path + "' to Classpath" > > > > #Add the jars in the directory to the Classpath > > for jar in glob(jar_path + sep + "*.jar"): > > try: > > if File(jar).toURL() not in all_urls: > > path.append(jar) > > except IOException: > > print "Unable to add '" + jar + "' to Classpath" > > > > However, what is really strange is that if my package is not in the Jython Lib directory, then the imports fail. What is really strange about this failure is that the import does not execute code in the __init__.py or module files. I have deleted the class files, and they are not regenerated. This is the part of the directory structure of my package: > > > > SAS > > | > > -> __init__.py (contains various utility routines including > > -> add_module_jars) DIServer > > -> __init__.py (contains a class called MDOContext) > > -> support > > -> CreditRisk > > -> MAClient > > > > Normally, I can execute a statement like this in the console to import MDOContext: > > > > from SAS.DIServer import MDOContext > > > > However, in the 2.2 beta, this produces an error: > > > > Jython 2.2b1 on java1.4.2_09 (JIT: null) Type "copyright", "credits" > > or "license" for more information. > > >>> import sys > > >>> sys.path.append("C:\\SASJythonPackage") > > >>> from SAS.DIServer import MDOContext > > Traceback (innermost last): > > File "<console>", line 1, in ? > > ImportError: no module named DIServer > > > > If I step back and try to import SAS directly, then I can see that even though the console has not generated an error, the import did not work correctly. > > > > Jython 2.2b1 on java1.4.2_09 (JIT: null) Type "copyright", "credits" > > or "license" for more information. > > >>> import sys > > >>> sys.path.append("C:\\SASJythonPackage") > > >>> import SAS > > >>> dir() > > ['SAS', '__doc__', '__name__', 'sys'] > > >>> dir(SAS) > > ['CreditRisk', 'DIServer', 'MAClient', '__name__', 'support'] > > >>> > > > > When I execute the dir(SAS) command, it should look something like this: > > Jython 2.1 on java1.4.2_09 (JIT: null) Type "copyright", "credits" or > > "license" for more information. > > >>> import sys > > >>> sys.path.append("C:\\SASJythonPackage") > > >>> import SAS > > >>> dir(SAS) > > ['Class', 'ClassLoader', 'ConfigParser', 'File', 'Hashtable', > > 'IOException', 'SASJythonPackagePath', 'SAS_TIME_OFFSET', 'ST_ATIME', > > 'System', '__all__', '__doc__', '__file__', '__name__', '__path__', > > '_read_users', '_write_users', 'add_module_jars', 'array', 'choice', > > 'client_stats_path', 'copyfile', 'exists', 'get_key_list', 'get_user', > > 'getcwd', 'glob', 'global_locks_path', 'local_stat_path', 'lock', > > 'log', 'makedirs', 'my_name_is', 'normcase', 'olderthan', > > 'packageManager', 'path', 'permute', 'printCP', 'read_config_file', > > 'remove', 'remove_list_duplicates', 'restore_user', 'rmdir', > > 'sasjythonpackage_path', 'sep', 'setup_users', 'sleep', 'stat', > > 'stub_client_side_job', 'stub_job_class', 'stub_tracker', 'system', > > 'time'] > > > > I have tried stepping through the import code, and it appears that SAS is loaded as a module of type "java", instead of coming from a .py file. Here is the sys.modules output from Jython 2.2 beta: > > > > >>> sys.modules > > {'__builtin__': <module '__builtin__' from 'null'>, 'SAS': <java > > package SAS 1>, 'java': <java package java 2>, 'sys': sys module, > > 'os': <jclass org.python.modules.os 3>, 'stat': <module 'stat' from > > 'C:\jython2.2b1\Lib\stat.py'>, 'sitecustomize': <module > > 'sitecustomize' from 'C:\jython2.2b1\Lib\sitecustomize.py'>, 'site': > > <module 'site' from 'C:\jython2.2b1\Lib\site.py'>, 'javapath': <module > > 'javapath' from 'C:\jython2.2b1\Lib\javapath.py'>, 'javaos': <module > > 'javaos' from 'C:\jython2.2b1\Lib\javaos.py'>, 'java.io': <java > > package java.io 4>, 'UserDict': <module 'UserDict' from > > 'C:\jython2.2b1\Lib\UserDict.py'>, '__main__': <module '__main__' from > > 'null'>, 'java.lang': <java package java.lang 5>, 'exceptions': > > <jclass org.python.core.exceptions 6>} > > > > And here is the output from Jython 2.1: > > > > {'__main__': <module __main__ at 10276870>, 'os': <jclass > > org.python.modules.os at 18707897>, 'java.lang': <java package > > java.lang at 18610053>, 'fnmatch': <module fnmatch at 18304709>, > > 'strop': None, 'sre': <module sre at 20211730>, 'SAS.glob': None, > > 'glob': <module glob at 27035333>, 'javaos': <module javaos at > > 22293724>, 'copy_reg': <module copy_reg at 21840659>, '__builtin__': > > <module __builtin__ at 24027487>, 'types': <jclass > > org.python.modules.types at 2389016>, 'SAS.java': None, 'SAS.os': > > None, 'SAS.random': None, 'SAS.stat': None, 'SAS.sys': None, 'random': > > <module random at 21094410>, 'ConfigParser': <module ConfigParser at > > 31174955>, 'time': <jclass org.python.modules.time at 5014562>, > > 'shutil': <module shutil at 24565346>, 'SAS': <module SAS at > > 16046701>, 'java.io': <java package java.io at 19949342>, 'SAS.time': > > None, 'sre_parse': <module sre_parse at 12715534>, 'jarray': <jclass > > org.python.modules.jarray at 1816810>, 'sitecustomize': <module > > sitecustomize at > > 599654>, 'stat': <module stat at 12066474>, 'SAS.jarray': None, > > 599654>'thread': <jclass org.python.modules.thread at 31811005>, > > 599654>'java': <java package java at 24798854>, 'site': <module site > > 599654>at 14740287>, 'sys': sys module, 'java.util': <java package > > 599654>java.util at 7647499>, 'SAS.ConfigParser': None, 'math': > > 599654><jclass org.python.modules.math at 18053010>, '_sre': <jclass > > 599654>org.python.modules._sre at 17769531>, 'UserDict': <module > > 599654>UserDict at 18073623>, 'string': <module string at 28664226>, > > 599654>'SAS.shutil': None, 'sre_compile': <module sre_compile at > > 599654>18670846>, 'os.path': <module javapath at 33426790>, 're': > > 599654><module re at 2220309>, 'javapath': <module javapath at > > 599654>33426790>, 'exceptions': <jclass org.python.core.exceptions at > > 599654>4214450>, 'sre_constants': <module sre_constants at 32414915>} > > > > I will keep trying to figure out what is going on, and sorry for the length of this reply. I was just really confused when moving the package to the Lib directory worked. > > > > Thanks, > > Alan > > > > > > -----Original Message----- > > From: Charlie Groves [mailto:cha...@gm...] > > Sent: Tuesday, February 13, 2007 2:14 AM > > To: Alan Field > > Cc: jython users > > Subject: Re: [Jython-dev] Problems with import and Jython 2.2 Beta1... > > > > On 2/11/07, Alan Field <Ala...@sa...> wrote: > > > I have also been able to use a JAR file in 2.2 just by adding it to system.path. I thought that this was going to be the way that Jython supported dynamically using JAR files. I am going to start deleting lines from my modules to try and see how far the import is getting, but I was just looking for some other clues to try and track this down. > > > > I'm going to look at your code more closely later to see how things have changed between 2.1 and now, but until I do that could you tell me what kind of errors you're getting after adding a jar to sys.path? > > > > Thanks, > > Charlie > > > |
From: Alan F. <Ala...@sa...> - 2007-02-15 16:32:22
|
Charlie, Well that did it! Thanks a lot for the suggestion. So now how do I = figure out what is causing this? I have looked in the ext directory of = my JVM, and I have these 3 JAR files: dnsns.jar sunjce_provider.jar sunpkcs11.jar None of these has anything in it that looks like "SAS". I use this = method to print the current CLASSPATH: def printCP(): """ Prints the contents of the Classpath """ for url in ClassLoader.getSystemClassLoader().getURLs(): print url And here is the output, after I have imported the module file:/C:/jython2.2b1/jython.jar=20 This is the output from sys.path: >>> sys.path ['C:\\SASJythonPackage', '', 'C:\\jython2.2b1', 'C:\\jython2.2b1\\Lib', = '__classpath__'] How do I read the value of __classpath__? Thanks, Alan -----Original Message----- From: Charlie Groves [mailto:cha...@gm...]=20 Sent: Thursday, February 15, 2007 11:16 AM To: Alan Field Cc: jython users Subject: Re: Problems with import and Jython 2.2 Beta1... Did you try sys.path.insert(0, "C:\\SASJythonPackage")? It's getting to = be more of a longshot, but the offending package could still be in your = JVM's ext or you could have a site file that adds it to your sys.path. Charlie On 2/15/07, Alan Field <Ala...@sa...> wrote: > Charlie, > > I was actually pursuing that as the problem, but in my batch file that = I use to start Jython I clear the CLASSPATH. The jython.jar file is the = only entry on my CLASSPATH in either case. (Whether the package is = inside or outside the Lib directory.) SAS.__file__ is None when the = package is outside the Lib directory and has the path to the __init__.py = file if the package is inside the Lib directory. > > Thanks, > Alan > > -----Original Message----- > From: Charlie Groves [mailto:cha...@gm...] > Sent: Thursday, February 15, 2007 1:41 AM > To: Alan Field > Cc: jython users > Subject: Re: Problems with import and Jython 2.2 Beta1... > > Hmm, could there be an incomplete SAS package somewhere in your = classpath? That could account for all of the symptoms here. The = package in your classpath gets imported before the one you append to the = end of sys.path. When you move the package to the Lib directory, it's = tried before the classpath so it works. Could you try inserting your = package directory at the head of sys.path or printing out SAS.__file__ = to see where it's living? > > Charlie > > On 2/13/07, Alan Field <Ala...@sa...> wrote: > > Charlie, > > > > Well, this has gotten much more interesting. For some reason, if I = move my Python package to Jython's Lib directory, it executes correctly. = (I have some changes to make, but the import behavior is correct.) I = have also been able to verify that the following code will work = correctly to add JAR files dynamically in the 2.2 beta. (The method now = adds JAR files to the sys.path, and the directory to sys.path and = packageManager.addClassPath()) I have not completely tested this = approach, but it seems to work in my preliminary testing. > > > > def add_module_jars(jar_path): > > """ > > This function makes every JAR files in the supplied path > > dynamically loadable without being on the CLASSPATH environment = variable. > > Do not add the entry to the CLASSPATH if it already exists. > > """ > > if exists(jar_path): > > print "Adding jars from directory =3D '" + jar_path + "'" > > > > all_urls =3D=20 > > list(ClassLoader.getSystemClassLoader().getURLs()) > > > > #Add the directory to the Classpath > > try: > > if File(jar_path).toURL() not in all_urls: > > path.append(jar_path) > > packageManager.addClassPath(jar_path) > > except IOException: > > print "Unable to add '" + jar_path + "' to Classpath" > > > > #Add the jars in the directory to the Classpath > > for jar in glob(jar_path + sep + "*.jar"): > > try: > > if File(jar).toURL() not in all_urls: > > path.append(jar) > > except IOException: > > print "Unable to add '" + jar + "' to Classpath" > > > > However, what is really strange is that if my package is not in the = Jython Lib directory, then the imports fail. What is really strange = about this failure is that the import does not execute code in the = __init__.py or module files. I have deleted the class files, and they = are not regenerated. This is the part of the directory structure of my = package: > > > > SAS > > | > > -> __init__.py (contains various utility routines including > > -> add_module_jars) DIServer > > -> __init__.py (contains a class called MDOContext) > > -> support > > -> CreditRisk > > -> MAClient > > > > Normally, I can execute a statement like this in the console to = import MDOContext: > > > > from SAS.DIServer import MDOContext > > > > However, in the 2.2 beta, this produces an error: > > > > Jython 2.2b1 on java1.4.2_09 (JIT: null) Type "copyright", "credits" > > or "license" for more information. > > >>> import sys > > >>> sys.path.append("C:\\SASJythonPackage") > > >>> from SAS.DIServer import MDOContext > > Traceback (innermost last): > > File "<console>", line 1, in ? > > ImportError: no module named DIServer > > > > If I step back and try to import SAS directly, then I can see that = even though the console has not generated an error, the import did not = work correctly. > > > > Jython 2.2b1 on java1.4.2_09 (JIT: null) Type "copyright", "credits" > > or "license" for more information. > > >>> import sys > > >>> sys.path.append("C:\\SASJythonPackage") > > >>> import SAS > > >>> dir() > > ['SAS', '__doc__', '__name__', 'sys'] > > >>> dir(SAS) > > ['CreditRisk', 'DIServer', 'MAClient', '__name__', 'support'] > > >>> > > > > When I execute the dir(SAS) command, it should look something like = this: > > Jython 2.1 on java1.4.2_09 (JIT: null) Type "copyright", "credits"=20 > > or "license" for more information. > > >>> import sys > > >>> sys.path.append("C:\\SASJythonPackage") > > >>> import SAS > > >>> dir(SAS) > > ['Class', 'ClassLoader', 'ConfigParser', 'File', 'Hashtable',=20 > > 'IOException', 'SASJythonPackagePath', 'SAS_TIME_OFFSET',=20 > > 'ST_ATIME', 'System', '__all__', '__doc__', '__file__', '__name__',=20 > > '__path__', '_read_users', '_write_users', 'add_module_jars',=20 > > 'array', 'choice', 'client_stats_path', 'copyfile', 'exists',=20 > > 'get_key_list', 'get_user', 'getcwd', 'glob', 'global_locks_path',=20 > > 'local_stat_path', 'lock', 'log', 'makedirs', 'my_name_is',=20 > > 'normcase', 'olderthan', 'packageManager', 'path', 'permute',=20 > > 'printCP', 'read_config_file', 'remove', 'remove_list_duplicates',=20 > > 'restore_user', 'rmdir', 'sasjythonpackage_path', 'sep',=20 > > 'setup_users', 'sleep', 'stat', 'stub_client_side_job',=20 > > 'stub_job_class', 'stub_tracker', 'system', 'time'] > > > > I have tried stepping through the import code, and it appears that = SAS is loaded as a module of type "java", instead of coming from a .py = file. Here is the sys.modules output from Jython 2.2 beta: > > > > >>> sys.modules > > {'__builtin__': <module '__builtin__' from 'null'>, 'SAS': <java=20 > > package SAS 1>, 'java': <java package java 2>, 'sys': sys module, > > 'os': <jclass org.python.modules.os 3>, 'stat': <module 'stat' from=20 > > 'C:\jython2.2b1\Lib\stat.py'>, 'sitecustomize': <module=20 > > 'sitecustomize' from 'C:\jython2.2b1\Lib\sitecustomize.py'>, 'site': > > <module 'site' from 'C:\jython2.2b1\Lib\site.py'>, 'javapath':=20 > > <module 'javapath' from 'C:\jython2.2b1\Lib\javapath.py'>, 'javaos': = > > <module 'javaos' from 'C:\jython2.2b1\Lib\javaos.py'>, 'java.io':=20 > > <java package java.io 4>, 'UserDict': <module 'UserDict' from=20 > > 'C:\jython2.2b1\Lib\UserDict.py'>, '__main__': <module '__main__'=20 > > from 'null'>, 'java.lang': <java package java.lang 5>, 'exceptions': > > <jclass org.python.core.exceptions 6>} > > > > And here is the output from Jython 2.1: > > > > {'__main__': <module __main__ at 10276870>, 'os': <jclass=20 > > org.python.modules.os at 18707897>, 'java.lang': <java package=20 > > java.lang at 18610053>, 'fnmatch': <module fnmatch at 18304709>, > > 'strop': None, 'sre': <module sre at 20211730>, 'SAS.glob': None, > > 'glob': <module glob at 27035333>, 'javaos': <module javaos at > > 22293724>, 'copy_reg': <module copy_reg at 21840659>, '__builtin__': > > <module __builtin__ at 24027487>, 'types': <jclass=20 > > org.python.modules.types at 2389016>, 'SAS.java': None, 'SAS.os': > > None, 'SAS.random': None, 'SAS.stat': None, 'SAS.sys': None, = 'random': > > <module random at 21094410>, 'ConfigParser': <module ConfigParser at > > 31174955>, 'time': <jclass org.python.modules.time at 5014562>, > > 'shutil': <module shutil at 24565346>, 'SAS': <module SAS at > > 16046701>, 'java.io': <java package java.io at 19949342>, = 'SAS.time': > > None, 'sre_parse': <module sre_parse at 12715534>, 'jarray': <jclass = > > org.python.modules.jarray at 1816810>, 'sitecustomize': <module=20 > > sitecustomize at > > 599654>, 'stat': <module stat at 12066474>, 'SAS.jarray': None, > > 599654>'thread': <jclass org.python.modules.thread at 31811005>, > > 599654>'java': <java package java at 24798854>, 'site': <module site = > > 599654>at 14740287>, 'sys': sys module, 'java.util': <java package=20 > > 599654>java.util at 7647499>, 'SAS.ConfigParser': None, 'math': > > 599654><jclass org.python.modules.math at 18053010>, '_sre': <jclass = > > 599654>org.python.modules._sre at 17769531>, 'UserDict': <module=20 > > 599654>UserDict at 18073623>, 'string': <module string at 28664226>, > > 599654>'SAS.shutil': None, 'sre_compile': <module sre_compile at > > 599654>18670846>, 'os.path': <module javapath at 33426790>, 're': > > 599654><module re at 2220309>, 'javapath': <module javapath at > > 599654>33426790>, 'exceptions': <jclass org.python.core.exceptions=20 > > 599654>33426790>at > > 599654>4214450>, 'sre_constants': <module sre_constants at=20 > > 599654>4214450>32414915>} > > > > I will keep trying to figure out what is going on, and sorry for the = length of this reply. I was just really confused when moving the package = to the Lib directory worked. > > > > Thanks, > > Alan > > > > > > -----Original Message----- > > From: Charlie Groves [mailto:cha...@gm...] > > Sent: Tuesday, February 13, 2007 2:14 AM > > To: Alan Field > > Cc: jython users > > Subject: Re: [Jython-dev] Problems with import and Jython 2.2 = Beta1... > > > > On 2/11/07, Alan Field <Ala...@sa...> wrote: > > > I have also been able to use a JAR file in 2.2 just by adding it = to system.path. I thought that this was going to be the way that Jython = supported dynamically using JAR files. I am going to start deleting = lines from my modules to try and see how far the import is getting, but = I was just looking for some other clues to try and track this down. > > > > I'm going to look at your code more closely later to see how things = have changed between 2.1 and now, but until I do that could you tell me = what kind of errors you're getting after adding a jar to sys.path? > > > > Thanks, > > Charlie > > > |
From: Charlie G. <cha...@gm...> - 2007-02-16 06:05:14
|
On 2/15/07, Alan Field <Ala...@sa...> wrote: > This is the output from sys.path: > >>> sys.path > ['C:\\SASJythonPackage', '', 'C:\\jython2.2b1', 'C:\\jython2.2b1\\Lib', '__classpath__'] > > How do I read the value of __classpath__? __classpath__ is just an entry for Jython's classloader import hook to try at that point. It's what jython uses to figure out when to try and load something from the classpath. Do you have anything in the directory you're running from with SAS in it? That's what '' specifies, and it seems like the only thing left to check. Charlie |
From: Alan F. <Ala...@sa...> - 2007-02-16 13:31:38
|
Charlie, I don't think the '' entry is causing this problem, because then the = import would fail if my package was in the Lib directory. If I insert my = package directory in sys.path, the import does not fail until the entry = is inserted after the "__classpath__" entry. This problem is also not = just a name clash. If I rename the directory from "SAS" to "SASFull", = then the import still fails if it is after the "__classpath__" entry. Thanks, Alan -----Original Message----- From: Charlie Groves [mailto:cha...@gm...] Sent: Fri 2/16/2007 1:05 AM To: Alan Field Cc: jython users Subject: Re: Problems with import and Jython 2.2 Beta1... =20 On 2/15/07, Alan Field <Ala...@sa...> wrote: > This is the output from sys.path: > >>> sys.path > ['C:\\SASJythonPackage', '', 'C:\\jython2.2b1', = 'C:\\jython2.2b1\\Lib', '__classpath__'] > > How do I read the value of __classpath__? __classpath__ is just an entry for Jython's classloader import hook to try at that point. It's what jython uses to figure out when to try and load something from the classpath. Do you have anything in the directory you're running from with SAS in it? That's what '' specifies, and it seems like the only thing left to check. Charlie |
From: Charlie G. <cha...@gm...> - 2007-02-18 06:11:19
|
Hmm, then I'm at a loss as to why this is happening. I can't reproduce it. Could you send me the SAS package so I can try to catch it in the act? Charlie On 2/16/07, Alan Field <Ala...@sa...> wrote: > Charlie, > > I don't think the '' entry is causing this problem, because then the import would fail if my package was in the Lib directory. If I insert my package directory in sys.path, the import does not fail until the entry is inserted after the "__classpath__" entry. This problem is also not just a name clash. If I rename the directory from "SAS" to "SASFull", then the import still fails if it is after the "__classpath__" entry. > > Thanks, > Alan > > > -----Original Message----- > From: Charlie Groves [mailto:cha...@gm...] > Sent: Fri 2/16/2007 1:05 AM > To: Alan Field > Cc: jython users > Subject: Re: Problems with import and Jython 2.2 Beta1... > > On 2/15/07, Alan Field <Ala...@sa...> wrote: > > This is the output from sys.path: > > >>> sys.path > > ['C:\\SASJythonPackage', '', 'C:\\jython2.2b1', 'C:\\jython2.2b1\\Lib', '__classpath__'] > > > > How do I read the value of __classpath__? > > __classpath__ is just an entry for Jython's classloader import hook to > try at that point. It's what jython uses to figure out when to try > and load something from the classpath. > > Do you have anything in the directory you're running from with SAS in > it? That's what '' specifies, and it seems like the only thing left > to check. > > Charlie > > |
From: Oti <oh...@gm...> - 2007-02-25 07:26:47
|
Just a thought: did you check your cachedir ? Maybe there is a java package SAS lingering around. best wishes, Oti. On 2/18/07, Charlie Groves <cha...@gm...> wrote: > Hmm, then I'm at a loss as to why this is happening. I can't > reproduce it. Could you send me the SAS package so I can try to catch > it in the act? > > Charlie > > On 2/16/07, Alan Field <Ala...@sa...> wrote: > > Charlie, > > > > I don't think the '' entry is causing this problem, because then the import would fail if my package was in the Lib directory. If I insert my package directory in sys.path, the import does not fail until the entry is inserted after the "__classpath__" entry. This problem is also not just a name clash. If I rename the directory from "SAS" to "SASFull", then the import still fails if it is after the "__classpath__" entry. > > > > Thanks, > > Alan > > > > > > -----Original Message----- > > From: Charlie Groves [mailto:cha...@gm...] > > Sent: Fri 2/16/2007 1:05 AM > > To: Alan Field > > Cc: jython users > > Subject: Re: Problems with import and Jython 2.2 Beta1... > > > > On 2/15/07, Alan Field <Ala...@sa...> wrote: > > > This is the output from sys.path: > > > >>> sys.path > > > ['C:\\SASJythonPackage', '', 'C:\\jython2.2b1', 'C:\\jython2.2b1\\Lib', '__classpath__'] > > > > > > How do I read the value of __classpath__? > > > > __classpath__ is just an entry for Jython's classloader import hook to > > try at that point. It's what jython uses to figure out when to try > > and load something from the classpath. > > > > Do you have anything in the directory you're running from with SAS in > > it? That's what '' specifies, and it seems like the only thing left > > to check. > > > > Charlie > > > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: Alan F. <Ala...@sa...> - 2007-02-26 15:46:30
|
Oti, Well that was a good thought, but it didn't pan out! I deleted my = cachedir, and tried the test again with the same results. The problem is = definitely related to the "__classpath__" entry in sys.path and what = happens when Jython reaches that entry. I am trying to narrow down the = issue by removing items from my package, but I haven't made it there = yet. Thanks, Alan -----Original Message----- From: Oti [mailto:oh...@gm...]=20 Sent: Sunday, February 25, 2007 2:27 AM To: Charlie Groves Cc: Alan Field; jython users Subject: Re: [Jython-users] Problems with import and Jython 2.2 Beta1... Just a thought: did you check your cachedir ? Maybe there is a java = package SAS lingering around. best wishes, Oti. |
From: Alan F. <Ala...@sa...> - 2007-02-28 19:18:30
|
(Cross-posting to jython-dev since it has actual development content!) OK, I figured it out. First I turned on debug messaging in the registry = file to see if that would provide any clues. Here is the trace when the = import is successful: >>> from SAS.DIServer import MDOContext <single-top>: MDOContext=3D import: trying source C:\jython2.2b1\SAS import: trying precompiled with no sourceC:\jython2.2b1\SAS$py.class import: trying source C:\jython2.2b1\SAS import: trying precompiled with no sourceC:\jython2.2b1\SAS$py.class import: trying source C:\jython2.2b1\Lib\SAS import: trying precompiled with no sourceC:\jython2.2b1\Lib\SAS$py.class #This is the point at which the import succeeds... import: trying precompiled C:\SASJythonPackage\SAS\__init__$py.class import: 'SAS' as C:\SASJythonPackage\SAS\__init__.py And here is the trace when the import is not successful: >>> from SAS.DIServer import MDOContext <single-top>: MDOContext=3D import: trying source C:\jython2.2b1\SAS import: trying precompiled with no sourceC:\jython2.2b1\SAS$py.class import: trying source C:\jython2.2b1\SAS import: trying precompiled with no sourceC:\jython2.2b1\SAS$py.class import: trying source C:\jython2.2b1\Lib\SAS import: trying precompiled with no sourceC:\jython2.2b1\Lib\SAS$py.class #This is the point where the trace deviates from the successful trace... import: trying SAS in packagemanager for path None import: java package as 'C:\SASJythonPackage\SAS' import: 'SAS' as java package import: 'SAS' as java package import: trying SAS.DIServer as java class in syspath loader Traceback (innermost last): File "<console>", line 1, in ? ImportError: no module named DIServer So I found the "import: trying <something> in packagemanager for path = <something>" message in org.python.core.JavaImporter.find_module(). Then = I stepped through the code while the import was happening. Here is the = call stack:=20 org.python.core.JavaImporter.find_module() org.python.core.PackageManager.lookupName() org.python.core.PyJavaPackage.__findattr__() org.python.core.SysPackageManager.packageExists() org.python.core.PathPackageManager.packageExists() In org.python.core.PathPackageManager.packageExists() a = org.python.core.PackageExistsFileFilter object is created which looks = through the files in the directory to see if the directory is a Java or = Python package. Here is where it gets interesting. At some point in the = past, I was using jythonc to compile some classes and one of these = classes was still in the directory. It is named = "message$_PyInner.class". I don't have the original source code anymore, = so I am not exactly sure what created this class but this is the root = cause of my import problem. The = org.python.core.PackageExistsFileFilter.accept() method tests for files = that end in ".py" and "$py.class". If it finds any files with this = extension, then the directory is treated as a Python package. If it = finds a file that ends in ".class", then the directory is treated as a = Java package. I added a test to the = org.python.core.PackageExistsFileFilter.accept() method for = "$_PyInner.class", and then the import succeeded. This also explains why this wasn't a name clash. The $_PyInner.class existed = in the directory no matter what the name. Here is the updated accept = method: public boolean accept(File dir, String name) { if (name.endsWith(".py") || name.endsWith("$py.class") || = name.endsWith("$_PyInner.class")) { this.python =3D true; } else if (name.endsWith(".class")) { this.java =3D true; } return false; } I can enter a bug in the bugtracker, but I do not know if there are any = other file extensions generated by jythonc that might cause this = problem. Anybody out there know? Thanks for the suggestions. Alan |
From: Oti <oh...@gm...> - 2007-02-28 20:27:31
|
Alan, my compliments - great analysis ! Unfortunately I do not know enough about jythonc to give a list of possible class file endings. I'll check if I can find the $_PyInner.class somewhere in the code and deduce the rest from it. best wishes, Oti. On 2/28/07, Alan Field <Ala...@sa...> wrote: > (Cross-posting to jython-dev since it has actual development content!) > > OK, I figured it out. First I turned on debug messaging in the registry file to see if that would provide any clues. Here is the trace when the import is successful: > > >>> from SAS.DIServer import MDOContext > <single-top>: MDOContext= > import: trying source C:\jython2.2b1\SAS > import: trying precompiled with no sourceC:\jython2.2b1\SAS$py.class > import: trying source C:\jython2.2b1\SAS > import: trying precompiled with no sourceC:\jython2.2b1\SAS$py.class > import: trying source C:\jython2.2b1\Lib\SAS > import: trying precompiled with no sourceC:\jython2.2b1\Lib\SAS$py.class > #This is the point at which the import succeeds... > import: trying precompiled C:\SASJythonPackage\SAS\__init__$py.class > import: 'SAS' as C:\SASJythonPackage\SAS\__init__.py > > And here is the trace when the import is not successful: > >>> from SAS.DIServer import MDOContext > <single-top>: MDOContext= > import: trying source C:\jython2.2b1\SAS > import: trying precompiled with no sourceC:\jython2.2b1\SAS$py.class > import: trying source C:\jython2.2b1\SAS > import: trying precompiled with no sourceC:\jython2.2b1\SAS$py.class > import: trying source C:\jython2.2b1\Lib\SAS > import: trying precompiled with no sourceC:\jython2.2b1\Lib\SAS$py.class > #This is the point where the trace deviates from the successful trace... > import: trying SAS in packagemanager for path None > import: java package as 'C:\SASJythonPackage\SAS' > import: 'SAS' as java package > import: 'SAS' as java package > import: trying SAS.DIServer as java class in syspath loader > Traceback (innermost last): > File "<console>", line 1, in ? > ImportError: no module named DIServer > > So I found the "import: trying <something> in packagemanager for path <something>" message in org.python.core.JavaImporter.find_module(). Then I stepped through the code while the import was happening. Here is the call stack: > > org.python.core.JavaImporter.find_module() > org.python.core.PackageManager.lookupName() > org.python.core.PyJavaPackage.__findattr__() > org.python.core.SysPackageManager.packageExists() > org.python.core.PathPackageManager.packageExists() > > In org.python.core.PathPackageManager.packageExists() a org.python.core.PackageExistsFileFilter object is created which looks through the files in the directory to see if the directory is a Java or Python package. Here is where it gets interesting. At some point in the past, I was using jythonc to compile some classes and one of these classes was still in the directory. It is named "message$_PyInner.class". I don't have the original source code anymore, so I am not exactly sure what created this class but this is the root cause of my import problem. The org.python.core.PackageExistsFileFilter.accept() method tests for files that end in ".py" and "$py.class". If it finds any files with this extension, then the directory is treated as a Python package. If it finds a file that ends in ".class", then the directory is treated as a Java package. I added a test to the org.python.core.PackageExistsFileFilter.accept() method for "$_PyInner.class", and then the import succeeded. This > also explains why this wasn't a name clash. The $_PyInner.class existed in the directory no matter what the name. Here is the updated accept method: > > public boolean accept(File dir, String name) { > if (name.endsWith(".py") || name.endsWith("$py.class") || name.endsWith("$_PyInner.class")) { > this.python = true; > } else if (name.endsWith(".class")) { > this.java = true; > } > return false; > } > > I can enter a bug in the bugtracker, but I do not know if there are any other file extensions generated by jythonc that might cause this problem. Anybody out there know? > > Thanks for the suggestions. > Alan > |
From: Alan F. <Ala...@sa...> - 2007-02-28 20:46:03
|
Oti, Thanks a lot. Finding the debug messages was really a big help. I did = not know about them until I found them in the source code, and then = checked the registry file. The messages helped to narrow down which = method was behaving incorrectly. Good luck finding the other jythonc = file extensions. I haven't had any luck so far. The more I think about this, the more I am concerned though. Basically = my import was failing because the directory was being flagged as both a = Java and Python package. Adding the test for "$_PyInner.class" will fix = my situation, but it seems like the import will still fail if I have a = Java class in the default package in the same directory as a Python = "__init__.py" file. I'll try an experiment to see if this is true, but I = think this is a scenario that should work. Thanks, Alan -----Original Message----- From: Oti [mailto:oh...@gm...]=20 Sent: Wednesday, February 28, 2007 3:27 PM To: Alan Field Cc: Charlie Groves; jython users; Jython-Dev Subject: Re: [Jython-users] Problems with import and Jython 2.2 Beta1... Alan, my compliments - great analysis ! Unfortunately I do not know enough about jythonc to give a list of = possible class file endings. I'll check if I can find the = $_PyInner.class somewhere in the code and deduce the rest from it. best wishes, Oti. |
From: Alan F. <Ala...@sa...> - 2007-02-14 16:11:35
|
Just for completeness, here is a session with Jython 2.2 and my code in = Jython's Lib directory. In this situation, the "SAS" module is loaded = from the __init__.py file. Jython 2.2b1 on java1.5.0_10 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import SAS >>> dir(SAS) ['Class', 'ClassLoader', 'ConfigParser', 'File', 'Hashtable', = 'IOException', 'SASJythonPackagePath', 'SAS_TIME_OFFSET', 'ST_ATIME', = 'System', '__all__', '__doc__', '__file__', '__name__', '__path__', = '_read_users', '_write_users', 'add_module_jars', 'array', 'choice', = 'client_stats_path', 'copyfile', 'exists', 'get_key_list', 'get_user', = 'getcwd', 'glob', 'global_locks_path', 'local_stat_path', 'lock', 'log', = 'makedirs', 'my_name_is', 'normcase', 'olderthan', 'packageManager', = 'path', 'permute', 'printCP', 'read_config_file', 'remove', = 'remove_list_duplicates', 'restore_user', 'rmdir', = 'sasjythonpackage_path', 'sep', 'setup_users', 'sleep', 'stat', = 'stub_client_side_job', stub_job_class', 'stub_tracker', 'system', = 'time'] >>> import sys >>> sys.modules {'copy_reg': <module 'copy_reg' from 'C:\jython2.2b1\Lib\copy_reg.py'>, = 're': <module 're'from 'C:\jython2.2b1\Lib\re.py'>, '__builtin__': = <module '__builtin__' from 'null'>, 'sre_constants': <module = 'sre_constants' from 'C:\jython2.2b1\Lib\sre_constants.py'>, 'SAS': = <module 'SAS' from 'C:\jython2.2b1\Lib\SAS\__init__.py'>, 'SAS.random': = None, 'jarray': <jclass org.python.modules.jarray 1>, 'sys': sys module, = 'SAS.jarray': None, 'sre': <module 'sre' from = 'C:\jython2.2b1\Lib\sre.py'>, 'SAS.shutil': None, 'SAS.glob': None, = 'stat': <module 'stat' from 'C:\jython2.2b1\Lib\stat.py'>, 'strop': = None, 'java': <java package java 2>, 'time': <jclass = org.python.modules.time.Time 3>, 'javapath': <module 'javapath' from = 'C:\jython2.2b1\Lib\javapath.py'>, 'SAS.time': None, 'sre_compile': = <module 'sre_compile' from 'C:\jython2.2b1\Lib\sre_compile.py'>, 'os': = <jclass org.python.modules.os 4>, 'site': <module 'site' from = 'C:\jython2.2b1\Lib\site.py'>, 'sre_parse': <module 'sre_parse' from 'C:\jython2.2b1\Lib\sre_parse.py'>, 'UserDict': <module 'UserDict' from = 'C:\jython2.2b1\Lib\UserDict.py'>, 'types': <jclass = org.python.modules.types 5>,'fnmatch': <module 'fnmatch' from = 'C:\jython2.2b1\Lib\fnmatch.py'>, 'random': <module 'random' from = 'C:\jython2.2b1\Lib\random.py'>, 'SAS.os': None, 'SAS.java': None, = '_sre': <jclass org.python.modules._sre 6>, 'os.path': <module = 'javapath' from 'C:\jython2.2b1\Lib\javapath.py'>, 'shutil': <module = 'shutil' from 'C:\jython2.2b1\Lib\shutil.py'>, 'ConfigParser': <module = 'ConfigParser' from 'C:\jython2.2b1\Lib\ConfigParser.py'>, 'string': = <module 'string' from 'C:\jython2.2b1\Lib\string.py'>, 'math': <jclass = org.python.modules.math 7>, 'SAS.sys': None, 'javaos': <module 'javaos' = from 'C:\jython2.2b1\Lib\javaos.py'>, 'java.io': <javapackage java.io = 8>, 'SAS.ConfigParser': None, 'sitecustomize': <module 'sitecustomize' = from 'C:\jython2.2b1\Lib\sitecustomize.py'>, 'glob': <module 'glob' from = 'C:\jython2.2b1\Lib\glob.py'>, 'exceptions': <jclass org.python.core.exceptions 9>, 'SAS.stat': None, '__main__': = <module '__main__' from 'null'>, 'java.lang': <java package java.lang = 10>, 'java.util': <java package java.util 11>} So in this situation the SAS module is represented in sys.modules as = "'SAS': <module 'SAS' from 'C:\jython2.2b1\Lib\SAS\__init__.py'>". If I = run the same batch file with the same code in a directory outside of = Jython's Lib directory, the entry looks like this: "'SAS': <java package = SAS 1>". I am not sure why this is happening, but I think it is the root = of the problem. Thanks, Alan |