Archived

This forum has been archived. Please start a new discussion on GitHub.

Should slice2py --prefix update imports?

I'm having difficulties using the --prefix option to slice2py. The generated __init__.py files import the prefixed files (TEST_... below); but the modules themselves don't.
$ slice2py --output-dir=out -I. a.ice c.ice
$ PYTHONPATH=out:$ICE_HOME/python python2.4
Python 2.4.4 (#2, Apr 12 2007, 21:22:23) 
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import c
>>> c.d()
object #0 (::c::d)
{
}
>>> f = c.d()
>>> f.ice_ids()
('::Ice::Object', '::a::b', '::c::d')
>>> 
$ rm -rf out/*
$ slice2py --output-dir=out --prefix=TEST_ -I. a.ice c.ice
$ PYTHONPATH=out:$ICE_HOME/python python2.4
Python 2.4.4 (#2, Apr 12 2007, 21:22:23) 
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import c
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/josh/bug/out/c/__init__.py", line 4, in ?
    import TEST_c_ice
  File "/home/josh/bug/out/TEST_c_ice.py", line 14, in ?
    import a_ice
ImportError: No module named a_ice
>>>
$ ls -ltra out/
total 28K
drwxr-xr-x 3 josh josh 4.0K 2007-06-07 21:43 ..
-rw-r--r-- 1 josh josh 1.6K 2007-06-07 21:44 TEST_c_ice.py
-rw-r--r-- 1 josh josh 1.5K 2007-06-07 21:44 TEST_a_ice.py
drwxr-xr-x 2 josh josh 4.0K 2007-06-07 21:44 a
-rw-r--r-- 1 josh josh 2.0K 2007-06-07 21:45 TEST_c_ice.pyc
drwxr-xr-x 2 josh josh 4.0K 2007-06-07 21:45 c
drwxr-xr-x 4 josh josh 4.0K 2007-06-07 21:45 .
$ head -n 20 out/TEST_c_ice.py
# **********************************************************************
#
# Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

# Ice version 3.2.0
# Generated from file `c.ice'

import Ice, IcePy, __builtin__
import a_ice

Comments

  • mes
    mes California
    Hi Josh,

    As you have seen, specifying the --prefix option does not influence the import statements that correspond to #include statements in your Slice file. In the example you provided, I presume that c.ice contains the statement

    #include <a.ice>

    slice2py translates that directive into the following import statement:

    import a_ice

    As explained in Section 22.15.2 of the Ice manual, you have to carefully plan your use of the --prefix option and #include directives. The solution for your example is to modify the #include directive in c.ice as follows:

    #include <TEST/a.ice>

    This will cause the translator to emit the following statement:

    import TEST_a_ice

    Naturally, this also means you have to create a subdirectory named TEST and place a.ice inside it.

    One way to learn more about this subject is to examine the way we do it for Ice for Python; in particular, have a look at python/Makefile.

    Hope that helps,
    - Mark